Passed
Push — master ( 23152a...a65783 )
by Povilas
02:36
created

ListCompilerPassTest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 5
eloc 37
dl 0
loc 50
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A testProcess() 0 39 4
A setUp() 0 4 1
1
<?php
2
3
namespace Povs\ListerBundle\DependencyInjection\Compiler;
4
5
use PHPUnit\Framework\TestCase;
6
use Symfony\Component\DependencyInjection\Argument\ServiceClosureArgument;
7
use Symfony\Component\DependencyInjection\ContainerBuilder;
8
use Symfony\Component\DependencyInjection\Definition;
9
use Symfony\Component\DependencyInjection\Reference;
10
11
/**
12
 * @author Povilas Margaiatis <[email protected]>
13
 */
14
class ListCompilerPassTest extends TestCase
15
{
16
    private $compilerPass;
17
    private $containerBuilder;
18
19
    public function setUp()
20
    {
21
        $this->compilerPass = new ListCompilerPass();
22
        $this->containerBuilder = $this->createMock(ContainerBuilder::class);
23
    }
24
25
    public function testProcess(): void
26
    {
27
        $locatorDefinitionMock = $this->createMock(Definition::class);
28
        $this->containerBuilder->expects($this->exactly(6))
29
            ->method('findTaggedServiceIds')
30
            ->withConsecutive(
31
                ['povs_lister.list', true],
32
                ['povs_lister.query_type', true],
33
                ['povs_lister.field_type', true],
34
                ['povs_lister.list_type', true],
35
                ['povs_lister.filter_type', true],
36
                ['povs_lister.selector_type', true]
37
            )
38
            ->willReturn([
39
                'id' => ['tag'],
40
            ]);
41
        $this->containerBuilder->expects($this->exactly(6))
42
            ->method('getDefinition')
43
            ->withConsecutive(
44
                ['.povs_lister.locator.list'],
45
                ['.povs_lister.locator.query_type'],
46
                ['.povs_lister.locator.field_type'],
47
                ['.povs_lister.locator.list_type'],
48
                ['.povs_lister.locator.filter_type'],
49
                ['.povs_lister.locator.selector_type']
50
            )
51
            ->willReturn($locatorDefinitionMock);
52
        $locatorDefinitionMock->expects($this->exactly(6))
53
            ->method('setArgument')
54
            ->with(0, $this->callback(static function ($arg) {
55
                $argument = $arg['id'];
56
                $value = $argument->getValues()[0];
57
                return count($arg) === 1 &&
58
                    $argument instanceof ServiceClosureArgument &&
59
                    $value instanceof Reference &&
60
                    (string) $value === 'id';
61
            }));
62
63
        $this->compilerPass->process($this->containerBuilder);
64
    }
65
}
66