From 6d64d62c8e9a80ee1d1bb0dc240db76da51b2dba Mon Sep 17 00:00:00 2001 From: Qiang Xue Date: Sat, 19 Jul 2014 15:59:12 -0400 Subject: [PATCH] Fixed test break. --- tests/unit/TestCase.php | 16 ++++++++++++++++ tests/unit/framework/widgets/ActiveFieldTest.php | 2 +- tests/unit/framework/widgets/BreadcrumbsTest.php | 2 +- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/tests/unit/TestCase.php b/tests/unit/TestCase.php index 4d9b7aa266..f598cc9672 100644 --- a/tests/unit/TestCase.php +++ b/tests/unit/TestCase.php @@ -53,6 +53,22 @@ abstract class TestCase extends \PHPUnit_Framework_TestCase new $appClass(ArrayHelper::merge($defaultConfig, $config)); } + protected function mockWebApplication($config = [], $appClass = '\yii\web\Application') + { + static $defaultConfig = [ + 'id' => 'testapp', + 'basePath' => __DIR__, + 'components' => [ + 'request' => [ + 'cookieValidationKey' => 'wefJDF8sfdsfSDefwqdxj9oq', + ], + ] + ]; + $defaultConfig['vendorPath'] = dirname(dirname(__DIR__)) . '/vendor'; + + new $appClass(ArrayHelper::merge($defaultConfig, $config)); + } + /** * Destroys application in Yii::$app by setting it to null. */ diff --git a/tests/unit/framework/widgets/ActiveFieldTest.php b/tests/unit/framework/widgets/ActiveFieldTest.php index d181353a6c..1330342fcd 100644 --- a/tests/unit/framework/widgets/ActiveFieldTest.php +++ b/tests/unit/framework/widgets/ActiveFieldTest.php @@ -27,7 +27,7 @@ class ActiveFieldTest extends \yiiunit\TestCase $_SERVER['SCRIPT_FILENAME'] = "index.php"; $_SERVER['SCRIPT_NAME'] = "index.php"; - $this->mockApplication([], 'yii\web\Application'); + $this->mockWebApplication(); Yii::setAlias('@testWeb', '/'); Yii::setAlias('@testWebRoot', '@yiiunit/data/web'); diff --git a/tests/unit/framework/widgets/BreadcrumbsTest.php b/tests/unit/framework/widgets/BreadcrumbsTest.php index 69c1ab59d4..9bd1b72ce2 100644 --- a/tests/unit/framework/widgets/BreadcrumbsTest.php +++ b/tests/unit/framework/widgets/BreadcrumbsTest.php @@ -20,7 +20,7 @@ class BreadcrumbsTest extends \yiiunit\TestCase $_SERVER['SCRIPT_FILENAME'] = "index.php"; $_SERVER['SCRIPT_NAME'] = "index.php"; - $this->mockApplication([], 'yii\web\Application'); + $this->mockWebApplication(); $this->breadcrumbs = new Breadcrumbs(); }