【发布时间】:2012-10-09 12:28:44
【问题描述】:
我正在阅读 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 ());
}
【问题讨论】:
标签: url frameworks zend-framework2 phpunit