Commit c30ee60e by Benjamin Wöster

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
parent 5e0f6604
...@@ -21,12 +21,12 @@ class TestCase extends \yii\test\TestCase ...@@ -21,12 +21,12 @@ class TestCase extends \yii\test\TestCase
} }
} }
public function getParam($name) public function getParam($name,$default=null)
{ {
if (self::$params === null) { if (self::$params === null) {
self::$params = require(__DIR__ . '/data/config.php'); 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()) protected function requireApp($requiredConfig=array())
...@@ -38,12 +38,13 @@ class TestCase extends \yii\test\TestCase ...@@ -38,12 +38,13 @@ class TestCase extends \yii\test\TestCase
); );
$newConfig = array_merge( $defaultConfig, $requiredConfig ); $newConfig = array_merge( $defaultConfig, $requiredConfig );
$appClass = $this->getParam( 'appClass', '\yii\web\Application' );
if (!(\yii::$app instanceof \yii\web\Application)) { if (!(\yii::$app instanceof $appClass)) {
new \yii\web\Application( $newConfig ); new $appClass( $newConfig );
$usedConfig = $newConfig; $usedConfig = $newConfig;
} elseif ($newConfig !== $usedConfig) { } elseif ($newConfig !== $usedConfig) {
new \yii\web\Application( $newConfig ); new $appClass( $newConfig );
$usedConfig = $newConfig; $usedConfig = $newConfig;
} }
} }
......
<?php <?php
return array( return array(
//'appClass' => '\yii\web\Application',
'appClass' => '\yii\console\Application',
'mysql' => array( 'mysql' => array(
'dsn' => 'mysql:host=127.0.0.1;dbname=yiitest', 'dsn' => 'mysql:host=127.0.0.1;dbname=yiitest',
'username' => 'travis', 'username' => 'travis',
......
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