ZF-11619: Zend_Test_PHPUnit_ControllerTestCase::url implementation lacks support for default route in case custom routes are defined


The current implementation of Zend_Test_PHPUnit_ControllerTestCase::url() sets the default route only in case no custom routes are defined. In case a user has some custom routes defined, e.g. in application.ini, additionally to the default route, the behavior of the test code differs from the main project code. The result is that an exception "Zend_Controller_Router_Exception: Route default is not defined" is thrown.

The solution is to apply the patch.

--- /usr/share/php/Zend/Test/PHPUnit/ControllerTestCase.php 2011-07-28 10:32:30.000000000 +0200 +++ ControllerTestCase.php 2011-07-28 10:33:44.000000000 +0200 @@ -1166,15 +1166,16 @@ * @param string $name * @param bool $reset * @param bool $encode + * @param bool $default */ - public function url($urlOptions = array(), $name = null, $reset = false, $encode = true) + public function url($urlOptions = array(), $name = null, $reset = false, $encode = true, $default = false) { $frontController = $this->getFrontController(); $router = $frontController->getRouter(); if (!$router instanceof Zend_Controller_Router_Rewrite) { throw new Exception('This url helper utility function only works when the router is of type Zend_Controller_Router_Rewrite'); } - if (count($router->getRoutes()) == 0) { + if ($default) { $router->addDefaultRoutes(); } return $router->assemble($urlOptions, $name, $reset, $encode);


A possible workaround is to simply include the defaultRoutes in your bootstrap (or wherever you set your routes):


Some conversation about this is here:…