Security update for permissions_by_term
[yaffs-website] / vendor / behat / behat / src / Behat / Behat / EventDispatcher / Tester / EventDispatchingScenarioTester.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\EventDispatcher\Tester;
12
13 use Behat\Behat\EventDispatcher\Event\AfterScenarioSetup;
14 use Behat\Behat\EventDispatcher\Event\AfterScenarioTested;
15 use Behat\Behat\EventDispatcher\Event\BeforeScenarioTeardown;
16 use Behat\Behat\EventDispatcher\Event\BeforeScenarioTested;
17 use Behat\Behat\Tester\ScenarioTester;
18 use Behat\Gherkin\Node\FeatureNode;
19 use Behat\Gherkin\Node\ScenarioInterface as Scenario;
20 use Behat\Testwork\Environment\Environment;
21 use Behat\Testwork\Tester\Result\TestResult;
22 use Symfony\Component\EventDispatcher\EventDispatcherInterface;
23
24 /**
25  * Scenario tester dispatching BEFORE/AFTER events during tests.
26  *
27  * @author Konstantin Kudryashov <ever.zet@gmail.com>
28  */
29 final class EventDispatchingScenarioTester implements ScenarioTester
30 {
31     /**
32      * @var ScenarioTester
33      */
34     private $baseTester;
35     /**
36      * @var EventDispatcherInterface
37      */
38     private $eventDispatcher;
39     /**
40      * @var string
41      */
42     private $beforeEventName;
43     /**
44      * @var string
45      */
46     private $afterSetupEventName;
47     /**
48      * @var string
49      */
50     private $beforeTeardownEventName;
51     /**
52      * @var string
53      */
54     private $afterEventName;
55
56     /**
57      * Initializes tester.
58      *
59      * @param ScenarioTester           $baseTester
60      * @param EventDispatcherInterface $eventDispatcher
61      * @param string                   $beforeEventName
62      * @param string                   $afterSetupEventName
63      * @param string                   $beforeTeardownEventName
64      * @param string                   $afterEventName
65      */
66     public function __construct(
67         ScenarioTester $baseTester,
68         EventDispatcherInterface $eventDispatcher,
69         $beforeEventName,
70         $afterSetupEventName,
71         $beforeTeardownEventName,
72         $afterEventName
73     ) {
74         $this->baseTester = $baseTester;
75         $this->eventDispatcher = $eventDispatcher;
76         $this->beforeEventName = $beforeEventName;
77         $this->afterSetupEventName = $afterSetupEventName;
78         $this->beforeTeardownEventName = $beforeTeardownEventName;
79         $this->afterEventName = $afterEventName;
80     }
81
82     /**
83      * {@inheritdoc}
84      */
85     public function setUp(Environment $env, FeatureNode $feature, Scenario $scenario, $skip)
86     {
87         $event = new BeforeScenarioTested($env, $feature, $scenario);
88         $this->eventDispatcher->dispatch($this->beforeEventName, $event);
89
90         $setup = $this->baseTester->setUp($env, $feature, $scenario, $skip);
91
92         $event = new AfterScenarioSetup($env, $feature, $scenario, $setup);
93         $this->eventDispatcher->dispatch($this->afterSetupEventName, $event);
94
95         return $setup;
96     }
97
98     /**
99      * {@inheritdoc}
100      */
101     public function test(Environment $env, FeatureNode $feature, Scenario $scenario, $skip)
102     {
103         return $this->baseTester->test($env, $feature, $scenario, $skip);
104     }
105
106     /**
107      * {@inheritdoc}
108      */
109     public function tearDown(Environment $env, FeatureNode $feature, Scenario $scenario, $skip, TestResult $result)
110     {
111         $event = new BeforeScenarioTeardown($env, $feature, $scenario, $result);
112         $this->eventDispatcher->dispatch($this->beforeTeardownEventName, $event);
113
114         $teardown = $this->baseTester->tearDown($env, $feature, $scenario, $skip, $result);
115
116         $event = new AfterScenarioTested($env, $feature, $scenario, $result, $teardown);
117         $this->eventDispatcher->dispatch($this->afterEventName, $event);
118
119         return $teardown;
120     }
121 }