Skip to content

Commit dfb03cb

Browse files
author
Rafal Ksiazek
committed
Testing
1 parent aaec300 commit dfb03cb

File tree

5 files changed

+172
-6
lines changed

5 files changed

+172
-6
lines changed

config/application.config.php

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
'DoctrineModule',
66
'DoctrineORMModule',
77
'DluTwBootstrap',
8+
'Acl',
89
'Auth',
910
'Application',
1011
'User',

module/Auth/test/AuthTest/Controller/LoginControllerTest.php

+34
Original file line numberDiff line numberDiff line change
@@ -163,4 +163,38 @@ public function testAction_WithExceptionInService()
163163
$this->assertNotRedirect();
164164
}
165165

166+
public function testAction_WhenLoginIsFailed()
167+
{
168+
$data = [
169+
'login' => uniqid('login'),
170+
'password' => uniqid('password'),
171+
'csrf' => 'csrfToken'
172+
];
173+
174+
$inputFilterMock = $this->getMock(InputFilterInterface::class);
175+
176+
$this->loginFormMock->expects($this->once())
177+
->method('setData')->with($data);
178+
179+
$this->loginFormMock->expects($this->once())
180+
->method('isValid')->will($this->returnValue(true));
181+
182+
$this->loginFormMock->expects($this->once())
183+
->method('getInputFilter')->will($this->returnValue($inputFilterMock));
184+
185+
$this->loginService->expects($this->once())
186+
->method('login')
187+
->with($inputFilterMock)
188+
->will($this->returnValue(false));
189+
190+
$this->controller->dispatch(
191+
(new Request())
192+
->setMethod(Request::METHOD_POST)
193+
->setPost(new Parameters($data))
194+
);
195+
196+
$this->assertResponseStatusCode(Response::STATUS_CODE_200);
197+
$this->assertNotRedirect();
198+
}
199+
166200
}

module/Auth/test/AuthTest/Service/Storage/DbStorageTest.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,14 @@ public function testWriteAndReadAndClear()
4949
->will($this->returnValue($userEntity));
5050

5151
$result = $this->testedObject->read();
52+
$this->assertSame($userEntity, $result);
5253

54+
// read again without searching in repository
55+
$result = $this->testedObject->read();
5356
$this->assertSame($userEntity, $result);
5457

5558
$this->testedObject->clear();
56-
5759
$result = $this->testedObject->read();
58-
5960
$this->assertSame(null, $result);
6061
}
6162

module/Library/test/LibraryTest/Repository/BookRepositoryTest.php

+71-4
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22

33
namespace LibraryTest\Repository;
44

5+
use Application\Library\QueryFilter\Exception\UnrecognizedFieldException;
6+
use Application\Library\QueryFilter\Exception\UnsupportedTypeException;
57
use Application\Library\QueryFilter\QueryFilter;
6-
use Application\Library\QueryFilter\Command\Repository;
8+
use Application\Library\QueryFilter\Command;
79
use Doctrine\ORM\Query;
810
use Doctrine\ORM\QueryBuilder;
911
use DoctrineModule\Stdlib\Hydrator\DoctrineObject;
@@ -13,7 +15,7 @@
1315
use PHPUnit_Framework_MockObject_MockObject as MockObject;
1416
use Test\Bootstrap;
1517

