GtmExtensionTest   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 76
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 5
Bugs 1 Features 0
Metric Value
wmc 5
c 5
b 1
f 0
lcom 1
cbo 4
dl 0
loc 76
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 7 1
A loadConfiguration() 0 5 1
A testWithoutConfiguration() 0 12 1
A testWithId() 0 9 1
A testWithOutId() 0 11 1
1
<?php
2
3
namespace Evheniy\GtmBundle\Tests\DependencyInjection;
4
5
use Symfony\Component\DependencyInjection\ContainerBuilder;
6
use Symfony\Component\Config\FileLocator;
7
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
8
use Evheniy\GtmBundle\DependencyInjection\GtmExtension;
9
10
/**
11
 * Class GtmExtensionTest
12
 *
13
 * @package Evheniy\GtmBundle\Tests\DependencyInjection
14
 */
15
class GtmExtensionTest extends \PHPUnit_Framework_TestCase
16
{
17
    /**
18
     * @var GtmExtension
19
     */
20
    private $extension;
21
    /**
22
     * @var ContainerBuilder
23
     */
24
    private $container;
25
26
    /**
27
     *
28
     */
29
    protected function setUp()
30
    {
31
        $this->extension = new GtmExtension();
32
33
        $this->container = new ContainerBuilder();
34
        $this->container->registerExtension($this->extension);
35
    }
36
37
    /**
38
     * @param ContainerBuilder $container
39
     * @param string           $resource
40
     */
41
    protected function loadConfiguration(ContainerBuilder $container, $resource)
42
    {
43
        $loader = new YamlFileLoader($container, new FileLocator(__DIR__ . '/Fixtures/'));
44
        $loader->load($resource . '.yml');
45
    }
46
47
    /**
48
     * Test empty config
49
     */
50
    public function testWithoutConfiguration()
51
    {
52
        $this->setExpectedException(
53
            'Symfony\Component\Config\Definition\Exception\InvalidConfigurationException',
54
            'The child node "id" at path "gtm" must be configured.'
55
        );
56
57
        $this->container->loadFromExtension($this->extension->getAlias());
58
        $this->container->compile();
59
60
        $this->assertFalse($this->container->hasParameter('gtm'));
61
    }
62
63
    /**
64
     * Test normal config
65
     */
66
    public function testWithId()
67
    {
68
        $this->loadConfiguration($this->container, 'withId');
69
        $this->container->compile();
70
        $this->assertTrue($this->container->hasParameter('gtm'));
71
        $gtm = $this->container->getParameter('gtm');
72
        $this->assertNotEmpty($gtm['id']);
73
        $this->assertEquals($gtm['id'], 'test');
74
    }
75
76
    /**
77
     * Test wrong config
78
     */
79
    public function testWithOutId()
80
    {
81
        $this->setExpectedException(
82
            'Symfony\Component\Config\Definition\Exception\InvalidConfigurationException',
83
            'The child node "id" at path "gtm" must be configured.'
84
        );
85
86
        $this->loadConfiguration($this->container, 'withOutId');
87
        $this->container->compile();
88
        $this->assertFalse($this->container->hasParameter('gtm'));
89
    }
90
}