Passed
Pull Request — master (#3)
by Vincent
08:42
created

PrimeConnectionFactoryPassTest   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 19
c 1
b 0
f 0
dl 0
loc 38
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A test_services_are_ordered_according_to_priority() 0 19 1
A test_throw_exception_when_no_loaders() 0 9 1
1
<?php
2
3
namespace Bdf\PrimeBundle\Tests\DependencyInjection\Compiler;
4
5
use Bdf\Prime\Connection\Factory\ChainFactory;
6
use Bdf\PrimeBundle\DependencyInjection\Compiler\PrimeConnectionFactoryPass;
7
use PHPUnit\Framework\TestCase;
8
use Symfony\Component\DependencyInjection\ContainerBuilder;
9
use Symfony\Component\DependencyInjection\Reference;
10
11
/**
12
 *
13
 */
14
class PrimeConnectionFactoryPassTest extends TestCase
15
{
16
    /**
17
     *
18
     */
19
    public function test_throw_exception_when_no_loaders()
20
    {
21
        $this->expectException(\RuntimeException::class);
22
        $this->expectExceptionMessage('You must tag at least one service as "bdf_prime.connection_factory" to use the "'.ChainFactory::class.'" service');
23
        $container = new ContainerBuilder();
24
        $container->register(ChainFactory::class);
25
26
        $serializerPass = new PrimeConnectionFactoryPass();
27
        $serializerPass->process($container);
28
    }
29
30
    /**
31
     *
32
     */
33
    public function test_services_are_ordered_according_to_priority()
34
    {
35
        $container = new ContainerBuilder();
36
37
        $definition = $container->register(ChainFactory::class)->setArguments([null]);
38
        $container->register('n2')->addTag('bdf_prime.connection_factory', ['priority' => 100]);
39
        $container->register('n1')->addTag('bdf_prime.connection_factory', ['priority' => 200]);
40
        $container->register('n3')->addTag('bdf_prime.connection_factory');
41
42
        $serializerPass = new PrimeConnectionFactoryPass();
43
        $serializerPass->process($container);
44
45
        $expected = [
46
            new Reference('n1'),
47
            new Reference('n2'),
48
            new Reference('n3'),
49
        ];
50
51
        $this->assertEquals($expected, $definition->getArgument(0));
52
    }
53
}