From 0788e1045f98ebea7ce03e1910d98b506a06755e Mon Sep 17 00:00:00 2001 From: Qiang Xue Date: Sun, 29 Dec 2013 20:54:20 -0500 Subject: [PATCH] Refactored unit tests. --- apps/basic/tests/unit/_bootstrap.php | 2 -- extensions/yii/codeception/TestCase.php | 27 +++++++++++++++++---------- framework/yii/test/DbFixtureManager.php | 7 +++---- framework/yii/test/DbTestTrait.php | 7 +++++-- 4 files changed, 25 insertions(+), 18 deletions(-) diff --git a/apps/basic/tests/unit/_bootstrap.php b/apps/basic/tests/unit/_bootstrap.php index 8592f19..80cc72a 100644 --- a/apps/basic/tests/unit/_bootstrap.php +++ b/apps/basic/tests/unit/_bootstrap.php @@ -1,5 +1,3 @@ appConfig : $config; if (is_string($config)) { - $config = Yii::getAlias($config); + $configFile = Yii::getAlias($config); + if (!is_file($configFile)) { + throw new InvalidConfigException("The application configuration file does not exist: $config"); + } + $config = require($configFile); } - if (!is_array($config)) { - throw new InvalidConfigException('Please provide a configuration for creating application.'); + if (is_array($config)) { + if (!isset($config['class'])) { + $config['class'] = 'yii\web\Application'; + } + return Yii::createObject($config); + } else { + throw new InvalidConfigException('Please provide a configuration array to mock up an application.'); } - return new static::$appClass($config); } /** diff --git a/framework/yii/test/DbFixtureManager.php b/framework/yii/test/DbFixtureManager.php index f657a40..0072fd2 100644 --- a/framework/yii/test/DbFixtureManager.php +++ b/framework/yii/test/DbFixtureManager.php @@ -10,7 +10,6 @@ namespace yii\test; use Yii; use yii\base\Component; use yii\base\InvalidConfigException; -use yii\db\ActiveRecord; use yii\db\ActiveRecordInterface; use yii\db\Connection; @@ -185,7 +184,7 @@ class DbFixtureManager extends Component * Returns the specified ActiveRecord instance in the fixture data. * @param string $fixtureName the fixture name * @param string $modelName the alias for the fixture data row - * @return \yii\db\ActiveRecord the ActiveRecord instance. Null is returned if there is no such fixture row. + * @return ActiveRecordInterface the ActiveRecord instance. Null is returned if there is no such fixture row. */ public function getModel($fixtureName, $modelName) { @@ -196,9 +195,9 @@ class DbFixtureManager extends Component return $this->_models[$fixtureName][$modelName]; } $row = $this->_rows[$fixtureName][$modelName]; - /** @var \yii\db\ActiveRecord $modelClass */ + /** @var ActiveRecordInterface $modelClass */ $modelClass = $this->_models[$fixtureName]; - /** @var \yii\db\ActiveRecord $model */ + /** @var ActiveRecordInterface $model */ $model = new $modelClass; $keys = []; foreach ($model->primaryKey() as $key) { diff --git a/framework/yii/test/DbTestTrait.php b/framework/yii/test/DbTestTrait.php index 8a6dc3c..a6d616e 100644 --- a/framework/yii/test/DbTestTrait.php +++ b/framework/yii/test/DbTestTrait.php @@ -19,15 +19,18 @@ use Yii; * * ~~~ * use yii\test\DbTestTrait; + * use yii\codeception\TestCase; * use app\models\Post; * use app\models\User; * - * class PostTestCase extends \PHPUnit_Framework_TestCase + * class PostTestCase extends TestCase * { * use DbTestTrait; * - * public function setUp() + * protected function setUp() * { + * parent::setUp(); + * * $this->loadFixtures([ * 'posts' => Post::className(), * 'users' => User::className(),