1
|
|
|
<?php |
2
|
|
|
namespace Yoanm\BehatUtilsExtension\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\BehatUtilsExtension\ServiceContainer\Configuration\EventSubscriberConfiguration; |
11
|
|
|
use Yoanm\BehatUtilsExtension\ServiceContainer\Configuration\LoggerConfiguration; |
12
|
|
|
use Yoanm\BehatUtilsExtension\ServiceContainer\Configuration\StepLoggerConfiguration; |
13
|
|
|
|
14
|
|
|
class BehatUtilsExtension implements Extension |
15
|
|
|
{ |
16
|
|
|
const EXTENSION_CONFIG_KEY = 'behat_utils'; |
17
|
|
|
const CONTAINER_KEY_BASE = 'behat_utils_extension'; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* {@inheritdoc} |
21
|
|
|
*/ |
22
|
1 |
|
public function getConfigKey() |
23
|
|
|
{ |
24
|
1 |
|
return self::EXTENSION_CONFIG_KEY; |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
// @codeCoverageIgnoreStart |
28
|
|
|
/** |
29
|
|
|
* {@inheritdoc} |
30
|
|
|
*/ |
31
|
|
|
public function initialize(ExtensionManager $extensionManager) |
32
|
|
|
{ |
33
|
|
|
} |
34
|
|
|
// @codeCoverageIgnoreEnd |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* {@inheritdoc} |
38
|
|
|
*/ |
39
|
2 |
|
public function configure(ArrayNodeDefinition $builder) |
40
|
|
|
{ |
41
|
1 |
|
$builder->append((new LoggerConfiguration())->getConfigNode()); |
42
|
1 |
|
$builder->append((new StepLoggerConfiguration())->getConfigNode()); |
43
|
2 |
|
$builder->append((new EventSubscriberConfiguration())->getConfigNode()); |
44
|
1 |
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* {@inheritdoc} |
48
|
|
|
*/ |
49
|
5 |
|
public function load(ContainerBuilder $container, array $config) |
50
|
|
|
{ |
51
|
5 |
|
$this->bindConfigToContainer($container, $config); |
52
|
|
|
|
53
|
5 |
|
$loader = new XmlFileLoader( |
54
|
5 |
|
$container, |
55
|
5 |
|
new FileLocator(__DIR__.'/../Resources/config') |
56
|
5 |
|
); |
57
|
|
|
|
58
|
5 |
|
$loader->load('logger.xml'); |
59
|
|
|
|
60
|
5 |
|
if (true === $config['event_subscriber']['enabled']) { |
61
|
2 |
|
$loader->load('event_subscriber.xml'); |
62
|
2 |
|
} |
63
|
|
|
|
64
|
5 |
|
if (true === $config['step_logger']['enabled']) { |
65
|
2 |
|
$loader->load('behat_step_logger.xml'); |
66
|
2 |
|
} |
67
|
5 |
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* {@inheritdoc} |
71
|
|
|
*/ |
72
|
1 |
|
public function process(ContainerBuilder $container) |
73
|
|
|
{ |
74
|
1 |
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* @param ContainerBuilder $container |
78
|
|
|
* @param array $config |
79
|
|
|
* @param string $baseId |
80
|
|
|
*/ |
81
|
5 |
|
protected function bindConfigToContainer( |
82
|
|
|
ContainerBuilder $container, |
83
|
|
|
array $config, |
84
|
|
|
$baseId = self::CONTAINER_KEY_BASE |
85
|
|
|
) { |
86
|
5 |
|
foreach ($config as $configKey => $configValue) { |
87
|
5 |
|
if (is_array($configValue)) { |
88
|
5 |
|
$this->bindConfigToContainer( |
89
|
5 |
|
$container, |
90
|
5 |
|
$configValue, |
91
|
5 |
|
sprintf('%s.%s', $baseId, $configKey) |
92
|
5 |
|
); |
93
|
5 |
|
} else { |
94
|
5 |
|
$container->setParameter(sprintf('%s.%s', $baseId, $configKey), $configValue); |
95
|
|
|
} |
96
|
5 |
|
} |
97
|
5 |
|
} |
98
|
|
|
} |
99
|
|
|
|