From c30ee60e9c6739d6862addd13ef5a5d22a971ee2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20W=C3=B6ster?= Date: Thu, 9 May 2013 22:06:58 +0200 Subject: [PATCH] add: new key for unit tests config named "className". Allows to run the tests using different Application instances (consoleApp/ webApp) mod: TestCase::getParam accepts second param $default=null --- tests/unit/TestCase.php | 11 ++++++----- tests/unit/data/config.php | 2 ++ 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/tests/unit/TestCase.php b/tests/unit/TestCase.php index 9a65138..314e2b0 100644 --- a/tests/unit/TestCase.php +++ b/tests/unit/TestCase.php @@ -21,12 +21,12 @@ class TestCase extends \yii\test\TestCase } } - public function getParam($name) + public function getParam($name,$default=null) { if (self::$params === null) { self::$params = require(__DIR__ . '/data/config.php'); } - return isset(self::$params[$name]) ? self::$params[$name] : null; + return isset(self::$params[$name]) ? self::$params[$name] : $default; } protected function requireApp($requiredConfig=array()) @@ -38,12 +38,13 @@ class TestCase extends \yii\test\TestCase ); $newConfig = array_merge( $defaultConfig, $requiredConfig ); + $appClass = $this->getParam( 'appClass', '\yii\web\Application' ); - if (!(\yii::$app instanceof \yii\web\Application)) { - new \yii\web\Application( $newConfig ); + if (!(\yii::$app instanceof $appClass)) { + new $appClass( $newConfig ); $usedConfig = $newConfig; } elseif ($newConfig !== $usedConfig) { - new \yii\web\Application( $newConfig ); + new $appClass( $newConfig ); $usedConfig = $newConfig; } } diff --git a/tests/unit/data/config.php b/tests/unit/data/config.php index 238a7cc..fe5f229 100644 --- a/tests/unit/data/config.php +++ b/tests/unit/data/config.php @@ -1,6 +1,8 @@ '\yii\web\Application', + 'appClass' => '\yii\console\Application', 'mysql' => array( 'dsn' => 'mysql:host=127.0.0.1;dbname=yiitest', 'username' => 'travis',