6d9b9c6e9aad21846610156429e86ead783826c5
[yaffs-website] / vendor / behat / behat / src / Behat / Behat / EventDispatcher / Event / BeforeStepTeardown.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\BeforeTeardown;
19 use Behat\Testwork\Tester\Result\ExceptionResult;
20 use Behat\Testwork\Tester\Result\TestResult;
21
22 /**
23  * Represents an event before step teardown.
24  *
25  * @author Konstantin Kudryashov <ever.zet@gmail.com>
26  */
27 final class BeforeStepTeardown extends StepTested implements BeforeTeardown
28 {
29     /**
30      * @var FeatureNode
31      */
32     private $feature;
33     /**
34      * @var StepNode
35      */
36     private $step;
37     /**
38      * @var StepResult
39      */
40     private $result;
41
42     /**
43      * Initializes event.
44      *
45      * @param Environment $env
46      * @param FeatureNode $feature
47      * @param StepNode    $step
48      * @param StepResult  $result
49      */
50     public function __construct(
51         Environment $env,
52         FeatureNode $feature,
53         StepNode $step,
54         StepResult $result
55     ) {
56         parent::__construct($env);
57
58         $this->feature = $feature;
59         $this->step = $step;
60         $this->result = $result;
61     }
62
63     /**
64      * Returns feature.
65      *
66      * @return FeatureNode
67      */
68     public function getFeature()
69     {
70         return $this->feature;
71     }
72
73     /**
74      * Returns step node.
75      *
76      * @return StepNode
77      */
78     public function getStep()
79     {
80         return $this->step;
81     }
82
83     /**
84      * Returns current test result.
85      *
86      * @return TestResult
87      */
88     public function getTestResult()
89     {
90         return $this->result;
91     }
92
93     /**
94      * Checks if step call produced any output (stdOut or exception).
95      *
96      * @return Boolean
97      */
98     public function hasOutput()
99     {
100         return $this->resultHasException() || $this->resultCallHasOutput();
101     }
102
103     /**
104      * Checks if result has produced exception.
105      *
106      * @return Boolean
107      */
108     private function resultHasException()
109     {
110         return $this->result instanceof ExceptionResult && $this->result->getException();
111     }
112
113     /**
114      * Checks if result is executed and call result has produced exception or stdOut.
115      *
116      * @return Boolean
117      */
118     private function resultCallHasOutput()
119     {
120         if (!$this->result instanceof ExecutedStepResult) {
121             return false;
122         }
123
124         return $this->result->getCallResult()->hasStdOut() || $this->result->getCallResult()->hasException();
125     }
126 }