16-
class BookRepositoryTestCase extends AbstractRepositoryTestCase
18+
class BookRepositoryTest extends AbstractRepositoryTestCase
1719
{
1820
/**
1921
* @var BookRepository
@@ -152,7 +154,7 @@ public function testDelete_WithoutFlush()
152154
$this->testedObj->delete($bookEntity, false);
153155
}
154156

155-
public function testFindByQueryFilter()
157+
public function testFindByQueryFilter_WithValidQueryData()
156158
{
157159
$sm = Bootstrap::getServiceManager();
158160

@@ -188,7 +190,7 @@ public function testFindByQueryFilter()
188190
$queryFilter = $sm->get(QueryFilter::class);
189191
$queryFilter->setQueryParameters($queryData);
190192

191-
$commandCollection = $sm->get(Repository\CommandCollection::class);
193+
$commandCollection = $sm->get(Command\Repository\CommandCollection::class);
192194

193195
$this->classMetadataMock->expects($this->any())
194196
->method('getFieldNames')
@@ -213,4 +215,69 @@ public function testFindByQueryFilter()
213215

214216
$this->testedObj->findByQueryFilter($queryFilter, $commandCollection);
215217
}
218+
219+
public function testFindByQueryFilter_WithNotFoundCriteriaCommand()
220+
{
221+
$sm = Bootstrap::getServiceManager();
222+
223+
$queryData = [
224+
'$fields' => 'id,author,title',
225+
];
226+
227+
$fieldNames = [
228+
'id',
229+
'author',
230+
'title',
231+
'year',
232+
'price',
233+
'name',
234+
'status'
235+
];
236+
237+
/** @var QueryFilter $queryFilter */
238+
$queryFilter = $sm->get(QueryFilter::class);
239+
$queryFilter->setQueryParameters($queryData);
240+
241+
$commandCollection = new Command\Repository\CommandCollection(
242+
[
243+
new Command\Repository\BetweenCommand()
244+
]
245+
);
246+
247+
$this->classMetadataMock->expects($this->any())
248+
->method('getFieldNames')
249+
->will($this->returnValue($fieldNames));
250+
251+
$this->setExpectedException(UnsupportedTypeException::class, 'Unsupported condition type: fields');
252+
253+
$this->testedObj->findByQueryFilter($queryFilter, $commandCollection);
254+
}
255+
256+
public function testFindByQueryFilter_WithUnrecognizedField()
257+
{
258+
$sm = Bootstrap::getServiceManager();
259+
260+
$queryData = [
261+
'$fields' => 'id,author,title',
262+
];
263+
264+
$fieldNames = [
265+
'author',
266+
'title',
267+
];
268+
269+
/** @var QueryFilter $queryFilter */
270+
$queryFilter = $sm->get(QueryFilter::class);
271+
$queryFilter->setQueryParameters($queryData);
272+
273+
$commandCollection = $sm->get(Command\Repository\CommandCollection::class);
274+
275+
$this->classMetadataMock->expects($this->any())
276+
->method('getFieldNames')
277+
->will($this->returnValue($fieldNames));
278+
279+
$this->setExpectedException(UnrecognizedFieldException::class, 'Field unrecognized in entity: id');
280+
281+
$this->testedObj->findByQueryFilter($queryFilter, $commandCollection);
282+
}
216283
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<?php
2+
3+
namespace UserTest\Entity;
4+
5+
use User\Entity\UserEntity;
6+
7+
class UserEntityTest extends \PHPUnit_Framework_TestCase
8+
{
9+
/**
10+
* @var UserEntity
11+
*/
12+
private $testedObject;
13+
14+
public function setUp()
15+
{
16+
$this->testedObject = new UserEntity();
17+
}
18+
19+
public function testInstance()
20+
{
21+
$this->assertNull($this->testedObject->getId());
22+
}
23+
24+
public function testSetAndGetName()
25+
{
26+
$value = uniqid('name');
27+
28+
$this->testedObject->setName($value);
29+
$result = $this->testedObject->getName();
30+
31+
$this->assertSame($value, $result);
32+
}
33+
34+
public function testSetAndGetLogin()
35+
{
36+
$value = uniqid('login');
37+
38+
$this->testedObject->setLogin($value);
39+
$result = $this->testedObject->getLogin();
40+
41+
$this->assertSame($value, $result);
42+
}
43+
44+
public function testSetAndGetEmail()
45+
{
46+
$value = uniqid('email');
47+
48+
$this->testedObject->setEmail($value);
49+
$result = $this->testedObject->getEmail();
50+
51+
$this->assertSame($value, $result);
52+
}
53+
54+
public function testSetAndGetPassword()
55+
{
56+
$value = uniqid('password');
57+
58+
$this->testedObject->setPassword($value);
59+
$result = $this->testedObject->getPassword();
60+
61+
$this->assertSame($value, $result);
62+
}
63+
}

0 commit comments

Comments
 (0)