Commit d4b30e26 by Benjamin Wöster

allow unit tests to requireApp() on setUp()

parent 8332e8c6
...@@ -13,4 +13,23 @@ class TestCase extends \yii\test\TestCase ...@@ -13,4 +13,23 @@ class TestCase extends \yii\test\TestCase
} }
return isset(self::$params[$name]) ? self::$params[$name] : null; return isset(self::$params[$name]) ? self::$params[$name] : null;
} }
protected function requireApp($requiredConfig=array())
{
static $usedConfig = array();
static $defaultConfig = array(
'id' => 'testapp',
'basePath' => __DIR__,
);
$newConfig = array_merge( $defaultConfig, $requiredConfig );
if (!(\yii::$app instanceof \yii\web\Application)) {
new \yii\web\Application( $newConfig );
$usedConfig = $newConfig;
} elseif ($newConfig !== $usedConfig) {
new \yii\web\Application( $newConfig );
$usedConfig = $newConfig;
}
}
} }
...@@ -13,6 +13,12 @@ abstract class CacheTest extends TestCase ...@@ -13,6 +13,12 @@ abstract class CacheTest extends TestCase
*/ */
abstract protected function getCacheInstance(); abstract protected function getCacheInstance();
protected function setUp()
{
parent::setUp();
$this->requireApp();
}
public function testSet() public function testSet()
{ {
$cache = $this->getCacheInstance(); $cache = $this->getCacheInstance();
......
...@@ -17,6 +17,8 @@ class DbCacheTest extends CacheTest ...@@ -17,6 +17,8 @@ class DbCacheTest extends CacheTest
$this->markTestSkipped('pdo and pdo_mysql extensions are required.'); $this->markTestSkipped('pdo and pdo_mysql extensions are required.');
} }
parent::setUp();
$this->getConnection()->createCommand(" $this->getConnection()->createCommand("
CREATE TABLE IF NOT EXISTS tbl_cache ( CREATE TABLE IF NOT EXISTS tbl_cache (
id char(128) NOT NULL, id char(128) NOT NULL,
......
...@@ -4,15 +4,13 @@ namespace yiiunit\framework\helpers; ...@@ -4,15 +4,13 @@ namespace yiiunit\framework\helpers;
use Yii; use Yii;
use yii\helpers\Html; use yii\helpers\Html;
use yii\web\Application; use yiiunit\TestCase;
class HtmlTest extends \yii\test\TestCase class HtmlTest extends TestCase
{ {
public function setUp() public function setUp()
{ {
new Application(array( $this->requireApp(array(
'id' => 'test',
'basePath' => '@yiiunit/runtime',
'components' => array( 'components' => array(
'request' => array( 'request' => array(
'class' => 'yii\web\Request', 'class' => 'yii\web\Request',
...@@ -30,11 +28,6 @@ class HtmlTest extends \yii\test\TestCase ...@@ -30,11 +28,6 @@ class HtmlTest extends \yii\test\TestCase
$this->assertEquals($expected, $actual); $this->assertEquals($expected, $actual);
} }
public function tearDown()
{
Yii::$app = null;
}
public function testEncode() public function testEncode()
{ {
$this->assertEquals("a&lt;&gt;&amp;&quot;&#039;", Html::encode("a<>&\"'")); $this->assertEquals("a&lt;&gt;&amp;&quot;&#039;", Html::encode("a<>&\"'"));
......
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