Repository navigation
Expand file tree
/
Copy pathScenario.php
More file actions
137 lines (118 loc) · 3.45 KB
/
Copy pathScenario.php
File metadata and controls
137 lines (118 loc) · 3.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
<?php
namespace Codeception;
use Codeception\Event\StepEvent;
use Codeception\Exception\ConditionalAssertionFailed;
use Codeception\Lib\Notification;
use Codeception\Step;
use Codeception\Test\Metadata;
class Scenario
{
/**
* @var TestInterface
*/
protected $test;
/**
* @var Metadata
*/
protected $metadata;
/**
* @var array
*/
protected $steps = [];
/**
* @var string
*/
protected $feature;
/**
* Constructor
*
* @param TestInterface $test
*/
public function __construct(TestInterface $test)
{
$this->metadata = $test->getMetadata();
$this->test = $test;
}
public function setFeature($feature)
{
$this->metadata->setFeature($feature);
}
public function getFeature()
{
return $this->metadata->getFeature();
}
public function current($key)
{
return $this->metadata->getCurrent($key);
}
public function runStep(Step $step)
{
$this->steps[] = $step;
$result = null;
$this->metadata->getService('dispatcher')->dispatch(Events::STEP_BEFORE, new StepEvent($this->test, $step));
try {
$result = $step->run($this->metadata->getService('modules'));
} catch (ConditionalAssertionFailed $f) {
$result = $this->test->getTestResultObject();
$result->addFailure(clone($this->test), $f, $result->time());
} catch (\Exception $e) {
$this->metadata->getService('dispatcher')->dispatch(Events::STEP_AFTER, new StepEvent($this->test, $step));
throw $e;
}
$this->metadata->getService('dispatcher')->dispatch(Events::STEP_AFTER, new StepEvent($this->test, $step));
$step->executed = true;
return $result;
}
public function addStep(Step $step)
{
$this->steps[] = $step;
}
/**
* Returns the steps of this scenario.
*
* @return array
*/
public function getSteps()
{
return $this->steps;
}
public function getHtml()
{
$text = '';
foreach ($this->getSteps() as $step) {
/** @var Step $step */
if ($step->getName() !== 'Comment') {
$text .= $step->getHtml() . '<br/>';
} else {
$text .= trim($step->getHumanizedArguments(), '"') . '<br/>';
}
}
$text = str_replace(['"\'', '\'"'], ["'", "'"], $text);
$text = "<h3>" . strtoupper('I want to ' . $this->getFeature()) . "</h3>" . $text;
return $text;
}
public function getText()
{
$text = implode("\r\n", $this->getSteps());
$text = str_replace(array('"\'','\'"'), array("'","'"), $text);
$text = strtoupper('I want to ' . $this->getFeature()) . str_repeat("\r\n", 2) . $text . str_repeat("\r\n", 2);
return $text;
}
public function comment($comment)
{
$this->runStep(new \Codeception\Step\Comment($comment, []));
}
public function skip($message = '')
{
throw new \PHPUnit_Framework_SkippedTestError($message);
}
public function incomplete($message = '')
{
throw new \PHPUnit_Framework_IncompleteTestError($message);
}
public function __call($method, $args)
{
// all methods were deprecated and removed from here
Notification::deprecate("\$scenario->$method() was deprecated in 2.1 and removed. Don't use it");
}
}