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 extends AbstractExtension |
14
|
|
|
{ |
15
|
|
|
/** @var Extension[] */ |
16
|
|
|
private $subExtensionList = []; |
17
|
|
|
|
18
|
7 |
|
public function __construct(Extension $kernelSubExtension = null, Extension $loggerSubExtension = null) |
19
|
|
|
{ |
20
|
7 |
|
$this->subExtensionList[] = $kernelSubExtension ?: new KernelSubExtension(); |
21
|
7 |
|
$this->subExtensionList[] = $loggerSubExtension ?: new LoggerSubExtension(); |
22
|
7 |
|
} |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* {@inheritdoc} |
26
|
|
|
*/ |
27
|
1 |
|
public function getConfigKey() |
28
|
|
|
{ |
29
|
1 |
|
return 'behat3_symfony'; |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
// @codeCoverageIgnoreStart |
33
|
|
|
// Not possible to cover this because ExtensionManager is a final class |
34
|
|
|
// Will be covered by FT |
35
|
|
|
/** |
36
|
|
|
* {@inheritdoc} |
37
|
|
|
*/ |
38
|
|
|
public function initialize(ExtensionManager $extensionManager) |
39
|
|
|
{ |
40
|
|
|
foreach ($this->subExtensionList as $subExtension) { |
41
|
|
|
$subExtension->initialize($extensionManager); |
42
|
|
|
} |
43
|
|
|
} |
44
|
|
|
// @codeCoverageIgnoreEnd |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* {@inheritdoc} |
48
|
|
|
*/ |
49
|
1 |
|
public function configure(ArrayNodeDefinition $builder) |
50
|
|
|
{ |
51
|
1 |
|
foreach ($this->subExtensionList as $subExtension) { |
52
|
1 |
|
$subExtension->configure( |
53
|
1 |
|
$builder->children() |
54
|
1 |
|
->arrayNode($subExtension->getConfigKey()) |
55
|
1 |
|
); |
56
|
1 |
|
} |
57
|
1 |
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* {@inheritdoc} |
61
|
|
|
*/ |
62
|
4 |
|
public function load(ContainerBuilder $container, array $config) |
63
|
|
|
{ |
64
|
4 |
|
foreach ($config['kernel'] as $key => $value) { |
65
|
4 |
|
$container->setParameter(sprintf('behat3_symfony_extension.kernel.%s', $key), $value); |
66
|
4 |
|
} |
67
|
4 |
|
foreach ($config['logger'] as $key => $value) { |
68
|
4 |
|
$container->setParameter(sprintf('behat3_symfony_extension.logger.%s', $key), $value); |
69
|
4 |
|
} |
70
|
4 |
|
$loader = new XmlFileLoader( |
71
|
4 |
|
$container, |
72
|
4 |
|
new FileLocator(__DIR__.'/../Resources/config') |
73
|
4 |
|
); |
74
|
|
|
|
75
|
4 |
|
$loader->load('client.xml'); |
76
|
4 |
|
$loader->load('kernel.xml'); |
77
|
4 |
|
$loader->load('initializer.xml'); |
78
|
4 |
|
$loader->load('logger.xml'); |
79
|
4 |
|
if (true === $config['kernel']['reboot']) { |
80
|
2 |
|
$loader->load('kernel_auto_reboot.xml'); |
81
|
2 |
|
} |
82
|
4 |
|
if (true === $config['kernel']['debug']) { |
83
|
2 |
|
$loader->load('kernel_debug_mode.xml'); |
84
|
2 |
|
} |
85
|
4 |
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* {@inheritdoc} |
89
|
|
|
*/ |
90
|
1 |
|
public function process(ContainerBuilder $container) |
91
|
|
|
{ |
92
|
1 |
|
foreach ($this->subExtensionList as $subExtension) { |
93
|
1 |
|
$subExtension->process($container); |
94
|
1 |
|
} |
95
|
1 |
|
} |
96
|
|
|
} |
97
|
|
|
|