Security update for permissions_by_term
[yaffs-website] / vendor / behat / behat / src / Behat / Testwork / Tester / ServiceContainer / TesterExtension.php
1 <?php
2
3 /*
4  * This file is part of the Behat Testwork.
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\Testwork\Tester\ServiceContainer;
12
13 use Behat\Testwork\Cli\ServiceContainer\CliExtension;
14 use Behat\Testwork\Environment\ServiceContainer\EnvironmentExtension;
15 use Behat\Testwork\ServiceContainer\Extension;
16 use Behat\Testwork\ServiceContainer\ExtensionManager;
17 use Behat\Testwork\ServiceContainer\ServiceProcessor;
18 use Behat\Testwork\Specification\ServiceContainer\SpecificationExtension;
19 use Behat\Testwork\Suite\ServiceContainer\SuiteExtension;
20 use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
21 use Symfony\Component\DependencyInjection\ContainerBuilder;
22 use Symfony\Component\DependencyInjection\Definition;
23 use Symfony\Component\DependencyInjection\Reference;
24
25 /**
26  * Provides tester services.
27  *
28  * @author Konstantin Kudryashov <ever.zet@gmail.com>
29  */
30 abstract class TesterExtension implements Extension
31 {
32     /*
33      * Available services
34      */
35     const EXERCISE_ID = 'tester.exercise';
36     const SUITE_TESTER_ID = 'tester.suite';
37     const SPECIFICATION_TESTER_ID = 'tester.specification';
38     const RESULT_INTERPRETER_ID = 'tester.result.interpreter';
39
40     /**
41      * Available extension points
42      */
43     const EXERCISE_WRAPPER_TAG = 'tester.exercise.wrapper';
44     const SUITE_TESTER_WRAPPER_TAG = 'tester.suite.wrapper';
45     const SPECIFICATION_TESTER_WRAPPER_TAG = 'tester.specification.wrapper';
46     const RESULT_INTERPRETATION_TAG = 'test.result.interpretation';
47
48     /**
49      * @var ServiceProcessor
50      */
51     private $processor;
52
53     /**
54      * Initializes extension.
55      *
56      * @param null|ServiceProcessor $processor
57      */
58     public function __construct(ServiceProcessor $processor = null)
59     {
60         $this->processor = $processor ? : new ServiceProcessor();
61     }
62
63     /**
64      * {@inheritdoc}
65      */
66     public function getConfigKey()
67     {
68         return 'testers';
69     }
70
71     /**
72      * {@inheritdoc}
73      */
74     public function initialize(ExtensionManager $extensionManager)
75     {
76     }
77
78     /**
79      * {@inheritdoc}
80      */
81     public function configure(ArrayNodeDefinition $builder)
82     {
83         $builder
84             ->addDefaultsIfNotSet()
85             ->children()
86                 ->booleanNode('strict')
87                     ->info('Sets the strict mode for result interpretation')
88                     ->defaultFalse()
89                 ->end()
90                 ->booleanNode('skip')
91                     ->info('Tells tester to skip all tests')
92                     ->defaultFalse()
93                 ->end()
94             ->end()
95         ;
96     }
97
98     /**
99      * {@inheritdoc}
100      */
101     public function load(ContainerBuilder $container, array $config)
102     {
103         $this->loadExerciseController($container, $config['skip']);
104         $this->loadStrictController($container, $config['strict']);
105         $this->loadResultInterpreter($container);
106         $this->loadExercise($container);
107         $this->loadSuiteTester($container);
108         $this->loadSpecificationTester($container);
109     }
110
111     /**
112      * {@inheritdoc}
113      */
114     public function process(ContainerBuilder $container)
115     {
116         $this->processExerciseWrappers($container);
117         $this->processSuiteTesterWrappers($container);
118         $this->processSpecificationTesterWrappers($container);
119         $this->processResultInterpretations($container);
120     }
121
122     /**
123      * Loads exercise cli controllers.
124      *
125      * @param ContainerBuilder $container
126      * @param Boolean          $skip
127      */
128     protected function loadExerciseController(ContainerBuilder $container, $skip = false)
129     {
130         $definition = new Definition('Behat\Testwork\Tester\Cli\ExerciseController', array(
131             new Reference(SuiteExtension::REGISTRY_ID),
132             new Reference(SpecificationExtension::FINDER_ID),
133             new Reference(self::EXERCISE_ID),
134             new Reference(self::RESULT_INTERPRETER_ID),
135             $skip
136         ));
137         $definition->addTag(CliExtension::CONTROLLER_TAG, array('priority' => 0));
138         $container->setDefinition(CliExtension::CONTROLLER_TAG . '.exercise', $definition);
139     }
140
141     /**
142      * Loads exercise cli controllers.
143      *
144      * @param ContainerBuilder $container
145      * @param Boolean          $strict
146      */
147     protected function loadStrictController(ContainerBuilder $container, $strict = false)
148     {
149         $definition = new Definition('Behat\Testwork\Tester\Cli\StrictController', array(
150             new Reference(self::RESULT_INTERPRETER_ID),
151             $strict
152         ));
153         $definition->addTag(CliExtension::CONTROLLER_TAG, array('priority' => 300));
154         $container->setDefinition(CliExtension::CONTROLLER_TAG . '.strict', $definition);
155     }
156
157     /**
158      * Loads result interpreter controller
159      *
160      * @param ContainerBuilder $container
161      */
162     protected function loadResultInterpreter(ContainerBuilder $container)
163     {
164         $definition = new Definition('Behat\Testwork\Tester\Result\ResultInterpreter');
165         $container->setDefinition(self::RESULT_INTERPRETER_ID, $definition);
166
167         $definition = new Definition('Behat\Testwork\Tester\Result\Interpretation\SoftInterpretation');
168         $definition->addTag(self::RESULT_INTERPRETATION_TAG);
169         $container->setDefinition(self::RESULT_INTERPRETATION_TAG . '.soft', $definition);
170     }
171
172     /**
173      * Loads exercise tester.
174      *
175      * @param ContainerBuilder $container
176      */
177     protected function loadExercise(ContainerBuilder $container)
178     {
179         $definition = new Definition('Behat\Testwork\Tester\Runtime\RuntimeExercise', array(
180             new Reference(EnvironmentExtension::MANAGER_ID),
181             new Reference(self::SUITE_TESTER_ID)
182         ));
183         $container->setDefinition(self::EXERCISE_ID, $definition);
184     }
185
186     /**
187      * Loads suite tester.
188      *
189      * @param ContainerBuilder $container
190      */
191     protected function loadSuiteTester(ContainerBuilder $container)
192     {
193         $definition = new Definition('Behat\Testwork\Tester\Runtime\RuntimeSuiteTester', array(
194             new Reference(self::SPECIFICATION_TESTER_ID)
195         ));
196         $container->setDefinition(self::SUITE_TESTER_ID, $definition);
197     }
198
199     /**
200      * Loads specification tester.
201      *
202      * @param ContainerBuilder $container
203      */
204     abstract protected function loadSpecificationTester(ContainerBuilder $container);
205
206     /**
207      * Processes all registered exercise wrappers.
208      *
209      * @param ContainerBuilder $container
210      */
211     protected function processExerciseWrappers(ContainerBuilder $container)
212     {
213         $this->processor->processWrapperServices($container, self::EXERCISE_ID, self::EXERCISE_WRAPPER_TAG);
214     }
215
216     /**
217      * Processes all registered suite tester wrappers.
218      *
219      * @param ContainerBuilder $container
220      */
221     protected function processSuiteTesterWrappers(ContainerBuilder $container)
222     {
223         $this->processor->processWrapperServices($container, self::SUITE_TESTER_ID, self::SUITE_TESTER_WRAPPER_TAG);
224     }
225
226     /**
227      * Processes all registered specification tester wrappers.
228      *
229      * @param ContainerBuilder $container
230      */
231     protected function processSpecificationTesterWrappers(ContainerBuilder $container)
232     {
233         $this->processor->processWrapperServices($container, self::SPECIFICATION_TESTER_ID, self::SPECIFICATION_TESTER_WRAPPER_TAG);
234     }
235
236     /**
237      * Processes all registered result interpretations.
238      *
239      * @param ContainerBuilder $container
240      */
241     protected function processResultInterpretations(ContainerBuilder $container)
242     {
243         $references = $this->processor->findAndSortTaggedServices($container, self::RESULT_INTERPRETATION_TAG);
244         $definition = $container->getDefinition(self::RESULT_INTERPRETER_ID);
245
246         foreach ($references as $reference) {
247             $definition->addMethodCall('registerResultInterpretation', array($reference));
248         }
249     }
250 }