Security update for permissions_by_term
[yaffs-website] / vendor / behat / behat / src / Behat / Behat / Tester / ServiceContainer / TesterExtension.php
1 <?php
2
3 /*
4  * This file is part of the Behat.
5  * (c) Konstantin Kudryashov <ever.zet@gmail.com>
6  *
7  * For the full copyright and license information, please view the LICENSE
8  * file that was distributed with this source code.
9  */
10
11 namespace Behat\Behat\Tester\ServiceContainer;
12
13 use Behat\Behat\Definition\ServiceContainer\DefinitionExtension;
14 use Behat\Testwork\Call\ServiceContainer\CallExtension;
15 use Behat\Testwork\Cli\ServiceContainer\CliExtension;
16 use Behat\Testwork\Environment\ServiceContainer\EnvironmentExtension;
17 use Behat\Testwork\EventDispatcher\ServiceContainer\EventDispatcherExtension;
18 use Behat\Testwork\Exception\ServiceContainer\ExceptionExtension;
19 use Behat\Testwork\ServiceContainer\ServiceProcessor;
20 use Behat\Testwork\Tester\ServiceContainer\TesterExtension as BaseExtension;
21 use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
22 use Symfony\Component\DependencyInjection\ContainerBuilder;
23 use Symfony\Component\DependencyInjection\Definition;
24 use Symfony\Component\DependencyInjection\Reference;
25
26 /**
27  * Provides gherkin testers.
28  *
29  * @author Konstantin Kudryashov <ever.zet@gmail.com>
30  */
31 class TesterExtension extends BaseExtension
32 {
33     /*
34      * Available services
35      */
36     const SCENARIO_TESTER_ID = 'tester.scenario';
37     const OUTLINE_TESTER_ID = 'tester.outline';
38     const EXAMPLE_TESTER_ID = 'tester.example';
39     const BACKGROUND_TESTER_ID = 'tester.background';
40     const STEP_TESTER_ID = 'tester.step';
41
42     /**
43      * Available extension points
44      */
45     const SCENARIO_TESTER_WRAPPER_TAG = 'tester.scenario.wrapper';
46     const OUTLINE_TESTER_WRAPPER_TAG = 'tester.outline.wrapper';
47     const EXAMPLE_TESTER_WRAPPER_TAG = 'tester.example.wrapper';
48     const BACKGROUND_TESTER_WRAPPER_TAG = 'tester.background.wrapper';
49     const STEP_TESTER_WRAPPER_TAG = 'tester.step.wrapper';
50
51     /**
52      * @var ServiceProcessor
53      */
54     private $processor;
55
56     /**
57      * Initializes extension.
58      *
59      * @param null|ServiceProcessor $processor
60      */
61     public function __construct(ServiceProcessor $processor = null)
62     {
63         $this->processor = $processor ? : new ServiceProcessor();
64
65         parent::__construct($this->processor);
66     }
67
68     /**
69      * {@inheritdoc}
70      */
71     public function configure(ArrayNodeDefinition $builder)
72     {
73         parent::configure($builder);
74
75         $builder
76             ->children()
77                 ->scalarNode('rerun_cache')
78                     ->info('Sets the rerun cache path')
79                     ->defaultValue(
80                         is_writable(sys_get_temp_dir())
81                             ? sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'behat_rerun_cache'
82                             : null
83                     )
84                 ->end()
85             ->end()
86         ;
87     }
88
89     /**
90      * {@inheritdoc}
91      */
92     public function load(ContainerBuilder $container, array $config)
93     {
94         parent::load($container, $config);
95
96         $this->loadRerunController($container, $config['rerun_cache']);
97         $this->loadPendingExceptionStringer($container);
98     }
99
100     /**
101      * {@inheritdoc}
102      */
103     public function process(ContainerBuilder $container)
104     {
105         parent::process($container);
106
107         $this->processScenarioTesterWrappers($container);
108         $this->processOutlineTesterWrappers($container);
109         $this->processExampleTesterWrappers($container);
110         $this->processBackgroundTesterWrappers($container);
111         $this->processStepTesterWrappers($container);
112     }
113
114     /**
115      * Loads specification tester.
116      *
117      * @param ContainerBuilder $container
118      */
119     protected function loadSpecificationTester(ContainerBuilder $container)
120     {
121         $definition = new Definition('Behat\Behat\Tester\Runtime\RuntimeFeatureTester', array(
122             new Reference(self::SCENARIO_TESTER_ID),
123             new Reference(self::OUTLINE_TESTER_ID),
124             new Reference(EnvironmentExtension::MANAGER_ID)
125         ));
126         $container->setDefinition(self::SPECIFICATION_TESTER_ID, $definition);
127
128         $this->loadScenarioTester($container);
129         $this->loadOutlineTester($container);
130         $this->loadBackgroundTester($container);
131         $this->loadStepTester($container);
132     }
133
134     /**
135      * Loads scenario tester.
136      *
137      * @param ContainerBuilder $container
138      */
139     protected function loadScenarioTester(ContainerBuilder $container)
140     {
141         $definition = new Definition('Behat\Behat\Tester\StepContainerTester', array(
142             new Reference(self::STEP_TESTER_ID)
143         ));
144         $container->setDefinition('tester.step_container', $definition);
145
146         $definition = new Definition('Behat\Behat\Tester\Runtime\RuntimeScenarioTester', array(
147             new Reference('tester.step_container'),
148             new Reference(self::BACKGROUND_TESTER_ID)
149         ));
150         $container->setDefinition(self::SCENARIO_TESTER_ID, $definition);
151
152         // Proper isolation for scenarios
153         $definition = new Definition('Behat\Behat\Tester\Runtime\IsolatingScenarioTester', array(
154                 new Reference(self::SCENARIO_TESTER_ID),
155                 new Reference(EnvironmentExtension::MANAGER_ID)
156             )
157         );
158         $definition->addTag(self::SCENARIO_TESTER_WRAPPER_TAG, array('priority' => -999999));
159         $container->setDefinition(self::SCENARIO_TESTER_WRAPPER_TAG . '.isolating', $definition);
160     }
161
162     /**
163      * Loads outline tester.
164      *
165      * @param ContainerBuilder $container
166      */
167     protected function loadOutlineTester(ContainerBuilder $container)
168     {
169         $definition = new Definition('Behat\Behat\Tester\Runtime\RuntimeOutlineTester', array(
170             new Reference(self::EXAMPLE_TESTER_ID)
171         ));
172         $container->setDefinition(self::OUTLINE_TESTER_ID, $definition);
173
174         $this->loadExampleTester($container);
175     }
176
177     /**
178      * Loads example tester.
179      *
180      * @param ContainerBuilder $container
181      */
182     protected function loadExampleTester(ContainerBuilder $container)
183     {
184         $definition = new Definition('Behat\Behat\Tester\StepContainerTester', array(
185             new Reference(self::STEP_TESTER_ID)
186         ));
187         $container->setDefinition('tester.step_container', $definition);
188
189         $definition = new Definition('Behat\Behat\Tester\Runtime\RuntimeScenarioTester', array(
190             new Reference('tester.step_container'),
191             new Reference(self::BACKGROUND_TESTER_ID)
192         ));
193         $container->setDefinition(self::EXAMPLE_TESTER_ID, $definition);
194
195         // Proper isolation for examples
196         $definition = new Definition('Behat\Behat\Tester\Runtime\IsolatingScenarioTester', array(
197                 new Reference(self::EXAMPLE_TESTER_ID),
198                 new Reference(EnvironmentExtension::MANAGER_ID)
199             )
200         );
201         $definition->addTag(self::EXAMPLE_TESTER_WRAPPER_TAG, array('priority' => -999999));
202         $container->setDefinition(self::EXAMPLE_TESTER_WRAPPER_TAG . '.isolating', $definition);
203     }
204
205     /**
206      * Loads background tester.
207      *
208      * @param ContainerBuilder $container
209      */
210     protected function loadBackgroundTester(ContainerBuilder $container)
211     {
212         $definition = new Definition('Behat\Behat\Tester\StepContainerTester', array(
213             new Reference(self::STEP_TESTER_ID)
214         ));
215         $container->setDefinition('tester.step_container', $definition);
216
217         $definition = new Definition('Behat\Behat\Tester\Runtime\RuntimeBackgroundTester', array(
218             new Reference('tester.step_container')
219         ));
220         $container->setDefinition(self::BACKGROUND_TESTER_ID, $definition);
221     }
222
223     /**
224      * Loads step tester.
225      *
226      * @param ContainerBuilder $container
227      */
228     protected function loadStepTester(ContainerBuilder $container)
229     {
230         $definition = new Definition('Behat\Behat\Tester\Runtime\RuntimeStepTester', array(
231             new Reference(DefinitionExtension::FINDER_ID),
232             new Reference(CallExtension::CALL_CENTER_ID)
233         ));
234         $container->setDefinition(self::STEP_TESTER_ID, $definition);
235     }
236
237     /**
238      * Loads rerun controller.
239      *
240      * @param ContainerBuilder $container
241      * @param null|string      $cachePath
242      */
243     protected function loadRerunController(ContainerBuilder $container, $cachePath)
244     {
245         $definition = new Definition('Behat\Behat\Tester\Cli\RerunController', array(
246             new Reference(EventDispatcherExtension::DISPATCHER_ID),
247             $cachePath,
248             $container->getParameter('paths.base')
249         ));
250         $definition->addTag(CliExtension::CONTROLLER_TAG, array('priority' => 200));
251         $container->setDefinition(CliExtension::CONTROLLER_TAG . '.rerun', $definition);
252     }
253
254     /**
255      * Loads pending exception stringer.
256      *
257      * @param ContainerBuilder $container
258      */
259     protected function loadPendingExceptionStringer(ContainerBuilder $container)
260     {
261         $definition = new Definition('Behat\Behat\Tester\Exception\Stringer\PendingExceptionStringer');
262         $definition->addTag(ExceptionExtension::STRINGER_TAG);
263         $container->setDefinition(ExceptionExtension::STRINGER_TAG . '.pending', $definition);
264     }
265
266     /**
267      * Processes all registered scenario tester wrappers.
268      *
269      * @param ContainerBuilder $container
270      */
271     protected function processScenarioTesterWrappers(ContainerBuilder $container)
272     {
273         $this->processor->processWrapperServices($container, self::SCENARIO_TESTER_ID, self::SCENARIO_TESTER_WRAPPER_TAG);
274     }
275
276     /**
277      * Processes all registered outline tester wrappers.
278      *
279      * @param ContainerBuilder $container
280      */
281     protected function processOutlineTesterWrappers(ContainerBuilder $container)
282     {
283         $this->processor->processWrapperServices($container, self::OUTLINE_TESTER_ID, self::OUTLINE_TESTER_WRAPPER_TAG);
284     }
285
286     /**
287      * Processes all registered example tester wrappers.
288      *
289      * @param ContainerBuilder $container
290      */
291     protected function processExampleTesterWrappers(ContainerBuilder $container)
292     {
293         $this->processor->processWrapperServices($container, self::EXAMPLE_TESTER_ID, self::EXAMPLE_TESTER_WRAPPER_TAG);
294     }
295
296     /**
297      * Processes all registered background tester wrappers.
298      *
299      * @param ContainerBuilder $container
300      */
301     protected function processBackgroundTesterWrappers(ContainerBuilder $container)
302     {
303         $this->processor->processWrapperServices($container, self::BACKGROUND_TESTER_ID, self::BACKGROUND_TESTER_WRAPPER_TAG);
304     }
305
306     /**
307      * Processes all registered step tester wrappers.
308      *
309      * @param ContainerBuilder $container
310      */
311     protected function processStepTesterWrappers(ContainerBuilder $container)
312     {
313         $this->processor->processWrapperServices($container, self::STEP_TESTER_ID, self::STEP_TESTER_WRAPPER_TAG);
314     }
315 }