Skip to content
This repository has been archived by the owner on May 1, 2019. It is now read-only.

Commit

Permalink
Merge pull request #335 from localheinz/feature/class-keyword
Browse files Browse the repository at this point in the history
Enhancement: Leverage class keyword as service identifiers for controllers
  • Loading branch information
Ocramius committed Feb 3, 2015
2 parents 395f37f + 924bfb3 commit 4f9644a
Show file tree
Hide file tree
Showing 5 changed files with 113 additions and 11 deletions.
11 changes: 6 additions & 5 deletions module/Application/config/module.config.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -18,7 +19,7 @@
'options' => [
'route' => '/live-search',
'defaults' => [
'controller' => 'Application\Controller\Search',
'controller' => Controller\SearchController::class,
'action' => 'index',
],
],
Expand All @@ -28,7 +29,7 @@
'options' => [
'route' => '/',
'defaults' => [
'controller' => 'Application\Controller\Index',
'controller' => Controller\IndexController::class,
'action' => 'index',
],
],
Expand All @@ -40,7 +41,7 @@
'options' => [
'route' => '/feed',
'defaults' => [
'controller' => 'Application\Controller\Index',
'controller' => Controller\IndexController::class,
'action' => 'feed',
],
],
Expand Down Expand Up @@ -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' => [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Expand Down
7 changes: 4 additions & 3 deletions module/ZfModule/config/module.config.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
<?php

use EdpGithub\Client;
use ZfModule\Controller;
use ZfModule\Delegators\EdpGithubClientAuthenticator;
use ZfModule\Mapper\ModuleHydrator;
use ZfModule\View\Helper;

return [
'controllers' => [
'factories' => [
'ZfModule\Controller\Index' => 'ZfModule\Controller\IndexControllerFactory',
Controller\IndexController::class => Controller\IndexControllerFactory::class,
],
],
'router' => [
Expand All @@ -18,7 +19,7 @@
'options' => [
'route' => '/:vendor/:module',
'defaults' => [
'controller' => 'ZfModule\Controller\Index',
'controller' => Controller\IndexController::class,
'action' => 'view',
],
],
Expand All @@ -28,7 +29,7 @@
'options' => [
'route' => '/module',
'defaults' => [
'controller' => 'ZfModule\Controller\Index',
'controller' => Controller\IndexController::class,
'action' => 'index',
],
],
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
<?php

namespace ZfModuleTest\Integration\Controller;

use Application\Service;
use ApplicationTest\Integration\Util\Bootstrap;
use stdClass;
use Zend\Test\PHPUnit\Controller\AbstractHttpControllerTestCase;
use ZfModule\Controller;
use ZfModule\Mapper;

class IndexControllerTest extends AbstractHttpControllerTestCase
{
protected function setUp()
{
parent::setUp();

$this->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');
}
}

0 comments on commit 4f9644a

Please sign in to comment.