Passed
Pull Request — master (#5)
by Vincent
03:09
created

testServicesAreOrderedAccordingToPriority()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 19
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 1
Metric Value
eloc 12
nc 1
nop 0
dl 0
loc 19
c 1
b 1
f 1
cc 1
rs 9.8666
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
class PrimeConnectionFactoryPassTest extends TestCase
12
{
13
    public function testThrowExceptionWhenNoLoaders()
14
    {
15
        $this->expectException(\RuntimeException::class);
16
        $this->expectExceptionMessage('You must tag at least one service as "bdf_prime.connection_factory" to use the "'.ChainFactory::class.'" service');
17
        $container = new ContainerBuilder();
18
        $container->register(ChainFactory::class);
19
20
        $serializerPass = new PrimeConnectionFactoryPass();
21
        $serializerPass->process($container);
22
    }
23
24
    public function testServicesAreOrderedAccordingToPriority()
25
    {
26
        $container = new ContainerBuilder();
27
28
        $definition = $container->register(ChainFactory::class)->setArguments([null]);
29
        $container->register('n2')->addTag('bdf_prime.connection_factory', ['priority' => 100]);
30
        $container->register('n1')->addTag('bdf_prime.connection_factory', ['priority' => 200]);
31
        $container->register('n3')->addTag('bdf_prime.connection_factory');
32
33
        $serializerPass = new PrimeConnectionFactoryPass();
34
        $serializerPass->process($container);
35
36
        $expected = [
37
            new Reference('n1'),
38
            new Reference('n2'),
39
            new Reference('n3'),
40
        ];
41
42
        $this->assertEquals($expected, $definition->getArgument(0));
43
    }
44
}
45