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