|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace FOS\ElasticaBundle\Tests\Doctrine; |
|
4
|
|
|
|
|
5
|
|
|
use Doctrine\ORM\EntityManager; |
|
6
|
|
|
use Doctrine\ORM\EntityRepository; |
|
7
|
|
|
use Doctrine\ORM\QueryBuilder; |
|
8
|
|
|
use FOS\ElasticaBundle\Doctrine\ORMPagerProvider; |
|
9
|
|
|
use FOS\ElasticaBundle\Provider\PagerfantaPager; |
|
10
|
|
|
use FOS\ElasticaBundle\Provider\PagerProviderInterface; |
|
11
|
|
|
use FOS\ElasticaBundle\Tests\Mocks\DoctrineORMCustomRepositoryMock; |
|
12
|
|
|
use Pagerfanta\Adapter\DoctrineORMAdapter; |
|
13
|
|
|
use Symfony\Bridge\Doctrine\ManagerRegistry; |
|
14
|
|
|
|
|
15
|
|
|
class ORMPagerProviderTest extends \PHPUnit_Framework_TestCase |
|
16
|
|
|
{ |
|
17
|
|
|
public function testShouldImplementPagerProviderInterface() |
|
18
|
|
|
{ |
|
19
|
|
|
$rc = new \ReflectionClass(ORMPagerProvider::class); |
|
20
|
|
|
|
|
21
|
|
|
$this->assertTrue($rc->implementsInterface(PagerProviderInterface::class)); |
|
22
|
|
|
} |
|
23
|
|
|
|
|
24
|
|
|
public function testCouldBeConstructedWithExpectedArguments() |
|
25
|
|
|
{ |
|
26
|
|
|
$doctrine = $this->createDoctrineMock(); |
|
27
|
|
|
$objectClass = 'anObjectClass'; |
|
28
|
|
|
$baseConfig = []; |
|
29
|
|
|
|
|
30
|
|
|
new ORMPagerProvider($doctrine, $objectClass, $baseConfig); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
public function testShouldReturnPagerfanataPagerWithDoctrineODMMongoDBAdapter() |
|
34
|
|
|
{ |
|
35
|
|
|
$objectClass = 'anObjectClass'; |
|
36
|
|
|
$baseConfig = ['query_builder_method' => 'createQueryBuilder']; |
|
37
|
|
|
|
|
38
|
|
|
$expectedBuilder = $this->getMock(QueryBuilder::class, [], [], '', false); |
|
|
|
|
|
|
39
|
|
|
|
|
40
|
|
|
$repository = $this->getMock(EntityRepository::class, [], [], '', false); |
|
|
|
|
|
|
41
|
|
|
$repository |
|
42
|
|
|
->expects($this->once()) |
|
43
|
|
|
->method('createQueryBuilder') |
|
44
|
|
|
->willReturn($expectedBuilder); |
|
45
|
|
|
|
|
46
|
|
|
$manager = $this->getMock(EntityManager::class, [], [], '', false); |
|
|
|
|
|
|
47
|
|
|
$manager |
|
48
|
|
|
->expects($this->once()) |
|
49
|
|
|
->method('getRepository') |
|
50
|
|
|
->with($objectClass) |
|
51
|
|
|
->willReturn($repository); |
|
52
|
|
|
|
|
53
|
|
|
|
|
54
|
|
|
$doctrine = $this->createDoctrineMock(); |
|
55
|
|
|
$doctrine |
|
56
|
|
|
->expects($this->once()) |
|
57
|
|
|
->method('getManagerForClass') |
|
58
|
|
|
->with($objectClass) |
|
59
|
|
|
->willReturn($manager); |
|
60
|
|
|
|
|
61
|
|
|
$provider = new ORMPagerProvider($doctrine, $objectClass, $baseConfig); |
|
62
|
|
|
|
|
63
|
|
|
$pager = $provider->provide(); |
|
64
|
|
|
|
|
65
|
|
|
$this->assertInstanceOf(PagerfantaPager::class, $pager); |
|
66
|
|
|
|
|
67
|
|
|
$adapter = $pager->getPagerfanta()->getAdapter(); |
|
68
|
|
|
$this->assertInstanceOf(DoctrineORMAdapter::class, $adapter); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
public function testShouldAllowCallCustomRepositoryMethod() |
|
72
|
|
|
{ |
|
73
|
|
|
$objectClass = 'anObjectClass'; |
|
74
|
|
|
$baseConfig = ['query_builder_method' => 'createQueryBuilder']; |
|
75
|
|
|
|
|
76
|
|
|
$repository = $this->getMock(DoctrineORMCustomRepositoryMock::class, [], [], '', false); |
|
|
|
|
|
|
77
|
|
|
$repository |
|
78
|
|
|
->expects($this->once()) |
|
79
|
|
|
->method('createCustomQueryBuilder') |
|
80
|
|
|
->willReturn($this->getMock(QueryBuilder::class, [], [], '', false)); |
|
|
|
|
|
|
81
|
|
|
|
|
82
|
|
|
$manager = $this->getMock(EntityManager::class, [], [], '', false); |
|
|
|
|
|
|
83
|
|
|
$manager |
|
84
|
|
|
->expects($this->once()) |
|
85
|
|
|
->method('getRepository') |
|
86
|
|
|
->with($objectClass) |
|
87
|
|
|
->willReturn($repository); |
|
88
|
|
|
|
|
89
|
|
|
|
|
90
|
|
|
$doctrine = $this->createDoctrineMock(); |
|
91
|
|
|
$doctrine |
|
92
|
|
|
->expects($this->once()) |
|
93
|
|
|
->method('getManagerForClass') |
|
94
|
|
|
->with($objectClass) |
|
95
|
|
|
->willReturn($manager); |
|
96
|
|
|
|
|
97
|
|
|
$provider = new ORMPagerProvider($doctrine, $objectClass, $baseConfig); |
|
98
|
|
|
|
|
99
|
|
|
$pager = $provider->provide(['query_builder_method' => 'createCustomQueryBuilder']); |
|
100
|
|
|
|
|
101
|
|
|
$this->assertInstanceOf(PagerfantaPager::class, $pager); |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
/** |
|
105
|
|
|
* @return \PHPUnit_Framework_MockObject_MockObject|ManagerRegistry |
|
106
|
|
|
*/ |
|
107
|
|
|
private function createDoctrineMock() |
|
108
|
|
|
{ |
|
109
|
|
|
return $this->getMock(ManagerRegistry::class, [], [], '', false); |
|
|
|
|
|
|
110
|
|
|
} |
|
111
|
|
|
} |
|
112
|
|
|
|
This method has been deprecated. The supplier of the class has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.