From f21c2c296466a84fe0d17b608f17293c3b3decda Mon Sep 17 00:00:00 2001
From: Qiang Xue <qiang.xue@gmail.com>
Date: Fri, 5 Sep 2014 16:39:18 -0400
Subject: [PATCH] Fixed test breaks.

---
 tests/unit/TestCase.php                           | 31 +++++++++++++++++++------------
 tests/unit/assets/.gitignore                      |  3 +++
 tests/unit/bootstrap.php                          |  2 ++
 tests/unit/extensions/smarty/ViewRendererTest.php |  2 +-
 tests/unit/extensions/twig/ViewRendererTest.php   |  2 +-
 5 files changed, 26 insertions(+), 14 deletions(-)
 create mode 100644 tests/unit/assets/.gitignore

diff --git a/tests/unit/TestCase.php b/tests/unit/TestCase.php
index f598cc9..5a286cf 100644
--- a/tests/unit/TestCase.php
+++ b/tests/unit/TestCase.php
@@ -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;
     }
 
     /**
diff --git a/tests/unit/assets/.gitignore b/tests/unit/assets/.gitignore
new file mode 100644
index 0000000..5e31724
--- /dev/null
+++ b/tests/unit/assets/.gitignore
@@ -0,0 +1,3 @@
+*
+!.gitignore
+!/coveralls/.gitkeep
diff --git a/tests/unit/bootstrap.php b/tests/unit/bootstrap.php
index 6e84928..39a7c59 100644
--- a/tests/unit/bootstrap.php
+++ b/tests/unit/bootstrap.php
@@ -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');
 
diff --git a/tests/unit/extensions/smarty/ViewRendererTest.php b/tests/unit/extensions/smarty/ViewRendererTest.php
index 02028f6..92e0290 100644
--- a/tests/unit/extensions/smarty/ViewRendererTest.php
+++ b/tests/unit/extensions/smarty/ViewRendererTest.php
@@ -22,7 +22,7 @@ class ViewRendererTest extends TestCase
     protected function setUp()
     {
         parent::setUp();
-        $this->mockApplication();
+        $this->mockWebApplication();
     }
 
     protected function tearDown()
diff --git a/tests/unit/extensions/twig/ViewRendererTest.php b/tests/unit/extensions/twig/ViewRendererTest.php
index 13fff38..cd13c81 100644
--- a/tests/unit/extensions/twig/ViewRendererTest.php
+++ b/tests/unit/extensions/twig/ViewRendererTest.php
@@ -22,7 +22,7 @@ class ViewRendererTest extends DatabaseTestCase
     protected function setUp()
     {
         parent::setUp();
-        $this->mockApplication();
+        $this->mockWebApplication();
     }
 
     protected function tearDown()
--
libgit2 0.27.1