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

Issue Type: Patch Created: 2011-07-28T08:43:11.000+0000 Last Updated: 2012-08-28T10:25:01.000+0000 Status: Open Fix version(s): Reporter: Martin Weber (mweber) Assignee: Matthew Weier O'Phinney (matthew) Tags: - Zend_Test_PHPUnit

Related issues: Attachments:


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);


Posted by Nathan Bell (nathanpbell) on 2012-08-28T10:25:01.000+0000

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


Some conversation about this is here:…

Have you found an issue?

See the Overview section for more details.


© 2006-2016 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.