You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

60 lines
1.4 KiB

13 years ago
<?php
namespace yiiunit;
12 years ago
/**
* This is the base class for all yii framework unit tests.
*/
abstract class TestCase extends \yii\test\TestCase
13 years ago
{
public static $params;
13 years ago
12 years ago
/**
* Clean up after test.
* By default the application created with [[mockApplication]] will be destroyed.
*/
protected function tearDown()
{
parent::tearDown();
12 years ago
$this->destroyApplication();
}
12 years ago
/**
* Returns a test configuration param from /data/config.php
* @param string $name params name
* @param mixed $default default value to use when param is not set.
* @return mixed the value of the configuration param
*/
public function getParam($name, $default = null)
13 years ago
{
if (self::$params === null) {
self::$params = require(__DIR__ . '/data/config.php');
13 years ago
}
return isset(self::$params[$name]) ? self::$params[$name] : $default;
13 years ago
}
12 years ago
/**
* Populates Yii::$app with a new application
* The application will be destroyed on tearDown() automatically.
* @param array $config The application configuration, if needed
*/
protected function mockApplication($config=array())
{
static $defaultConfig = array(
'id' => 'testapp',
'basePath' => __DIR__,
);
$appClass = $this->getParam( 'appClass', '\yii\web\Application' );
12 years ago
new $appClass(array_merge($defaultConfig,$config));
}
12 years ago
/**
* Destroys application in Yii::$app by setting it to null.
*/
protected function destroyApplication()
{
\Yii::$app = null;
}
}