Commit f21c2c29 by Qiang Xue

Fixed test breaks.

parent a27b6e92
......@@ -23,8 +23,8 @@ abstract class TestCase extends \PHPUnit_Framework_TestCase
/**
* 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.
* @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 static function getParam($name, $default = null)
......@@ -39,34 +39,41 @@ abstract class TestCase extends \PHPUnit_Framework_TestCase
/**
* Populates Yii::$app with a new application
* The application will be destroyed on tearDown() automatically.
* @param array $config The application configuration, if needed
* @param array $config The application configuration, if needed
* @param string $appClass name of the application class to create
*/
protected function mockApplication($config = [], $appClass = '\yii\console\Application')
{
static $defaultConfig = [
new $appClass(ArrayHelper::merge([
'id' => 'testapp',
'basePath' => __DIR__,
];
$defaultConfig['vendorPath'] = dirname(dirname(__DIR__)) . '/vendor';
new $appClass(ArrayHelper::merge($defaultConfig, $config));
'vendorPath' => $this->getVendorPath(),
], $config));
}
protected function mockWebApplication($config = [], $appClass = '\yii\web\Application')
{
static $defaultConfig = [
new $appClass(ArrayHelper::merge([
'id' => 'testapp',
'basePath' => __DIR__,
'vendorPath' => $this->getVendorPath(),
'components' => [
'request' => [
'cookieValidationKey' => 'wefJDF8sfdsfSDefwqdxj9oq',
'scriptFile' => __DIR__ .'/index.php',
'scriptUrl' => '/index.php',
],
]
];
$defaultConfig['vendorPath'] = dirname(dirname(__DIR__)) . '/vendor';
], $config));
}
new $appClass(ArrayHelper::merge($defaultConfig, $config));
protected function getVendorPath()
{
$vendor = dirname(dirname(__DIR__)) . '/vendor';
if (!is_dir($vendor)) {
$vendor = dirname(dirname(dirname(dirname(__DIR__))));
}
return $vendor;
}
/**
......
*
!.gitignore
!/coveralls/.gitkeep
......@@ -12,6 +12,8 @@ $_SERVER['SCRIPT_FILENAME'] = __FILE__;
$composerAutoload = __DIR__ . '/../../vendor/autoload.php';
if (is_file($composerAutoload)) {
require_once($composerAutoload);
} else {
require_once(__DIR__ . '/../../../../autoload.php');
}
require_once(__DIR__ . '/../../framework/Yii.php');
......
......@@ -22,7 +22,7 @@ class ViewRendererTest extends TestCase
protected function setUp()
{
parent::setUp();
$this->mockApplication();
$this->mockWebApplication();
}
protected function tearDown()
......
......@@ -22,7 +22,7 @@ class ViewRendererTest extends DatabaseTestCase
protected function setUp()
{
parent::setUp();
$this->mockApplication();
$this->mockWebApplication();
}
protected function tearDown()
......
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