1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the FOSElasticaBundle package. |
5
|
|
|
* |
6
|
|
|
* (c) FriendsOfSymfony <http://friendsofsymfony.github.com/> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace FOS\ElasticaBundle\Persister; |
13
|
|
|
|
14
|
|
|
use Symfony\Component\DependencyInjection\Container; |
15
|
|
|
use Symfony\Component\DependencyInjection\ContainerAwareInterface; |
16
|
|
|
|
17
|
|
|
class PagerPersisterRegistryTest extends \PHPUnit_Framework_TestCase |
18
|
|
|
{ |
19
|
|
|
public function testShouldImplementContainerAwareInterface() |
20
|
|
|
{ |
21
|
|
|
$rc = new \ReflectionClass(PagerPersisterRegistry::class); |
22
|
|
|
|
23
|
|
|
$this->assertTrue($rc->implementsInterface(ContainerAwareInterface::class)); |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
public function testShouldBeFinal() |
27
|
|
|
{ |
28
|
|
|
$rc = new \ReflectionClass(PagerPersisterRegistry::class); |
29
|
|
|
|
30
|
|
|
$this->assertTrue($rc->isFinal()); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
public function testCouldBeConstructedWithNameToServiceIdMap() |
34
|
|
|
{ |
35
|
|
|
new PagerPersisterRegistry([]); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
View Code Duplication |
public function testThrowsIfThereIsNoSuchEntryInNameToServiceIdMap() |
39
|
|
|
{ |
40
|
|
|
$container = new Container(); |
41
|
|
|
|
42
|
|
|
$registry = new PagerPersisterRegistry([ |
43
|
|
|
'the_name' => 'the_service_id', |
44
|
|
|
]); |
45
|
|
|
$registry->setContainer($container); |
46
|
|
|
|
47
|
|
|
$this->setExpectedException(\InvalidArgumentException::class, 'No pager persister was registered for the give name "the_other_name".'); |
|
|
|
|
48
|
|
|
$registry->getPagerPersister('the_other_name'); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
View Code Duplication |
public function testThrowsIfRelatedServiceDoesNotImplementPagerPersisterInterface() |
52
|
|
|
{ |
53
|
|
|
$container = new Container(); |
54
|
|
|
$container->set('the_service_id', new \stdClass()); |
55
|
|
|
|
56
|
|
|
$registry = new PagerPersisterRegistry([ |
57
|
|
|
'the_name' => 'the_service_id', |
58
|
|
|
]); |
59
|
|
|
$registry->setContainer($container); |
60
|
|
|
|
61
|
|
|
$this->setExpectedException(\LogicException::class, 'The pager provider service "the_service_id" must implement "FOS\ElasticaBundle\Persister\PagerPersisterInterface" interface but it is an instance of "stdClass" class.'); |
|
|
|
|
62
|
|
|
$registry->getPagerPersister('the_name'); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
View Code Duplication |
public function testThrowsIfThereIsServiceWithSuchId() |
66
|
|
|
{ |
67
|
|
|
$container = new Container(); |
68
|
|
|
|
69
|
|
|
$registry = new PagerPersisterRegistry([ |
70
|
|
|
'the_name' => 'the_service_id', |
71
|
|
|
]); |
72
|
|
|
$registry->setContainer($container); |
73
|
|
|
|
74
|
|
|
$this->setExpectedException(\LogicException::class, 'You have requested a non-existent service "the_service_id".'); |
|
|
|
|
75
|
|
|
$registry->getPagerPersister('the_name'); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
public function testShouldReturnPagerPersisterByGivenName() |
79
|
|
|
{ |
80
|
|
|
$pagerPersisterMock = $this->createPagerPersisterMock(); |
81
|
|
|
|
82
|
|
|
$container = new Container(); |
83
|
|
|
$container->set('the_service_id', $pagerPersisterMock); |
84
|
|
|
|
85
|
|
|
$registry = new PagerPersisterRegistry([ |
86
|
|
|
'the_name' => 'the_service_id', |
87
|
|
|
]); |
88
|
|
|
$registry->setContainer($container); |
89
|
|
|
|
90
|
|
|
$actualPagerPersister = $registry->getPagerPersister('the_name'); |
91
|
|
|
|
92
|
|
|
$this->assertSame($pagerPersisterMock, $actualPagerPersister); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* @return PagerPersisterInterface|\PHPUnit_Framework_MockObject_MockObject |
97
|
|
|
*/ |
98
|
|
|
private function createPagerPersisterMock() |
99
|
|
|
{ |
100
|
|
|
return $this->getMock(PagerPersisterInterface::class); |
|
|
|
|
101
|
|
|
} |
102
|
|
|
} |
103
|
|
|
|
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.