Completed
Push — refonte ( 7173e3...bffa4c )
by Arnaud
02:33
created

DataProviderCompilerPassTest   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 5
dl 0
loc 59
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace LAG\AdminBundle\Tests\DependencyInjection\CompilerPass;
4
5
use LAG\AdminBundle\DependencyInjection\CompilerPass\DataProviderCompilerPass;
6
use LAG\AdminBundle\Factory\DataProviderFactory;
7
use LAG\AdminBundle\Tests\AdminTestBase;
8
use Symfony\Component\DependencyInjection\ContainerBuilder;
9
use Symfony\Component\DependencyInjection\Definition;
10
use Symfony\Component\DependencyInjection\Reference;
11
12
class DataProviderCompilerPassTest extends AdminTestBase
13
{
14
    /**
15
     * Process method should add the definition of the tagged services to the data providers factory.
16
     */
17
    public function testProcess()
18
    {
19
        $definition = $this->getMockWithoutConstructor(Definition::class);
20
        $definition
21
            ->expects($this->once())
22
            ->method('addMethodCall')
23
            ->with('add', [
24
                'data_provider',
25
                new Reference('data_provider'),
26
            ])
27
        ;
28
        $builder = $this->getMockWithoutConstructor(ContainerBuilder::class);
29
        $builder
30
            ->expects($this->once())
31
            ->method('findDefinition')
32
            ->with(DataProviderFactory::class)
33
            ->willReturn($definition)
34
        ;
35
        $builder
36
            ->expects($this->once())
37
            ->method('has')
38
            ->with(DataProviderFactory::class)
39
            ->willReturn(true)
40
        ;
41
        $builder
42
            ->expects($this->once())
43
            ->method('findTaggedServiceIds')
44
            ->with('lag.admin.data_provider')
45
            ->willReturn([
46
                'data_provider' => [],
47
            ])
48
        ;
49
50
        $compilerPass = new DataProviderCompilerPass();
51
        $compilerPass->process($builder);
52
    }
53
54
    public function testProcessWithoutConfiguration()
55
    {
56
        $builder = $this->getMockWithoutConstructor(ContainerBuilder::class);
57
58
        $compilerPass = new DataProviderCompilerPass();
59
        $compilerPass->process($builder);
60
61
        $builder
62
            ->expects($this->never())
63
            ->method('findDefinition')
64
        ;
65
        $builder
66
            ->expects($this->never())
67
            ->method('findTaggedServiceIds')
68
        ;
69
    }
70
}
71