Commit 5046e687 by Qiang Xue

fixed random rbac testing failure.

parent 3b3fb18f
...@@ -11,6 +11,15 @@ function filemtime($file) ...@@ -11,6 +11,15 @@ function filemtime($file)
return \yiiunit\framework\rbac\PhpManagerTest::$filemtime ?: \filemtime($file); return \yiiunit\framework\rbac\PhpManagerTest::$filemtime ?: \filemtime($file);
} }
/**
* Mock for the time() function for rbac classes. Avoid random test fails.
* @return int
*/
function time()
{
return \yiiunit\framework\rbac\PhpManagerTest::$time ?: \time();
}
namespace yiiunit\framework\rbac; namespace yiiunit\framework\rbac;
use Yii; use Yii;
...@@ -22,6 +31,7 @@ use Yii; ...@@ -22,6 +31,7 @@ use Yii;
class PhpManagerTest extends ManagerTestCase class PhpManagerTest extends ManagerTestCase
{ {
public static $filemtime; public static $filemtime;
public static $time;
protected function getItemFile() protected function getItemFile()
{ {
...@@ -60,6 +70,7 @@ class PhpManagerTest extends ManagerTestCase ...@@ -60,6 +70,7 @@ class PhpManagerTest extends ManagerTestCase
protected function setUp() protected function setUp()
{ {
static::$filemtime = null; static::$filemtime = null;
static::$time = null;
parent::setUp(); parent::setUp();
$this->mockApplication(); $this->mockApplication();
$this->removeDataFiles(); $this->removeDataFiles();
...@@ -70,18 +81,19 @@ class PhpManagerTest extends ManagerTestCase ...@@ -70,18 +81,19 @@ class PhpManagerTest extends ManagerTestCase
{ {
$this->removeDataFiles(); $this->removeDataFiles();
static::$filemtime = null; static::$filemtime = null;
static::$time = null;
parent::tearDown(); parent::tearDown();
} }
public function testSaveLoad() public function testSaveLoad()
{ {
$this->prepareData(); static::$time = static::$filemtime = \time();
$this->prepareData();
$items = $this->auth->items; $items = $this->auth->items;
$children = $this->auth->children; $children = $this->auth->children;
$assignments = $this->auth->assignments; $assignments = $this->auth->assignments;
$rules = $this->auth->rules; $rules = $this->auth->rules;
static::$filemtime = time();
$this->auth->save(); $this->auth->save();
$this->auth = $this->createManager(); $this->auth = $this->createManager();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment