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

Commit 25d4db7

Browse files
committed
Enhancement: Add failing test
1 parent 063fb6d commit 25d4db7

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed

module/ZfModule/test/ZfModuleTest/Integration/Controller/UserControllerTest.php

+64
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,15 @@
44

55
use ApplicationTest\Integration\Util\Bootstrap;
66
use Zend\Http;
7+
use Zend\Mvc;
78
use Zend\Paginator;
89
use Zend\Test\PHPUnit\Controller\AbstractHttpControllerTestCase;
910
use ZfModule\Controller;
1011
use ZfModule\Mapper;
1112

13+
/**
14+
* @method Mvc\Application getApplication()
15+
*/
1216
class UserControllerTest extends AbstractHttpControllerTestCase
1317
{
1418
protected function setUp()
@@ -63,4 +67,64 @@ public function testUserPageCanBeAccessed()
6367
$this->assertActionName('modulesForUser');
6468
$this->assertResponseStatusCode(Http\Response::STATUS_CODE_200);
6569
}
70+
71+
/**
72+
* @dataProvider providerInvalidUserName
73+
*
74+
* @param string $userName
75+
*/
76+
public function testModulesForUserDoesNotMatchOnInvalidUserName($userName)
77+
{
78+
$moduleMapper = $this->getMockBuilder(Mapper\Module::class)->getMock();
79+
80+
$moduleMapper
81+
->expects($this->any())
82+
->method('pagination')
83+
->with(
84+
$this->equalTo(1),
85+
$this->equalTo(10),
86+
$this->equalTo($userName),
87+
$this->equalTo('created_at'),
88+
$this->equalTo('DESC')
89+
)
90+
->willReturn(new Paginator\Paginator(new Paginator\Adapter\Null()))
91+
;
92+
93+
$moduleMapper
94+
->expects($this->any())
95+
->method('findAll')
96+
->willReturn([])
97+
;
98+
99+
$this->getApplicationServiceLocator()
100+
->setAllowOverride(true)
101+
->setService(
102+
Mapper\Module::class,
103+
$moduleMapper
104+
)
105+
;
106+
107+
$url = sprintf(
108+
'/user/%s',
109+
$userName
110+
);
111+
112+
$this->dispatch($url);
113+
114+
$event = $this->getApplication()->getMvcEvent();
115+
116+
$this->assertSame(Mvc\Application::ERROR_ROUTER_NO_MATCH, $event->getError());
117+
}
118+
119+
/**
120+
* @return array
121+
*/
122+
public function providerInvalidUserName()
123+
{
124+
return [
125+
[
126+
'9',
127+
],
128+
];
129+
}
66130
}

0 commit comments

Comments
 (0)