1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Behat\SpawnerExtension\ServiceContainer; |
4
|
|
|
|
5
|
|
|
use Behat\Testwork\EventDispatcher\ServiceContainer\EventDispatcherExtension; |
6
|
|
|
use Behat\Testwork\ServiceContainer\Extension as ExtensionInterface; |
7
|
|
|
use Behat\Testwork\ServiceContainer\ExtensionManager; |
8
|
|
|
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition; |
9
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
10
|
|
|
use Symfony\Component\DependencyInjection\Definition; |
11
|
|
|
|
12
|
|
|
class SpawnerExtension implements ExtensionInterface |
13
|
|
|
{ |
14
|
|
|
const SPAWNER_ID = 'spawner'; |
15
|
|
|
|
16
|
|
|
/** @var array Default options for configuration */ |
17
|
|
|
private $defaultOptions = array( |
18
|
|
|
'commands' => array(), |
19
|
|
|
'work_dir' => '.', |
20
|
|
|
'win_prefix' => '', |
21
|
|
|
'nix_prefix' => 'exec', |
22
|
|
|
'sleep' => 0, |
23
|
|
|
); |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Loads a specific configuration. |
27
|
|
|
* |
28
|
|
|
* @param ContainerBuilder $container ContainerBuilder instance |
29
|
|
|
* @param array $config Extension configuration hash (from behat.yml) |
30
|
|
|
*/ |
31
|
|
|
public function load(ContainerBuilder $container, array $config) |
32
|
|
|
{ |
33
|
|
|
$this->loadSuiteListener($container); |
34
|
|
|
|
35
|
|
|
$config = array_merge($this->defaultOptions, $config); |
36
|
|
|
|
37
|
|
|
$container->setParameter('spawner.commands', $config['commands']); |
38
|
|
|
$container->setParameter('spawner.working_directory', $config['work_dir']); |
39
|
|
|
$container->setParameter('spawner.nix_prefix', $config['nix_prefix']); |
40
|
|
|
$container->setParameter('spawner.win_prefix', $config['win_prefix']); |
41
|
|
|
$container->setParameter('spawner.sleep', $config['sleep']); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* You can modify the container here before it is dumped to PHP code. |
46
|
|
|
* |
47
|
|
|
* @param ContainerBuilder $container |
48
|
|
|
* |
49
|
|
|
* @api |
50
|
|
|
*/ |
51
|
|
|
public function process(ContainerBuilder $container) |
52
|
|
|
{ |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* Returns the extension config key. |
57
|
|
|
* |
58
|
|
|
* @return string |
59
|
|
|
*/ |
60
|
|
|
public function getConfigKey() |
61
|
|
|
{ |
62
|
|
|
return 'spawner'; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* Initializes other extensions. |
67
|
|
|
* |
68
|
|
|
* This method is called immediately after all extensions are activated but |
69
|
|
|
* before any extension `configure()` method is called. This allows extensions |
70
|
|
|
* to hook into the configuration of other extensions providing such an |
71
|
|
|
* extension point. |
72
|
|
|
* |
73
|
|
|
* @param ExtensionManager $extensionManager |
74
|
|
|
*/ |
75
|
|
|
public function initialize(ExtensionManager $extensionManager) |
76
|
|
|
{ |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* Setups configuration for the extension. |
81
|
|
|
* |
82
|
|
|
* @param ArrayNodeDefinition $builder |
83
|
|
|
*/ |
84
|
|
|
public function configure(ArrayNodeDefinition $builder) |
85
|
|
|
{ |
86
|
|
|
$builder |
87
|
|
|
->children() |
88
|
|
|
->variableNode('commands') |
89
|
|
|
->end() |
90
|
|
|
->scalarNode('win_prefix') |
91
|
|
|
->defaultValue($this->defaultOptions['win_prefix']) |
92
|
|
|
->end() |
93
|
|
|
->scalarNode('work_dir') |
94
|
|
|
->defaultValue($this->defaultOptions['work_dir']) |
95
|
|
|
->end() |
96
|
|
|
->scalarNode('nix_prefix') |
97
|
|
|
->defaultValue($this->defaultOptions['nix_prefix']) |
98
|
|
|
->end() |
99
|
|
|
->integerNode('sleep') |
100
|
|
|
->defaultValue($this->defaultOptions['sleep']) |
101
|
|
|
->end() |
102
|
|
|
->end(); |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* Loads main suite listener |
107
|
|
|
* |
108
|
|
|
* @param ContainerBuilder $container |
109
|
|
|
*/ |
110
|
|
|
private function loadSuiteListener(ContainerBuilder $container) |
111
|
|
|
{ |
112
|
|
|
$definition = new Definition( |
113
|
|
|
'Behat\SpawnerExtension\Listener\SuiteListener', |
114
|
|
|
array( |
115
|
|
|
'%spawner.commands%', |
116
|
|
|
'%spawner.working_directory%', |
117
|
|
|
'%spawner.nix_prefix%', |
118
|
|
|
'%spawner.win_prefix%', |
119
|
|
|
'%spawner.sleep%', |
120
|
|
|
) |
121
|
|
|
); |
122
|
|
|
$definition->addTag(EventDispatcherExtension::SUBSCRIBER_TAG, array('priority' => 0)); |
123
|
|
|
$container->setDefinition('spawner.listener.suite', $definition); |
124
|
|
|
} |
125
|
|
|
} |
126
|
|
|
|