diff --git a/module/Application/config/module.config.php b/module/Application/config/module.config.php index 3d31b7c1..ce9054b2 100644 --- a/module/Application/config/module.config.php +++ b/module/Application/config/module.config.php @@ -6,6 +6,7 @@ * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ +use Application\Controller; use Application\Service; use Application\View; use Psr\Log; @@ -18,7 +19,7 @@ 'options' => [ 'route' => '/live-search', 'defaults' => [ - 'controller' => 'Application\Controller\Search', + 'controller' => Controller\SearchController::class, 'action' => 'index', ], ], @@ -28,7 +29,7 @@ 'options' => [ 'route' => '/', 'defaults' => [ - 'controller' => 'Application\Controller\Index', + 'controller' => Controller\IndexController::class, 'action' => 'index', ], ], @@ -40,7 +41,7 @@ 'options' => [ 'route' => '/feed', 'defaults' => [ - 'controller' => 'Application\Controller\Index', + 'controller' => Controller\IndexController::class, 'action' => 'feed', ], ], @@ -80,8 +81,8 @@ ], 'controllers' => [ 'factories' => [ - 'Application\Controller\Index' => 'Application\Controller\IndexControllerFactory', - 'Application\Controller\Search' => 'Application\Controller\SearchControllerFactory', + Controller\IndexController::class => Controller\IndexControllerFactory::class, + Controller\SearchController::class => Controller\SearchControllerFactory::class, ], ], 'service_manager' => [ diff --git a/module/Application/test/ApplicationTest/Integration/Controller/IndexControllerTest.php b/module/Application/test/ApplicationTest/Integration/Controller/IndexControllerTest.php index 15e6f320..eec3b8b1 100644 --- a/module/Application/test/ApplicationTest/Integration/Controller/IndexControllerTest.php +++ b/module/Application/test/ApplicationTest/Integration/Controller/IndexControllerTest.php @@ -80,7 +80,7 @@ public function testIndexActionCanBeAccessed() $this->dispatch('/'); - $this->assertControllerName('Application\Controller\Index'); + $this->assertControllerName(Controller\IndexController::class); $this->assertActionName('index'); $this->assertResponseStatusCode(Http\Response::STATUS_CODE_200); } @@ -112,7 +112,7 @@ public function testFeedActionCanBeAccessed() $this->dispatch('/feed'); - $this->assertControllerName('Application\Controller\Index'); + $this->assertControllerName(Controller\IndexController::class); $this->assertActionName('feed'); $this->assertResponseStatusCode(Http\Response::STATUS_CODE_200); } diff --git a/module/Application/test/ApplicationTest/Integration/Controller/SearchControllerTest.php b/module/Application/test/ApplicationTest/Integration/Controller/SearchControllerTest.php index 4f67c5d5..51793170 100644 --- a/module/Application/test/ApplicationTest/Integration/Controller/SearchControllerTest.php +++ b/module/Application/test/ApplicationTest/Integration/Controller/SearchControllerTest.php @@ -2,6 +2,7 @@ namespace ApplicationTest\Integration\Controller; +use Application\Controller; use ApplicationTest\Integration\Util\Bootstrap; use Zend\Http; use Zend\Test\PHPUnit\Controller\AbstractHttpControllerTestCase; @@ -37,7 +38,7 @@ public function testIndexActionCanBeAccessed() $this->dispatch('/live-search'); - $this->assertControllerName('Application\Controller\Search'); + $this->assertControllerName(Controller\SearchController::class); $this->assertActionName('index'); $this->assertResponseStatusCode(Http\Response::STATUS_CODE_200); } diff --git a/module/ZfModule/config/module.config.php b/module/ZfModule/config/module.config.php index 2cb28569..1f7b2f83 100644 --- a/module/ZfModule/config/module.config.php +++ b/module/ZfModule/config/module.config.php @@ -1,6 +1,7 @@ [ 'factories' => [ - 'ZfModule\Controller\Index' => 'ZfModule\Controller\IndexControllerFactory', + Controller\IndexController::class => Controller\IndexControllerFactory::class, ], ], 'router' => [ @@ -18,7 +19,7 @@ 'options' => [ 'route' => '/:vendor/:module', 'defaults' => [ - 'controller' => 'ZfModule\Controller\Index', + 'controller' => Controller\IndexController::class, 'action' => 'view', ], ], @@ -28,7 +29,7 @@ 'options' => [ 'route' => '/module', 'defaults' => [ - 'controller' => 'ZfModule\Controller\Index', + 'controller' => Controller\IndexController::class, 'action' => 'index', ], ], diff --git a/module/ZfModule/test/ZfModuleTest/Integration/Controller/IndexControllerTest.php b/module/ZfModule/test/ZfModuleTest/Integration/Controller/IndexControllerTest.php new file mode 100644 index 00000000..5c5e51c3 --- /dev/null +++ b/module/ZfModule/test/ZfModuleTest/Integration/Controller/IndexControllerTest.php @@ -0,0 +1,99 @@ +setApplicationConfig(Bootstrap::getConfig()); + } + + public function testIndexActionCanBeAccessed() + { + $this->dispatch('/module'); + + $this->assertControllerName(Controller\IndexController::class); + $this->assertActionName('index'); + } + + public function testOrganizationActionCanBeAccessed() + { + $owner = 'foo'; + + $url = sprintf( + '/module/list/%s', + $owner + ); + + $this->dispatch($url); + + $this->assertControllerName(Controller\IndexController::class); + $this->assertActionName('organization'); + } + + public function testViewActionCanBeAccessed() + { + $vendor = 'foo'; + $module = 'bar'; + + $moduleMapper = $this->getMockBuilder(Mapper\Module::class) + ->disableOriginalConstructor() + ->getMock() + ; + + $moduleMapper + ->expects($this->once()) + ->method('findByName') + ->with($this->equalTo($module)) + ->willReturn(new stdClass()) + ; + + $repositoryRetriever = $this->getMockBuilder(Service\RepositoryRetriever::class) + ->disableOriginalConstructor() + ->getMock() + ; + + $repositoryRetriever + ->expects($this->once()) + ->method('getUserRepositoryMetadata') + ->with( + $this->equalTo($vendor), + $this->equalTo($module) + ) + ->willReturn(new stdClass()) + ; + + $this->getApplicationServiceLocator() + ->setAllowOverride(true) + ->setService( + 'zfmodule_mapper_module', + $moduleMapper + ) + ->setService( + Service\RepositoryRetriever::class, + $repositoryRetriever + ) + ; + + $url = sprintf( + '/%s/%s', + $vendor, + $module + ); + + $this->dispatch($url); + + $this->assertControllerName(Controller\IndexController::class); + $this->assertActionName('view'); + } +}