Repository navigation
Expand file tree
/
Copy pathParser.php
More file actions
99 lines (85 loc) · 2.63 KB
/
Copy pathParser.php
File metadata and controls
99 lines (85 loc) · 2.63 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
<?php
namespace Codeception;
use Codeception\Util\Debug;
class Parser {
protected $scenario;
protected $code;
public function __construct(Scenario $scenario)
{
$this->scenario = $scenario;
}
public function prepareToRun($code)
{
$this->parseFeature($code);
$this->parseScenarioOptions($code);
}
public function parseFeature($code)
{
$matches = array();
$res = preg_match("~\\\$I->wantTo\\(['\"](.*?)['\"]\\);~", $code, $matches);
if ($res) {
$this->scenario->setFeature($matches[1]);
return;
}
$res = preg_match("~\\\$I->wantToTest\\(['\"](.*?)['\"]\\);~", $code, $matches);
if ($res) {
$this->scenario->setFeature("test ".$matches[1]);
return;
}
}
public function parseScenarioOptions($code)
{
$matches = array();
$res = preg_match_all("~\\\$scenario->.*?;~", $code, $matches);
if (!$res) {
return;
}
$scenario = $this->scenario;
foreach ($matches[0] as $line) {
eval($line);
}
}
public function parseSteps($code)
{
// parse per line
$friends = [];
$lines = explode("\n", $code);
$isFriend = false;
foreach ($lines as $line) {
// friends
if (preg_match("~\\\$I->haveFriend\((.*?)\);~", $line, $matches)) {
$friends[] = trim($matches[1],'\'"');
}
// friend's section start
if (preg_match("~\\\$(.*?)->does\(~", $line, $matches)) {
if (!in_array($friend = $matches[1], $friends)) {
continue;
}
$isFriend = true;
$this->addCommentStep("\n----- $friend does -----");
continue;
}
// actions
if (preg_match("~\\\$I->(.*)\((.*?)\);~", $line, $matches)) {
$this->addStep($matches);
}
// friend's section ends
if ($isFriend and strpos($line, '}') !== false) {
$this->addCommentStep("-------- back to me\n");
$isFriend = false;
}
}
}
protected function addStep($matches)
{
list($m, $action, $params) = $matches;
if (in_array($action, array('wantTo','wantToTest'))) {
return;
}
$this->scenario->addStep(new Step\Action($action, explode(',', $params)));
}
protected function addCommentStep($comment)
{
$this->scenario->addStep(new \Codeception\Step\Comment($comment,array()));
}
}