Browse Source

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
tags/2.0.0-beta
Benjamin Wöster 12 years ago
parent
commit
5e0f6604e8
  1. 20
      tests/unit/TestCase.php
  2. 3
      tests/unit/bootstrap.php

20
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;
}
}

3
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');

Loading…
Cancel
Save