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
}
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
*/
abstract protected function getCacheInstance();
protected function setUp()
{
parent::setUp();
$this->requireApp();
}
public function testSet()
{
$cache = $this->getCacheInstance();
......
......@@ -17,6 +17,8 @@ class DbCacheTest extends CacheTest
$this->markTestSkipped('pdo and pdo_mysql extensions are required.');
}
parent::setUp();
$this->getConnection()->createCommand("
CREATE TABLE IF NOT EXISTS tbl_cache (
id char(128) NOT NULL,
......
......@@ -4,15 +4,13 @@ namespace yiiunit\framework\helpers;
use Yii;
use yii\helpers\Html;
use yii\web\Application;
use yiiunit\TestCase;
class HtmlTest extends \yii\test\TestCase
class HtmlTest extends TestCase
{
public function setUp()
{
new Application(array(
'id' => 'test',
'basePath' => '@yiiunit/runtime',
$this->requireApp(array(
'components' => array(
'request' => array(
'class' => 'yii\web\Request',
......@@ -30,11 +28,6 @@ class HtmlTest extends \yii\test\TestCase
$this->assertEquals($expected, $actual);
}
public function tearDown()
{
Yii::$app = null;
}
public function testEncode()
{
$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