Commit f21c2c29 by Qiang Xue

Fixed test breaks.

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