|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Bludata\Lumen\Tests\Repositories; |
|
4
|
|
|
|
|
5
|
|
|
use Bludata\Lumen\Tests\BaseTest; |
|
6
|
|
|
|
|
7
|
|
|
abstract class BaseRepositoryTest extends BaseTest |
|
8
|
|
|
{ |
|
9
|
|
|
abstract public function getRepository(); |
|
|
|
|
|
|
10
|
|
|
|
|
11
|
|
|
abstract public function getMockObject(array $except = []); |
|
|
|
|
|
|
12
|
|
|
|
|
13
|
|
|
public function getFlushedMockObject(array $except = []) |
|
|
|
|
|
|
14
|
|
|
{ |
|
15
|
|
|
$entity = $this->getMockObject($except); |
|
16
|
|
|
|
|
17
|
|
|
$this->getRepository() |
|
18
|
|
|
->save($entity) |
|
19
|
|
|
->flush($entity); |
|
20
|
|
|
|
|
21
|
|
|
return $entity; |
|
22
|
|
|
} |
|
23
|
|
|
|
|
24
|
|
|
public function getMockArray(array $except = []) |
|
|
|
|
|
|
25
|
|
|
{ |
|
26
|
|
|
return $this->getMockObject($except)->toArray(); |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
public function getFlushedMockArray(array $except = []) |
|
|
|
|
|
|
30
|
|
|
{ |
|
31
|
|
|
return $this->getFlushedMockObject($except)->toArray(); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
View Code Duplication |
public function testFindAll() |
|
|
|
|
|
|
35
|
|
|
{ |
|
36
|
|
|
$entity = $this->getFlushedMockObject(); |
|
|
|
|
|
|
37
|
|
|
|
|
38
|
|
|
$findAll = $this->getRepository()->findAll()->getResult(); |
|
39
|
|
|
|
|
40
|
|
|
$this->assertGreaterThan(0, count($findAll)); |
|
41
|
|
|
$this->assertInstanceOf($this->getRepository()->getEntityName(), $findAll[0]); |
|
|
|
|
|
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
public function testFindBy() |
|
45
|
|
|
{ |
|
46
|
|
|
$entity = $this->getFlushedMockObject(); |
|
47
|
|
|
|
|
48
|
|
|
$repository = $this->getRepository(); |
|
49
|
|
|
|
|
50
|
|
|
$findBy = $repository->findBy(['id' => $entity->getId()]); |
|
51
|
|
|
|
|
52
|
|
|
$this->assertGreaterThan(0, count($findBy)); |
|
53
|
|
|
$this->assertInstanceOf($repository->getEntityName(), $findBy[0]); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
View Code Duplication |
public function testFindOneBy() |
|
|
|
|
|
|
57
|
|
|
{ |
|
58
|
|
|
$entity = $this->getFlushedMockObject(); |
|
59
|
|
|
|
|
60
|
|
|
$repository = $this->getRepository(); |
|
61
|
|
|
|
|
62
|
|
|
$findOneBy = $repository->findOneBy(['id' => $entity->getId()]); |
|
63
|
|
|
|
|
64
|
|
|
$this->assertInstanceOf($repository->getEntityName(), $findOneBy); |
|
65
|
|
|
$this->assertEquals($entity->getId(), $findOneBy->getId()); |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
View Code Duplication |
public function testFind() |
|
|
|
|
|
|
69
|
|
|
{ |
|
70
|
|
|
$entity = $this->getFlushedMockObject(); |
|
71
|
|
|
|
|
72
|
|
|
$repository = $this->getRepository(); |
|
73
|
|
|
|
|
74
|
|
|
$find = $repository->find($entity->getId()); |
|
75
|
|
|
|
|
76
|
|
|
$this->assertInstanceOf($repository->getEntityName(), $find); |
|
77
|
|
|
$this->assertEquals($entity->getId(), $find->getId()); |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
/** |
|
81
|
|
|
* @expectedException Symfony\Component\HttpKernel\Exception\NotFoundHttpException |
|
|
|
|
|
|
82
|
|
|
*/ |
|
83
|
|
|
public function testRemove() |
|
84
|
|
|
{ |
|
85
|
|
|
$repository = $this->getRepository(); |
|
86
|
|
|
|
|
87
|
|
|
$entity = $this->getFlushedMockObject(); |
|
88
|
|
|
|
|
89
|
|
|
$repository->remove($entity) |
|
90
|
|
|
->flush($entity); |
|
91
|
|
|
|
|
92
|
|
|
$repository->find($entity->getId()); |
|
93
|
|
|
} |
|
94
|
|
|
} |
|
95
|
|
|
|
For interface and abstract methods, it is impossible to infer the return type from the immediate code. In these cases, it is generally advisible to explicitly annotate these methods with a
@returndoc comment to communicate to implementors of these methods what they are expected to return.