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