diff --git a/tests/unit/TestCase.php b/tests/unit/TestCase.php index d098f30..9a65138 100644 --- a/tests/unit/TestCase.php +++ b/tests/unit/TestCase.php @@ -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; + } } diff --git a/tests/unit/bootstrap.php b/tests/unit/bootstrap.php index 285b55b..55f8158 100644 --- a/tests/unit/bootstrap.php +++ b/tests/unit/bootstrap.php @@ -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');