Skip to content

Commit 7c74926

Browse files
committed
Adapt tests
1 parent 895a7a6 commit 7c74926

File tree

4 files changed

+29
-70
lines changed

4 files changed

+29
-70
lines changed

src/Finder/PaginatedFinderInterface.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
namespace FOS\ElasticaBundle\Finder;
1313

14-
use Elastica\Query;
1514
use FOS\ElasticaBundle\Paginator\PaginatorAdapterInterface;
1615
use Pagerfanta\Pagerfanta;
1716

tests/Unit/DependencyInjection/FOSElasticaExtensionTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -390,9 +390,9 @@ public function testShouldRegisterPagerPersisterRegisterService()
390390

391391
$this->assertTrue($container->hasDefinition('fos_elastica.pager_persister_registry'));
392392

393-
$listener = $container->getDefinition('fos_elastica.pager_persister_registry');
394-
$this->assertSame(PagerPersisterRegistry::class, $listener->getClass());
395-
$this->assertSame([], $listener->getArgument(0));
393+
$registry = $container->getDefinition('fos_elastica.pager_persister_registry');
394+
$this->assertSame(PagerPersisterRegistry::class, $registry->getClass());
395+
$this->assertCount(0, $registry->getArgument(0)->getTaggedIteratorArgument()->getValues());
396396
}
397397

398398
public function testShouldRegisterDoctrineORMListener()

tests/Unit/Persister/AsyncPagerPersisterTest.php

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
use FOS\ElasticaBundle\Provider\PagerProviderInterface;
2323
use FOS\ElasticaBundle\Provider\PagerProviderRegistry;
2424
use PHPUnit\Framework\TestCase;
25-
use Symfony\Component\DependencyInjection\ContainerInterface;
2625
use Symfony\Component\DependencyInjection\ServiceLocator;
2726
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
2827
use Symfony\Component\Messenger\Envelope;
@@ -38,7 +37,7 @@ public function testShouldImplementPagerPersisterInterface()
3837

