Security update for permissions_by_term
[yaffs-website] / vendor / behat / behat / src / Behat / Behat / EventDispatcher / Event / AfterStepTested.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\Event;
12
13 use Behat\Behat\Tester\Result\ExecutedStepResult;
14 use Behat\Behat\Tester\Result\StepResult;
15 use Behat\Gherkin\Node\FeatureNode;
16 use Behat\Gherkin\Node\StepNode;
17 use Behat\Testwork\Environment\Environment;
18 use Behat\Testwork\EventDispatcher\Event\AfterTested;
19 use Behat\Testwork\Tester\Result\ExceptionResult;
20 use Behat\Testwork\Tester\Result\TestResult;
21 use Behat\Testwork\Tester\Setup\Teardown;
22
23 /**
24  * Represents an event after step has been tested.
25  *
26  * @author Konstantin Kudryashov <ever.zet@gmail.com>
27  */
28 final class AfterStepTested extends StepTested implements AfterTested
29 {
30     /**
31      * @var FeatureNode
32      */
33     private $feature;
34     /**
35      * @var StepNode
36      */
37     private $step;
38     /**
39      * @var StepResult
40      */
41     private $result;
42     /**
43      * @var Teardown
44      */
45     private $teardown;
46
47     /**
48      * Initializes event.
49      *
50      * @param Environment $env
51      * @param FeatureNode $feature
52      * @param StepNode    $step
53      * @param StepResult  $result
54      * @param Teardown    $teardown
55      */
56     public function __construct(
57         Environment $env,
58         FeatureNode $feature,
59         StepNode $step,
60         StepResult $result,
61         Teardown $teardown
62     ) {
63         parent::__construct($env);
64
65         $this->feature = $feature;
66         $this->step = $step;
67         $this->result = $result;
68         $this->teardown = $teardown;
69     }
70
71     /**
72      * Returns feature.
73      *
74      * @return FeatureNode
75      */
76     public function getFeature()
77     {
78         return $this->feature;
79     }
80
81     /**
82      * Returns step node.
83      *
84      * @return StepNode
85      */
86     public function getStep()
87     {
88         return $this->step;
89     }
90
91     /**
92      * Returns current test result.
93      *
94      * @return TestResult
95      */
96     public function getTestResult()
97     {
98         return $this->result;
99     }
100
101     /**
102      * Returns current test teardown.
103      *
104      * @return Teardown
105      */
106     public function getTeardown()
107     {
108         return $this->teardown;
109     }
110
111     /**
112      * Checks if step call, setup or teardown produced any output (stdOut or exception).
113      *
114      * @return Boolean
115      */
116     public function hasOutput()
117     {
118         return $this->teardownHasOutput() || $this->resultHasException() || $this->resultCallHasOutput();
119     }
120
121     /**
122      * Checks if step teardown has output.
123      *
124      * @return Boolean
125      */
126     private function teardownHasOutput()
127     {
128         return $this->teardown->hasOutput();
129     }
130
131     /**
132      * Checks if result has produced exception.
133      *
134      * @return Boolean
135      */
136     private function resultHasException()
137     {
138         return $this->result instanceof ExceptionResult && $this->result->getException();
139     }
140
141     /**
142      * Checks if result is executed and call result has produced exception or stdOut.
143      *
144      * @return Boolean
145      */
146     private function resultCallHasOutput()
147     {
148         if (!$this->result instanceof ExecutedStepResult) {
149             return false;
150         }
151
152         return $this->result->getCallResult()->hasStdOut() || $this->result->getCallResult()->hasException();
153     }
154 }