Completed
Pull Request — master (#25)
by Yo
04:49 queued 02:28
created

Behat3SymfonyExtension   A

Complexity

Total Complexity 15

Size/Duplication

Total Lines 86
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 8

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 15
lcom 1
cbo 8
dl 0
loc 86
ccs 41
cts 41
cp 1
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 3
A getConfigKey() 0 4 1
A initialize() 0 6 2
A configure() 0 9 2
B load() 0 24 5
A process() 0 6 2
1
<?php
2
namespace Yoanm\Behat3SymfonyExtension\ServiceContainer;
3
4
use Behat\Testwork\ServiceContainer\Extension;
5
use Behat\Testwork\ServiceContainer\ExtensionManager;
6
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
7
use Symfony\Component\Config\FileLocator;
8
use Symfony\Component\DependencyInjection\ContainerBuilder;
9
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
10
use Yoanm\Behat3SymfonyExtension\ServiceContainer\SubExtension\KernelSubExtension;
11
use Yoanm\Behat3SymfonyExtension\ServiceContainer\SubExtension\LoggerSubExtension;
12
13
class Behat3SymfonyExtension implements Extension
14
{
15
    const TEST_CLIENT_SERVICE_ID = 'behat3_symfony_extension.test.client';
16
17
    /** @var Extension[] */
18
    private $subExtensionList = [];
19
20 7
    public function __construct(Extension $kernelSubExtension = null, Extension $loggerSubExtension = null)
21
    {
22 7
        $this->subExtensionList[] = $kernelSubExtension ?: new KernelSubExtension();
23 7
        $this->subExtensionList[] = $loggerSubExtension ?: new LoggerSubExtension();
24 7
    }
25
26
    /**
27
     * {@inheritdoc}
28
     */
29 1
    public function getConfigKey()
30
    {
31 1
        return 'behat3_symfony';
32
    }
33
34
    // @codeCoverageIgnoreStart
35
    // Not possible to cover this because ExtensionManager is a final class
36
    // Will be covered by FT
37
    /**
38
     * {@inheritdoc}
39
     */
40
    public function initialize(ExtensionManager $extensionManager)
41
    {
42
        foreach ($this->subExtensionList as $subExtension) {
43
            $subExtension->initialize($extensionManager);
44
        }
45
    }
46
    // @codeCoverageIgnoreEnd
47
48
    /**
49
     * {@inheritdoc}
50
     */
51 1
    public function configure(ArrayNodeDefinition $builder)
52
    {
53 1
        foreach ($this->subExtensionList as $subExtension) {
54 1
            $subExtension->configure(
55 1
                $builder->children()
56 1
                    ->arrayNode($subExtension->getConfigKey())
57 1
            );
58 1
        }
59 1
    }
60
61
    /**
62
     * {@inheritdoc}
63
     */
64 4
    public function load(ContainerBuilder $container, array $config)
65
    {
66 4
        foreach ($config['kernel'] as $key => $value) {
67 4
            $container->setParameter(sprintf('behat3_symfony_extension.kernel.%s', $key), $value);
68 4
        }
69 4
        foreach ($config['logger'] as $key => $value) {
70 4
            $container->setParameter(sprintf('behat3_symfony_extension.logger.%s', $key), $value);
71 4
        }
72 4
        $loader = new XmlFileLoader(
73 4
            $container,
74 4
            new FileLocator(__DIR__.'/../Resources/config')
75 4
        );
76
77 4
        $loader->load('client.xml');
78 4
        $loader->load('kernel.xml');
79 4
        $loader->load('initializer.xml');
80 4
        $loader->load('logger.xml');
81 4
        if (true === $config['kernel']['reboot']) {
82 2
            $loader->load('kernel_auto_reboot.xml');
83 2
        }
84 4
        if (true === $config['kernel']['debug']) {
85 2
            $loader->load('kernel_debug_mode.xml');
86 2
        }
87 4
    }
88
89
    /**
90
     * {@inheritdoc}
91
     */
92 1
    public function process(ContainerBuilder $container)
93
    {
94 1
        foreach ($this->subExtensionList as $subExtension) {
95 1
            $subExtension->process($container);
96 1
        }
97 1
    }
98
}
99