Browse Source

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
tags/2.0.0-beta
Benjamin Wöster 12 years ago
parent
commit
c30ee60e9c
  1. 11
      tests/unit/TestCase.php
  2. 2
      tests/unit/data/config.php

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

2
tests/unit/data/config.php

@ -1,6 +1,8 @@
<?php
return array(
//'appClass' => '\yii\web\Application',
'appClass' => '\yii\console\Application',
'mysql' => array(
'dsn' => 'mysql:host=127.0.0.1;dbname=yiitest',
'username' => 'travis',

Loading…
Cancel
Save