3938
public function testInsertDispatchAsyncPersistPageObject()
4039
{
41-
$pagerPersisterRegistry = new PagerPersisterRegistry([]);
40+
$pagerPersisterRegistry = new PagerPersisterRegistry($this->createMock(ServiceLocator::class));
4241
$pagerProviderRegistry = $this->createMock(PagerProviderRegistry::class);
4342
$messageBus = $this->createMock(MessageBusInterface::class);
4443
$sut = new AsyncPagerPersister($pagerPersisterRegistry, $pagerProviderRegistry, $messageBus);
@@ -57,24 +56,20 @@ function ($message) {
5756

5857
public function testInsertPageReturnObjectCount()
5958
{
60-
$pagerPersisterRegistry = new PagerPersisterRegistry(
61-
[
62-
InPlacePagerPersister::NAME => 'my_service',
63-
]
64-
);
65-
66-
$serviceLocator = $this->createMock(ServiceLocator::class);
67-
$serviceLocator->expects($this->once())->method('has')->with('foo')->willReturn(true);
68-
$serviceLocator->expects($this->once())->method('get')->with('foo')->willReturn($this->createMock(ObjectPersisterInterface::class));
59+
$persistersLocator = $this->createMock(ServiceLocator::class);
60+
$persistersLocator->expects($this->once())->method('has')->with('foo')->willReturn(true);
61+
$persistersLocator->expects($this->once())->method('get')->with('foo')->willReturn($this->createMock(ObjectPersisterInterface::class));
6962

70-
$container = $this->createMock(ContainerInterface::class);
71-
$container->expects($this->once())->method('get')->with('my_service')->willReturn(
63+
$pagerPersistersLocator = $this->createMock(ServiceLocator::class);
64+
$pagerPersistersLocator->expects($this->once())->method('has')->with('in_place')->willReturn(true);
65+
$pagerPersistersLocator->expects($this->once())->method('get')->with('in_place')->willReturn(
7266
new InPlacePagerPersister(
73-
new PersisterRegistry($serviceLocator),
67+
new PersisterRegistry($persistersLocator),
7468
$this->createMock(EventDispatcherInterface::class)
7569
)
7670
);
77-
$pagerPersisterRegistry->setContainer($container);
71+
72+
$pagerPersisterRegistry = new PagerPersisterRegistry($pagerPersistersLocator);
7873

7974
$pagerMock = $this->createMock(PagerInterface::class);
8075
$pagerMock->expects($this->exactly(2))->method('setMaxPerPage')->with(10);

tests/Unit/Persister/PagerPersisterRegistryTest.php

Lines changed: 16 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -12,84 +12,49 @@
1212
namespace FOS\ElasticaBundle\Persister;
1313

1414
use PHPUnit\Framework\TestCase;
15-
use Symfony\Component\DependencyInjection\Container;
16-
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
15+
use Symfony\Component\DependencyInjection\ServiceLocator;
1716

1817
class PagerPersisterRegistryTest extends TestCase
1918
{
20-
public function testShouldImplementContainerAwareInterface()
21-
{
22-
$rc = new \ReflectionClass(PagerPersisterRegistry::class);
23-
24-
$this->assertTrue($rc->implementsInterface(ContainerAwareInterface::class));
25-
}
26-
2719
public function testShouldBeFinal()
2820
{
2921
$rc = new \ReflectionClass(PagerPersisterRegistry::class);
3022

3123
$this->assertTrue($rc->isFinal());
3224
}
3325

34-
public function testCouldBeConstructedWithNameToServiceIdMap()
35-
{
36-
new PagerPersisterRegistry([]);
37-
}
38-
3926
public function testThrowsIfThereIsNoSuchEntryInNameToServiceIdMap()
4027
{
41-
$container = new Container();
42-
43-
$registry = new PagerPersisterRegistry([
44-
'the_name' => 'the_service_id',
45-
]);
46-
$registry->setContainer($container);
28+
$serviceLocator = $this->createMock(ServiceLocator::class);
29+
$serviceLocator->expects($this->once())->method('has')->with('the_name')->willReturn(false);
4730

4831
$this->expectException(\InvalidArgumentException::class);
49-
$this->expectExceptionMessage('No pager persister was registered for the give name "the_other_name".');
50-
$registry->getPagerPersister('the_other_name');
51-
}
32+
$this->expectExceptionMessage('No pager persister was registered for the give name "the_name".');
5233

53-
public function testThrowsIfRelatedServiceDoesNotImplementPagerPersisterInterface()
54-
{
55-
$container = new Container();
56-
$container->set('the_service_id', new \stdClass());
57-
58-
$registry = new PagerPersisterRegistry([
59-
'the_name' => 'the_service_id',
60-
]);
61-
$registry->setContainer($container);
62-
63-
$this->expectException(\LogicException::class);
64-
$this->expectExceptionMessage('The pager provider service "the_service_id" must implement "FOS\ElasticaBundle\Persister\PagerPersisterInterface" interface but it is an instance of "stdClass" class.');
65-
$registry->getPagerPersister('the_name');
34+
(new PagerPersisterRegistry($serviceLocator))->getPagerPersister('the_name');
6635
}
6736

68-
public function testThrowsIfThereIsServiceWithSuchId()
37+
public function testThrowsIfRelatedServiceDoesNotImplementPagerPersisterInterface()
6938
{
70-
$container = new Container();
39+
$serviceLocator = $this->createMock(ServiceLocator::class);
40+
$serviceLocator->expects($this->once())->method('has')->with('the_name')->willReturn(true);
41+
$serviceLocator->expects($this->once())->method('get')->with('the_name')->willReturn(new \stdClass());
7142

72-
$registry = new PagerPersisterRegistry([
73-
'the_name' => 'the_service_id',
74-
]);
75-
$registry->setContainer($container);
43+
$this->expectException(\TypeError::class);
44+
$this->expectExceptionMessage('Return value of FOS\ElasticaBundle\Persister\PagerPersisterRegistry::getPagerPersister() must implement interface FOS\ElasticaBundle\Persister\PagerPersisterInterface, instance of stdClass returned');
7645

77-
$this->expectException(\LogicException::class);
78-
$this->expectExceptionMessage('You have requested a non-existent service "the_service_id".');
79-
$registry->getPagerPersister('the_name');
46+
(new PagerPersisterRegistry($serviceLocator))->getPagerPersister('the_name');
8047
}
8148

8249
public function testShouldReturnPagerPersisterByGivenName()
8350
{
8451
$pagerPersisterMock = $this->createPagerPersisterMock();
8552

86-
$container = new Container();
87-
$container->set('the_service_id', $pagerPersisterMock);
53+
$serviceLocator = $this->createMock(ServiceLocator::class);
54+
$serviceLocator->expects($this->once())->method('has')->with('the_name')->willReturn(true);
55+
$serviceLocator->expects($this->once())->method('get')->with('the_name')->willReturn($pagerPersisterMock);
8856

89-
$registry = new PagerPersisterRegistry([
90-
'the_name' => 'the_service_id',
91-
]);
92-
$registry->setContainer($container);
57+
$registry = new PagerPersisterRegistry($serviceLocator);
9358

9459
$actualPagerPersister = $registry->getPagerPersister('the_name');
9560

0 commit comments

Comments
 (0)