testCollectEnums()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 16
rs 9.7333
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php declare(strict_types=1);
2
3
namespace Yokai\EnumBundle\Tests\DependencyInjection\CompilerPass;
4
5
use Symfony\Component\DependencyInjection\ContainerBuilder;
6
use Symfony\Component\DependencyInjection\Definition;
7
use Symfony\Component\DependencyInjection\Reference;
8
use Yokai\EnumBundle\DependencyInjection\CompilerPass\TaggedEnumCollectorCompilerPass;
9
use Yokai\EnumBundle\Tests\TestCase;
10
11
/**
12
 * @author Yann Eugoné <[email protected]>
13
 */
14
class TaggedEnumCollectorCompilerPassTest extends TestCase
15
{
16
    /**
17
     * @var TaggedEnumCollectorCompilerPass
18
     */
19
    private $compiler;
20
21
    protected function setUp(): void
22
    {
23
        $this->compiler = new TaggedEnumCollectorCompilerPass;
24
    }
25
26
    public function testCollectWhenServiceNotAvailable(): void
27
    {
28
        $compiler = $this->prophesize(ContainerBuilder::class);
29
        $compiler->hasDefinition('enum.registry')->shouldBeCalled()->willReturn(false);
30
31
        $this->compiler->process($compiler->reveal());
32
    }
33
34
    public function testCollectEnums(): void
35
    {
36
        $registry = $this->prophesize(Definition::class);
37
        $registry->addMethodCall('add', [new Reference('enum.gender')])->shouldBeCalled();
38
        $registry->addMethodCall('add', [new Reference('enum.type')])->shouldBeCalled();
39
40
        $compiler = $this->prophesize(ContainerBuilder::class);
41
        $compiler->hasDefinition('enum.registry')->shouldBeCalled()->willReturn(true);
42
        $compiler->getDefinition('enum.registry')->shouldBeCalled()->willReturn($registry);
43
        $compiler->findTaggedServiceIds('enum')->shouldBeCalled()->willReturn([
44
            'enum.gender' => $this->prophesize(Definition::class)->reveal(),
45
            'enum.type' => $this->prophesize(Definition::class)->reveal(),
46
        ]);
47
48
        $this->compiler->process($compiler->reveal());
49
    }
50
}
51