Commit 5e0f6604 by Benjamin Wöster

mod: don't create app in bootstrap script, unit tests do it themselves

add: option to destroy app after each test to find unit tests that fail to require an app
parent d4b30e26
......@@ -6,6 +6,21 @@ class TestCase extends \yii\test\TestCase
{
public static $params;
protected function setUp() {
parent::setUp();
}
protected function tearDown()
{
parent::tearDown();
// If defined and set to true, destroy the app after each test.
// This will cause tests to fail, that rely on an existing app, but don't
// call requireApp() in their setUp().
if (defined('YII_DESTROY_APP_ON_TEARDOWN') && YII_DESTROY_APP_ON_TEARDOWN === true) {
$this->destroyApp();
}
}
public function getParam($name)
{
if (self::$params === null) {
......@@ -32,4 +47,9 @@ class TestCase extends \yii\test\TestCase
$usedConfig = $newConfig;
}
}
protected function destroyApp()
{
\yii::$app = null;
}
}
......@@ -2,6 +2,7 @@
define('YII_ENABLE_ERROR_HANDLER', false);
define('YII_DEBUG', true);
define('YII_DESTROY_APP_ON_TEARDOWN', false);
$_SERVER['SCRIPT_NAME'] = '/' . __DIR__;
$_SERVER['SCRIPT_FILENAME'] = __FILE__;
......@@ -9,6 +10,4 @@ require_once(__DIR__ . '/../../yii/Yii.php');
Yii::setAlias('@yiiunit', __DIR__);
new \yii\web\Application(array('id' => 'testapp', 'basePath' => __DIR__));
require_once(__DIR__ . '/TestCase.php');
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