Repository navigation
Expand file tree
/
Copy pathStep.php
More file actions
134 lines (112 loc) · 3.64 KB
/
Copy pathStep.php
File metadata and controls
134 lines (112 loc) · 3.64 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
<?php
namespace Codeception;
abstract class Step
{
/**
* @var string
*/
protected $action;
/**
* @var array
*/
protected $arguments;
protected $debugOutput;
public $executed = false;
public function __construct($action, array $arguments)
{
$this->action = $action;
$this->arguments = $arguments;
}
public function getName()
{
$class = explode('\\', __CLASS__);
return end($class);
}
public function pullDebugOutput()
{
$output = $this->debugOutput;
$this->debugOutput = null;
return $output;
}
public function getAction()
{
return $this->action;
}
public function getArguments($asString = FALSE)
{
if (!$asString) {
return $this->arguments;
} else {
$arguments = $this->arguments;
foreach ($arguments as $k => $argument) {
if (!is_string($argument) and is_callable($argument, true)) {
$arguments[$k] = 'lambda function';
continue;
}
if (is_object($argument)) {
if (method_exists($argument, '__toString')) {
$arguments[$k] = $argument->__toString();
} elseif (isset($argument->__mocked)) {
$arguments[$k] = $this->formatClassName($argument->__mocked);
} else {
$arguments[$k] = $this->formatClassName(get_class($argument));
}
continue;
}
}
if (defined('JSON_UNESCAPED_UNICODE')) {
return stripcslashes(trim(json_encode($arguments, JSON_UNESCAPED_UNICODE), '[]'));
}
return stripcslashes(trim(json_encode($arguments), '[]'));
}
}
protected function formatClassName($classname)
{
return trim($classname, "\\");
}
public function __toString()
{
return "I " . $this->getHumanizedAction();
}
public function getHumanizedAction()
{
return $this->humanize($this->getAction()) . ' ' . $this->getHumanizedArguments();
}
public function getHtmlAction()
{
$args = $this->getHumanizedArguments();
$args = preg_replace('~\$(.*?)\s~', '$<span style="color: #3C3C89; font-weight: bold;">$1</span>', $args);
return $this->humanize($this->getAction()) . ' <span style="color: #732E81;">' . $args . '</span>';
}
public function getHumanizedActionWithoutArguments()
{
return $this->humanize($this->getAction());
}
public function getHumanizedArguments()
{
return $this->clean($this->getArguments(true));
}
protected function clean($text)
{
return str_replace('\/', '', $text);
}
protected function humanize($text)
{
$text = preg_replace('/([A-Z]+)([A-Z][a-z])/', '\\1 \\2', $text);
$text = preg_replace('/([a-z\d])([A-Z])/', '\\1 \\2', $text);
$text = preg_replace('~\bdont\b~', 'don\'t', $text);
return strtolower($text);
}
public function run()
{
$this->executed = true;
$activeModule = \Codeception\SuiteManager::$modules[\Codeception\SuiteManager::$actions[$this->action]];
if (is_callable(array($activeModule, $this->action))) {
$result = call_user_func_array(array($activeModule, $this->action), $this->arguments);
} else {
throw new \RuntimeException("Action can't be called");
}
$this->debugOutput = $activeModule->_getDebugOutput();
return $result;
}
}