From 25d4db72e89798510b259af62d06db5ba0605c5d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20Mo=CC=88ller?= Date: Thu, 5 Mar 2015 09:29:27 +0100 Subject: [PATCH 1/2] Enhancement: Add failing test --- .../Controller/UserControllerTest.php | 64 +++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/module/ZfModule/test/ZfModuleTest/Integration/Controller/UserControllerTest.php b/module/ZfModule/test/ZfModuleTest/Integration/Controller/UserControllerTest.php index 88032c07..d13a5043 100644 --- a/module/ZfModule/test/ZfModuleTest/Integration/Controller/UserControllerTest.php +++ b/module/ZfModule/test/ZfModuleTest/Integration/Controller/UserControllerTest.php @@ -4,11 +4,15 @@ use ApplicationTest\Integration\Util\Bootstrap; use Zend\Http; +use Zend\Mvc; use Zend\Paginator; use Zend\Test\PHPUnit\Controller\AbstractHttpControllerTestCase; use ZfModule\Controller; use ZfModule\Mapper; +/** + * @method Mvc\Application getApplication() + */ class UserControllerTest extends AbstractHttpControllerTestCase { protected function setUp() @@ -63,4 +67,64 @@ public function testUserPageCanBeAccessed() $this->assertActionName('modulesForUser'); $this->assertResponseStatusCode(Http\Response::STATUS_CODE_200); } + + /** + * @dataProvider providerInvalidUserName + * + * @param string $userName + */ + public function testModulesForUserDoesNotMatchOnInvalidUserName($userName) + { + $moduleMapper = $this->getMockBuilder(Mapper\Module::class)->getMock(); + + $moduleMapper + ->expects($this->any()) + ->method('pagination') + ->with( + $this->equalTo(1), + $this->equalTo(10), + $this->equalTo($userName), + $this->equalTo('created_at'), + $this->equalTo('DESC') + ) + ->willReturn(new Paginator\Paginator(new Paginator\Adapter\Null())) + ; + + $moduleMapper + ->expects($this->any()) + ->method('findAll') + ->willReturn([]) + ; + + $this->getApplicationServiceLocator() + ->setAllowOverride(true) + ->setService( + Mapper\Module::class, + $moduleMapper + ) + ; + + $url = sprintf( + '/user/%s', + $userName + ); + + $this->dispatch($url); + + $event = $this->getApplication()->getMvcEvent(); + + $this->assertSame(Mvc\Application::ERROR_ROUTER_NO_MATCH, $event->getError()); + } + + /** + * @return array + */ + public function providerInvalidUserName() + { + return [ + [ + '9', + ], + ]; + } } From 32b448753c9e4afa2257b4e2f166ade657616261 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20Mo=CC=88ller?= Date: Fri, 6 Mar 2015 15:06:51 +0100 Subject: [PATCH 2/2] Fix: Config-key should be 'constraints' --- module/ZfModule/config/module.config.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/module/ZfModule/config/module.config.php b/module/ZfModule/config/module.config.php index a5814490..56196fe7 100644 --- a/module/ZfModule/config/module.config.php +++ b/module/ZfModule/config/module.config.php @@ -30,7 +30,7 @@ 'type' => 'Segment', 'options' => [ 'route' => '/user/:owner', - 'constrains' => [ + 'constraints' => [ 'owner' => '[a-zA-Z][a-zA-Z0-9_-]*', ], 'defaults' => [