From 6d69a74840d39625fba6e1d47a338ef334a88624 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20Mo=CC=88ller?= Date: Fri, 6 Mar 2015 15:36:10 +0100 Subject: [PATCH] Enhancement: Assert ModuleController::viewAction() is not dispatched to --- .../Controller/ModuleControllerTest.php | 86 +++++++++++++++++++ 1 file changed, 86 insertions(+) diff --git a/module/ZfModule/test/ZfModuleTest/Integration/Controller/ModuleControllerTest.php b/module/ZfModule/test/ZfModuleTest/Integration/Controller/ModuleControllerTest.php index 989ec653..9b6a4144 100644 --- a/module/ZfModule/test/ZfModuleTest/Integration/Controller/ModuleControllerTest.php +++ b/module/ZfModule/test/ZfModuleTest/Integration/Controller/ModuleControllerTest.php @@ -1225,6 +1225,92 @@ public function testViewActionCanBeAccessed() $this->assertActionName('view'); } + /** + * @dataProvider providerTakenUrls + * + * @param string $url + */ + public function testViewActionIsNotDispatchedToIfUrlIsTaken($url) + { + $moduleMapper = $this->getMockBuilder(Mapper\Module::class) + ->disableOriginalConstructor() + ->getMock() + ; + + $moduleMapper + ->expects($this->any()) + ->method('findByName') + ->willReturn(new Entity\Module()) + ; + + $repositoryRetriever = $this->getMockBuilder(RepositoryRetriever::class) + ->disableOriginalConstructor() + ->getMock() + ; + + $repositoryRetriever + ->expects($this->any()) + ->method('getUserRepositoryMetadata') + ->willReturn(new stdClass()) + ; + + $this->getApplicationServiceLocator() + ->setAllowOverride(true) + ->setService( + Mapper\Module::class, + $moduleMapper + ) + ->setService( + RepositoryRetriever::class, + $repositoryRetriever + ) + ; + + $this->dispatch($url); + + $routeMatch = $this->getApplication()->getMvcEvent()->getRouteMatch(); + + $controller = $routeMatch->getParam('controller'); + $action = $routeMatch->getParam('action'); + + $unexpectedController = Controller\ModuleController::class; + $unexpectedAction = 'view'; + + $isController = strtolower($controller) === strtolower($unexpectedController); + $isAction = strtolower($action) === $unexpectedAction; + + $this->assertFalse( + $isController && $isAction, + sprintf( + 'Failed to assert that the url "%s" is not dispatched to "%s::%sAction()"', + $url, + $unexpectedController, + $unexpectedAction + ) + ); + } + + /** + * @return array + */ + public function providerTakenUrls() + { + return [ + [ + '/module/add', + ], + [ + '/module/list', + ], + [ + '/module/remove', + ], + [ + '/user/anyone', + ], + ]; + } + /** * @link http://stackoverflow.com/a/15907250 *