Commit 31819641 by Qiang Xue

refactored TestCase.

parent 157b1ffd
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
namespace yii\codeception; namespace yii\codeception;
use Yii; use Yii;
use yii\base\InvalidConfigException;
/** /**
* TestCase is the base class for all codeception unit tests * TestCase is the base class for all codeception unit tests
...@@ -13,7 +14,8 @@ use Yii; ...@@ -13,7 +14,8 @@ use Yii;
class TestCase extends \PHPUnit_Framework_TestCase 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 = []; public static $appConfig = [];
/** /**
...@@ -21,6 +23,14 @@ class TestCase extends \PHPUnit_Framework_TestCase ...@@ -21,6 +23,14 @@ class TestCase extends \PHPUnit_Framework_TestCase
*/ */
public static $appClass = 'yii\web\Application'; public static $appClass = 'yii\web\Application';
/**
* @inheritdoc
*/
protected function setUp()
{
parent::setUp();
$this->mockApplication();
}
/** /**
* @inheritdoc * @inheritdoc
...@@ -39,7 +49,14 @@ class TestCase extends \PHPUnit_Framework_TestCase ...@@ -39,7 +49,14 @@ class TestCase extends \PHPUnit_Framework_TestCase
*/ */
protected function mockApplication($config = null) 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);
} }
/** /**
......
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