Browse Source

ZF-8193: call bootstrap run() method in controller test case when using Zend_Application

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@20256 44c647ce-9c0f-0410-b52a-842ac1e357ba
matthew 16 years ago
parent
commit
15f4b3e963

+ 7 - 1
library/Zend/Test/PHPUnit/ControllerTestCase.php

@@ -185,13 +185,19 @@ abstract class Zend_Test_PHPUnit_ControllerTestCase extends PHPUnit_Framework_Te
             $request->setRequestUri($url);
         }
         $request->setPathInfo(null);
+
         $controller = $this->getFrontController();
         $this->frontController
              ->setRequest($request)
              ->setResponse($this->getResponse())
              ->throwExceptions(false)
              ->returnResponse(false);
-        $this->frontController->dispatch();
+
+        if ($this->bootstrap instanceof Zend_Application) {
+            $this->bootstrap->run();
+        } else {
+            $this->frontController->dispatch();
+        }
     }
 
     /**

+ 24 - 0
tests/Zend/Test/PHPUnit/ControllerTestCaseTest.php

@@ -757,6 +757,30 @@ class Zend_Test_PHPUnit_ControllerTestCaseTest extends PHPUnit_Framework_TestCas
             $this->testCase->getFrontController()
         );
     }
+
+    /**
+     * @group ZF-8193
+     */
+    public function testWhenApplicationObjectUsedAsBootstrapTestCaseShouldExecuteBootstrapRunMethod()
+    {
+        require_once 'Zend/Application.php';
+        $application = new Zend_Application('testing', array(
+            'resources' => array(
+                'frontcontroller' => array(
+                    'controllerDirectory' => dirname(__FILE__) . '/_files/application/controllers',
+                ),
+            ),
+        ));
+        $this->testCase->bootstrap = $application;
+        $this->testCase->bootstrap();
+        $this->testCase->dispatch('/');
+        $front = $application->getBootstrap()->getResource('frontcontroller');
+        $boot  = $front->getParam('bootstrap');
+        $type  = is_object($boot)
+               ? get_class($boot)
+               : gettype($boot);
+        $this->assertTrue($boot === $this->testCase->bootstrap->getBootstrap(), $type);
+    }
 }
 
 // Concrete test case class for testing purposes