4 * This file is part of the Behat.
5 * (c) Konstantin Kudryashov <ever.zet@gmail.com>
7 * For the full copyright and license information, please view the LICENSE
8 * file that was distributed with this source code.
11 namespace Behat\Behat\EventDispatcher\ServiceContainer;
13 use Behat\Behat\EventDispatcher\Event\ExampleTested;
14 use Behat\Behat\EventDispatcher\Event\ScenarioTested;
15 use Behat\Behat\Tester\ServiceContainer\TesterExtension;
16 use Behat\Testwork\Cli\ServiceContainer\CliExtension;
17 use Behat\Testwork\EventDispatcher\ServiceContainer\EventDispatcherExtension as BaseExtension;
18 use Symfony\Component\DependencyInjection\ContainerBuilder;
19 use Symfony\Component\DependencyInjection\Definition;
20 use Symfony\Component\DependencyInjection\Reference;
23 * Extends Testwork EventDispatcherExtension with additional event-dispatching testers.
25 * @author Konstantin Kudryashov <ever.zet@gmail.com>
27 class EventDispatcherExtension extends BaseExtension
32 public function load(ContainerBuilder $container, array $config)
34 parent::load($container, $config);
36 $this->loadStopOnFailureController($container);
37 $this->loadEventDispatchingBackgroundTester($container);
38 $this->loadEventDispatchingFeatureTester($container);
39 $this->loadEventDispatchingOutlineTester($container);
40 $this->loadEventDispatchingScenarioTester($container);
41 $this->loadEventDispatchingExampleTester($container);
42 $this->loadEventDispatchingStepTester($container);
43 $this->loadTickingStepTester($container);
47 * Loads stop on failure controller.
49 * @param ContainerBuilder $container
51 protected function loadStopOnFailureController(ContainerBuilder $container)
53 $definition = new Definition('Behat\Behat\EventDispatcher\Cli\StopOnFailureController', array(
54 new Reference(EventDispatcherExtension::DISPATCHER_ID)
56 $definition->addTag(CliExtension::CONTROLLER_TAG, array('priority' => 100));
57 $container->setDefinition(CliExtension::CONTROLLER_TAG . '.stop_on_failure', $definition);
61 * Loads event-dispatching background tester.
63 * @param ContainerBuilder $container
65 protected function loadEventDispatchingBackgroundTester(ContainerBuilder $container)
67 $definition = new Definition('Behat\Behat\EventDispatcher\Tester\EventDispatchingBackgroundTester', array(
68 new Reference(TesterExtension::BACKGROUND_TESTER_ID),
69 new Reference(self::DISPATCHER_ID)
71 $definition->addTag(TesterExtension::BACKGROUND_TESTER_WRAPPER_TAG, array('priority' => -9999));
72 $container->setDefinition(TesterExtension::BACKGROUND_TESTER_WRAPPER_TAG . '.event_dispatching', $definition);
76 * Loads event-dispatching feature tester.
78 * @param ContainerBuilder $container
80 protected function loadEventDispatchingFeatureTester(ContainerBuilder $container)
82 $definition = new Definition('Behat\Behat\EventDispatcher\Tester\EventDispatchingFeatureTester', array(
83 new Reference(TesterExtension::SPECIFICATION_TESTER_ID),
84 new Reference(self::DISPATCHER_ID)
86 $definition->addTag(TesterExtension::SPECIFICATION_TESTER_WRAPPER_TAG, array('priority' => -9999));
87 $container->setDefinition(TesterExtension::SPECIFICATION_TESTER_WRAPPER_TAG . '.event_dispatching', $definition);
91 * Loads event-dispatching outline tester.
93 * @param ContainerBuilder $container
95 protected function loadEventDispatchingOutlineTester(ContainerBuilder $container)
97 $definition = new Definition('Behat\Behat\EventDispatcher\Tester\EventDispatchingOutlineTester', array(
98 new Reference(TesterExtension::OUTLINE_TESTER_ID),
99 new Reference(self::DISPATCHER_ID)
101 $definition->addTag(TesterExtension::OUTLINE_TESTER_WRAPPER_TAG, array('priority' => -9999));
102 $container->setDefinition(TesterExtension::OUTLINE_TESTER_WRAPPER_TAG . '.event_dispatching', $definition);
106 * Loads event-dispatching scenario tester.
108 * @param ContainerBuilder $container
110 protected function loadEventDispatchingScenarioTester(ContainerBuilder $container)
112 $definition = new Definition('Behat\Behat\EventDispatcher\Tester\EventDispatchingScenarioTester', array(
113 new Reference(TesterExtension::SCENARIO_TESTER_ID),
114 new Reference(self::DISPATCHER_ID),
115 ScenarioTested::BEFORE,
116 ScenarioTested::AFTER_SETUP,
117 ScenarioTested::BEFORE_TEARDOWN,
118 ScenarioTested::AFTER
120 $definition->addTag(TesterExtension::SCENARIO_TESTER_WRAPPER_TAG, array('priority' => -9999));
121 $container->setDefinition(TesterExtension::SCENARIO_TESTER_WRAPPER_TAG . '.event_dispatching', $definition);
125 * Loads event-dispatching example tester.
127 * @param ContainerBuilder $container
129 protected function loadEventDispatchingExampleTester(ContainerBuilder $container)
131 $definition = new Definition('Behat\Behat\EventDispatcher\Tester\EventDispatchingScenarioTester', array(
132 new Reference(TesterExtension::EXAMPLE_TESTER_ID),
133 new Reference(self::DISPATCHER_ID),
134 ExampleTested::BEFORE,
135 ExampleTested::AFTER_SETUP,
136 ExampleTested::BEFORE_TEARDOWN,
139 $definition->addTag(TesterExtension::EXAMPLE_TESTER_WRAPPER_TAG, array('priority' => -9999));
140 $container->setDefinition(TesterExtension::EXAMPLE_TESTER_WRAPPER_TAG . '.event_dispatching', $definition);
144 * Loads event-dispatching step tester.
146 * @param ContainerBuilder $container
148 protected function loadEventDispatchingStepTester(ContainerBuilder $container)
150 $definition = new Definition('Behat\Behat\EventDispatcher\Tester\EventDispatchingStepTester', array(
151 new Reference(TesterExtension::STEP_TESTER_ID),
152 new Reference(self::DISPATCHER_ID)
154 $definition->addTag(TesterExtension::STEP_TESTER_WRAPPER_TAG, array('priority' => -9999));
155 $container->setDefinition(TesterExtension::STEP_TESTER_WRAPPER_TAG . '.event_dispatching', $definition);
159 * Loads ticking step tester.
161 * @param ContainerBuilder $container
163 protected function loadTickingStepTester(ContainerBuilder $container)
165 if (!function_exists('pcntl_signal')) {
169 $definition = new Definition('Behat\Behat\EventDispatcher\Tester\TickingStepTester', array(
170 new Reference(TesterExtension::STEP_TESTER_ID)
172 $definition->addTag(TesterExtension::STEP_TESTER_WRAPPER_TAG, array('priority' => 9999));
173 $container->setDefinition(TesterExtension::STEP_TESTER_WRAPPER_TAG . '.ticking', $definition);