Yii2 Bootstrap 3
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

14 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
14 years ago
{
public static $params;
14 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)
14 years ago
{
if (self::$params === null) {
self::$params = require(__DIR__ . '/data/config.php');
14 years ago
}
return isset(self::$params[$name]) ? self::$params[$name] : $default;
14 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
12 years ago
* @param string $appClass name of the application class to create
12 years ago
*/
protected function mockApplication($config = [], $appClass = '\yii\console\Application')
{
static $defaultConfig = [
'id' => 'testapp',
'basePath' => __DIR__,
];
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;
}
}