TwigBundlePassTest   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 4
eloc 22
dl 0
loc 54
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A testWithTwigRoutingExtension() 0 10 1
A testWithTwig() 0 12 1
A testWithoutTwig() 0 6 1
A setUp() 0 8 1
1
<?php
2
3
/*
4
 *
5
 * (c) Yaroslav Honcharuk <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace Yarhon\RouteGuardBundle\Tests\DependencyInjection\Compiler;
12
13
use PHPUnit\Framework\TestCase;
14
use Symfony\Component\DependencyInjection\ContainerBuilder;
15
use Yarhon\RouteGuardBundle\DependencyInjection\Compiler\TwigBundlePass;
16
use Yarhon\RouteGuardBundle\Twig\Extension\RoutingExtension;
17
use Yarhon\RouteGuardBundle\Twig\RoutingRuntime;
18
19
/**
20
 * @author Yaroslav Honcharuk <[email protected]>
21
 */
22
class TwigBundlePassTest extends TestCase
23
{
24
    /**
25
     * @var ContainerBuilder
26
     */
27
    private $container;
28
29
    /**
30
     * @var TwigBundlePass
31
     */
32
    private $pass;
33
34
    public function setUp()
35
    {
36
        $this->container = new ContainerBuilder();
37
        $this->container->register(RoutingExtension::class)
38
            ->setArgument(0, []);
39
        $this->container->register(RoutingRuntime::class);
40
41
        $this->pass = new TwigBundlePass();
42
    }
43
44
    public function testWithoutTwig()
45
    {
46
        $this->pass->process($this->container);
47
48
        $this->assertFalse($this->container->hasDefinition(RoutingExtension::class));
49
        $this->assertFalse($this->container->hasDefinition(RoutingRuntime::class));
50
    }
51
52
    public function testWithTwig()
53
    {
54
        $this->container->register('twig');
55
56
        $this->pass->process($this->container);
57
58
        $this->assertTrue($this->container->hasDefinition(RoutingExtension::class));
59
        $this->assertTrue($this->container->hasDefinition(RoutingRuntime::class));
60
61
        $options = $this->container->getDefinition(RoutingExtension::class)->getArgument(0);
62
63
        $this->assertEquals(['discover_routing_functions' => false], $options);
64
    }
65
66
    public function testWithTwigRoutingExtension()
67
    {
68
        $this->container->register('twig');
69
        $this->container->register('twig.extension.routing');
70
71
        $this->pass->process($this->container);
72
73
        $options = $this->container->getDefinition(RoutingExtension::class)->getArgument(0);
74
75
        $this->assertEquals([], $options);
76
    }
77
}
78