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 Symfony\Component\DependencyInjection\Reference; |
11
|
|
|
use Yoanm\Behat3SymfonyExtension\Context\Initializer\BehatContextSubscriberInitializer; |
12
|
|
|
use Yoanm\Behat3SymfonyExtension\ServiceContainer\SubExtension\KernelSubExtension; |
13
|
|
|
use Yoanm\Behat3SymfonyExtension\ServiceContainer\SubExtension\LoggerSubExtension; |
14
|
|
|
|
15
|
|
|
class Behat3SymfonyExtension extends AbstractExtension |
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
|
|
|
/** |
37
|
|
|
* {@inheritdoc} |
38
|
|
|
*/ |
39
|
|
|
public function initialize(ExtensionManager $extensionManager) |
40
|
|
|
{ |
41
|
|
|
foreach ($this->subExtensionList as $subExtension) { |
42
|
|
|
$subExtension->initialize($extensionManager); |
43
|
|
|
} |
44
|
|
|
} |
45
|
|
|
// @codeCoverageIgnoreEnd |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* {@inheritdoc} |
49
|
|
|
*/ |
50
|
1 |
|
public function configure(ArrayNodeDefinition $builder) |
51
|
|
|
{ |
52
|
1 |
|
foreach ($this->subExtensionList as $subExtension) { |
53
|
1 |
|
$subExtension->configure( |
54
|
1 |
|
$builder->children() |
55
|
1 |
|
->arrayNode($subExtension->getConfigKey()) |
56
|
1 |
|
); |
57
|
1 |
|
} |
58
|
1 |
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* {@inheritdoc} |
62
|
|
|
*/ |
63
|
4 |
|
public function load(ContainerBuilder $container, array $config) |
64
|
|
|
{ |
65
|
4 |
|
foreach ($config['kernel'] as $key => $value) { |
66
|
4 |
|
$container->setParameter($this->buildContainerId(sprintf('kernel.%s', $key)), $value); |
67
|
4 |
|
} |
68
|
4 |
|
foreach ($config['logger'] as $key => $value) { |
69
|
4 |
|
$container->setParameter($this->buildContainerId(sprintf('logger.%s', $key)), $value); |
70
|
4 |
|
} |
71
|
4 |
|
$loader = new XmlFileLoader( |
72
|
4 |
|
$container, |
73
|
4 |
|
new FileLocator(__DIR__.'/../Resources/config') |
74
|
4 |
|
); |
75
|
|
|
|
76
|
4 |
|
$loader->load('client.xml'); |
77
|
4 |
|
$loader->load('kernel.xml'); |
78
|
4 |
|
$loader->load('initializer.xml'); |
79
|
4 |
|
$loader->load('logger.xml'); |
80
|
4 |
|
if (true === $config['kernel']['reboot']) { |
81
|
2 |
|
$loader->load('kernel_auto_reboot.xml'); |
82
|
2 |
|
} |
83
|
4 |
|
if (true === $config['kernel']['debug']) { |
84
|
2 |
|
$loader->load('kernel_debug_mode.xml'); |
85
|
2 |
|
} |
86
|
4 |
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* {@inheritdoc} |
90
|
|
|
*/ |
91
|
1 |
|
public function process(ContainerBuilder $container) |
92
|
|
|
{ |
93
|
1 |
|
foreach ($this->subExtensionList as $subExtension) { |
94
|
1 |
|
$subExtension->process($container); |
95
|
1 |
|
} |
96
|
1 |
|
} |
97
|
|
|
} |
98
|
|
|
|