Repository navigation
Expand file tree
/
Copy pathStep.php
More file actions
127 lines (101 loc) · 3.32 KB
/
Copy pathStep.php
File metadata and controls
127 lines (101 loc) · 3.32 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;
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 getAction()
{
return $this->action;
}
public function getArguments($asString = false)
{
return ($asString) ? $this->getArgumentsAsString($this->arguments) : $this->arguments;
}
protected function getArgumentsAsString(array $arguments)
{
foreach ($arguments as $key => $argument) {
$arguments[$key] = (is_string($argument)) ? $argument : $this->parseArgumentAsString($argument);
}
if (defined('JSON_UNESCAPED_UNICODE')) {
return stripcslashes(trim(json_encode($arguments, JSON_UNESCAPED_UNICODE), '[]'));
}
return stripcslashes(trim(json_encode($arguments), '[]'));
}
protected function parseArgumentAsString($argument)
{
if (is_callable($argument, true)) {
return 'lambda function';
}
if (!is_object($argument)) {
return $argument;
}
if (method_exists($argument, '__toString')) {
return $argument->__toString();
}
return (isset($argument->__mocked)) ? $this->formatClassName($argument->__mocked) : $this->formatClassName(get_class($argument));
}
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 = preg_replace('~\$(.*?)\s~', '$<span style="color: #3C3C89; font-weight: bold;">$1</span>', $this->getHumanizedArguments());
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))) {
throw new \RuntimeException("Action can't be called");
}
return call_user_func_array(array($activeModule, $this->action), $this->arguments);
}
}