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