diff --git a/tests/unit/TestCase.php b/tests/unit/TestCase.php index 314e2b0..fbc0da7 100644 --- a/tests/unit/TestCase.php +++ b/tests/unit/TestCase.php @@ -13,12 +13,7 @@ class TestCase extends \yii\test\TestCase 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(); - } + $this->destroyApp(); } public function getParam($name,$default=null) @@ -29,28 +24,19 @@ class TestCase extends \yii\test\TestCase return isset(self::$params[$name]) ? self::$params[$name] : $default; } - protected function requireApp($requiredConfig=array()) + protected function mockApplication($requiredConfig=array()) { - static $usedConfig = array(); static $defaultConfig = array( 'id' => 'testapp', 'basePath' => __DIR__, ); - $newConfig = array_merge( $defaultConfig, $requiredConfig ); $appClass = $this->getParam( 'appClass', '\yii\web\Application' ); - - if (!(\yii::$app instanceof $appClass)) { - new $appClass( $newConfig ); - $usedConfig = $newConfig; - } elseif ($newConfig !== $usedConfig) { - new $appClass( $newConfig ); - $usedConfig = $newConfig; - } + new $appClass(array_merge($defaultConfig,$requiredConfig)); } protected function destroyApp() { - \yii::$app = null; + \Yii::$app = null; } } diff --git a/tests/unit/bootstrap.php b/tests/unit/bootstrap.php index 55f8158..a0fdab4 100644 --- a/tests/unit/bootstrap.php +++ b/tests/unit/bootstrap.php @@ -2,7 +2,6 @@ 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__; diff --git a/tests/unit/framework/caching/CacheTest.php b/tests/unit/framework/caching/CacheTest.php index f3eda7a..a17f126 100644 --- a/tests/unit/framework/caching/CacheTest.php +++ b/tests/unit/framework/caching/CacheTest.php @@ -16,7 +16,7 @@ abstract class CacheTest extends TestCase protected function setUp() { parent::setUp(); - $this->requireApp(); + $this->mockApplication(); } public function testSet() diff --git a/tests/unit/framework/helpers/HtmlTest.php b/tests/unit/framework/helpers/HtmlTest.php index 9ba6b43..294cae0 100644 --- a/tests/unit/framework/helpers/HtmlTest.php +++ b/tests/unit/framework/helpers/HtmlTest.php @@ -10,7 +10,7 @@ class HtmlTest extends TestCase { public function setUp() { - $this->requireApp(array( + $this->mockApplication(array( 'components' => array( 'request' => array( 'class' => 'yii\web\Request',