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) { 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
); );
$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;
} }
} }

2
tests/unit/data/config.php

@ -1,6 +1,8 @@
<?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',

Loading…
Cancel
Save