我正在阅读 ZF 2 (http://framework.zend.com/manual/2.0/en/user-guide/routing-and-controllers.html) 并且我已经编写了一个控制器测试,但我已经有一个编纂的动作在我的控制器中,如果没有输入 ID,它会将用户定向到 indexAction,使用 PHPUnit 执行测试取决于我如何执行重定向示例:
// Does not Work
return $ this-> redirect () -> toRoute ('my_route', array ('action' => 'index'));
返回以下错误消息:
TopAcl\Controller\MY_CONTROLLER_ControllerTest :: testEditarActionCanBeAcessed Zend\Mvc\Router\Exception\RuntimeException: 找不到名为“my_route”的路由
// Works correctly
return $ this-> redirect () -> toUrl ('/ resource');
我在互联网上没有找到任何关于它的信息,有什么解释吗?我需要更多的加载文件吗?
// Follow the setUp of my ControllerTest:
protected function setUp ()
{
$ bootstrap = \Zend\Mvc\Application :: init (include 'config/application.config.php');
$ this-> controller = new ResourceController ();
$ this-> request = new Request ();
$ this-> routeMatch = new RouteMatch (array ('controller' => 'index'));
$ this-> event = $ bootstrap-> getMvcEvent ();
$ this-> event-> setRouteMatch ($ this-> routeMatch);
$ this-> controller-> SetEvent ($ this-> event);
$ this-> controller-> setEventManager ($ bootstrap-> getEventManager ());
$ this-> controller-> setServiceLocator ($ bootstrap-> getServiceManager ());
}