forked from KnpLabs/KnpPaginatorBundle
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPaginatorAwarePassTest.php
More file actions
68 lines (55 loc) · 2.79 KB
/
PaginatorAwarePassTest.php
File metadata and controls
68 lines (55 loc) · 2.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<?php
namespace Knp\Bundle\PaginatorBundle\Tests\DependencyInjection\Compiler;
use Knp\Bundle\PaginatorBundle\Definition\PaginatorAwareInterface;
use Knp\Bundle\PaginatorBundle\DependencyInjection\Compiler\PaginatorAwarePass;
use Knp\Component\Pager\PaginatorInterface;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Config\Definition\Exception\InvalidDefinitionException;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Loader\PhpFileLoader;
use Symfony\Component\DependencyInjection\Reference;
final class PaginatorAwarePassTest extends TestCase
{
public function testCorrectPassProcess(): void
{
$container = new ContainerBuilder();
$container->register('knp.paginator');
$container->register('tag.one', PaginatorAwareInterface::class)
->addTag(PaginatorAwarePass::PAGINATOR_AWARE_TAG, ['paginator' => 'knp.paginator']);
(new PaginatorAwarePass())->process($container);
self::assertEquals(
[['setPaginator', [new Reference('knp.paginator')]]],
$container->getDefinition('tag.one')->getMethodCalls()
);
}
public function testExceptionWrongInterface(): void
{
$container = new ContainerBuilder();
$container->register('knp.paginator');
$container->register('tag.one', 'stdClass')
->addTag(PaginatorAwarePass::PAGINATOR_AWARE_TAG, ['paginator' => 'knp.paginator']);
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage('Service "tag.one" must implement interface "Knp\\Bundle\\PaginatorBundle\\Definition\\PaginatorAwareInterface".');
(new PaginatorAwarePass())->process($container);
}
public function testExceptionNoPaginator(): void
{
$container = new ContainerBuilder();
$container->register('tag.one', PaginatorAwareInterface::class)
->addTag(PaginatorAwarePass::PAGINATOR_AWARE_TAG, ['paginator' => 'INVALID']);
$this->expectException(InvalidDefinitionException::class);
$this->expectExceptionMessage('Paginator service "INVALID" for tag "knp_paginator.injectable" on service "tag.one" could not be found.');
(new PaginatorAwarePass())->process($container);
}
public function testProxyAndLazy(): void
{
$container = new ContainerBuilder();
$loader = new PhpFileLoader($container, new FileLocator(__DIR__.'/../../../config'));
$loader->load('paginator.php');
$container->register('knp.paginator');
$definition = $container->getDefinition('knp_paginator');
$this->assertSame([['interface' => PaginatorInterface::class]], $definition->getTag('proxy'));
$this->assertTrue($definition->isLazy());
}
}