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 #477 from localheinz/fix/route-definition
Browse files Browse the repository at this point in the history
Enhancement: Assert ModuleController::viewAction() is not dispatched to
  • Loading branch information
Ocramius committed Mar 7, 2015
2 parents 39c8611 + 6d69a74 commit 11e8e4b
Showing 1 changed file with 86 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down

0 comments on commit 11e8e4b

Please sign in to comment.