From 3181964132a132ff56cca74663029848fb74c243 Mon Sep 17 00:00:00 2001 From: Qiang Xue Date: Wed, 18 Dec 2013 11:12:04 -0500 Subject: [PATCH] refactored TestCase. --- extensions/yii/codeception/TestCase.php | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/extensions/yii/codeception/TestCase.php b/extensions/yii/codeception/TestCase.php index 34dc11d..e30aa1d 100644 --- a/extensions/yii/codeception/TestCase.php +++ b/extensions/yii/codeception/TestCase.php @@ -3,6 +3,7 @@ namespace yii\codeception; use Yii; +use yii\base\InvalidConfigException; /** * TestCase is the base class for all codeception unit tests @@ -13,7 +14,8 @@ use Yii; class TestCase extends \PHPUnit_Framework_TestCase { /** - * @var array the application configuration that will be used for creating an application instance for each test. + * @var array|string the application configuration that will be used for creating an application instance for each test. + * You can use a string to represent the file path or path alias of a configuration file. */ public static $appConfig = []; /** @@ -21,6 +23,14 @@ class TestCase extends \PHPUnit_Framework_TestCase */ public static $appClass = 'yii\web\Application'; + /** + * @inheritdoc + */ + protected function setUp() + { + parent::setUp(); + $this->mockApplication(); + } /** * @inheritdoc @@ -39,7 +49,14 @@ class TestCase extends \PHPUnit_Framework_TestCase */ protected function mockApplication($config = null) { - return new static::$appClass($config === null ? static::$appConfig : $config); + $config = $config === null ? static::$appConfig : $config; + if (is_string($config)) { + $config = Yii::getAlias($config); + } + if (!is_array($config)) { + throw new InvalidConfigException('Please provide a configuration for creating application.'); + } + return new static::$appClass($config); } /**