Repository navigation
Expand file tree
/
Copy pathAbstractGuy.php
More file actions
127 lines (108 loc) · 2.79 KB
/
Copy pathAbstractGuy.php
File metadata and controls
127 lines (108 loc) · 2.79 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
<?php
namespace Codeception;
use Codeception\Step\Action;
abstract class AbstractGuy implements \ArrayAccess
{
public static $methods = array();
/**
* @var \Codeception\Scenario
*/
protected $scenario;
protected $running = false;
public function __construct(\Codeception\Scenario $scenario)
{
$this->scenario = $scenario;
}
/**
* Lazy-execution given anonymous function
* @param $callable \Closure
* @return null|void|bool|mixed
*/
public function execute($callable)
{
$this->scenario->addStep(new \Codeception\Step\Executor($callable, array()));
if ($this->scenario->running()) {
$this->scenario->runStep();
}
return $this;
}
public function wantToTest($text)
{
return $this->wantTo('test ' . $text);
}
public function wantTo($text)
{
if ($this->scenario->running()) {
$this->scenario->runStep();
return $this;
}
$this->scenario->setFeature(mb_strtolower($text, 'utf-8'));
return $this;
}
public function expectTo($prediction)
{
return $this->comment('I expect to ' . $prediction);
}
public function expect($prediction)
{
return $this->comment('I expect ' . $prediction);
}
public function amGoingTo($argumentation)
{
return $this->comment('I am going to ' . $argumentation);
}
public function am($role) {
return $this->comment('As a ' . $role);
}
public function lookForwardTo($achieveValue)
{
return $this->comment('So that I ' . $achieveValue);
}
/**
* In order to have this nicely looking comments.
*
* ``` php
* <?php
*
* $I['click on a product'];
* $I['then I select Purchase'];
* $I['I select shipment delivery'];
* $I['purchase a product'];
*
* ```
*
* @param mixed $offset
* @return mixed|void
*/
public function offsetGet($offset)
{
$this->comment($offset);
}
public function offsetSet($offset, $value)
{
// not needed
}
public function offsetExists($offset)
{
return false;
}
public function offsetUnset($offset)
{
// not needed
}
protected function comment($description)
{
$this->scenario->comment($description);
if ($this->scenario->running()) {
$this->scenario->runStep();
return $this;
}
}
public function __call($method, $arguments) {
if ($this->scenario->running()) {
$class = get_class($this);
throw new \RuntimeException("Call to undefined method $class::$method");
}
$this->scenario->addStep(new Action($method, $arguments));
}
}