1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the Behat Gherkin. |
5
|
|
|
* (c) Konstantin Kudryashov <[email protected]> |
6
|
|
|
* |
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
8
|
|
|
* file that was distributed with this source code. |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace Behat\Gherkin\Node; |
12
|
|
|
|
13
|
|
|
use Behat\Gherkin\Exception\NodeException; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Represents Gherkin Step. |
17
|
|
|
* |
18
|
|
|
* @author Konstantin Kudryashov <[email protected]> |
19
|
|
|
*/ |
20
|
|
|
class StepNode implements NodeInterface |
21
|
|
|
{ |
22
|
|
|
/** |
23
|
|
|
* @var string |
24
|
|
|
*/ |
25
|
|
|
private $keyword; |
26
|
|
|
/** |
27
|
|
|
* @var string |
28
|
|
|
*/ |
29
|
|
|
private $keywordType; |
30
|
|
|
/** |
31
|
|
|
* @var string |
32
|
|
|
*/ |
33
|
|
|
private $text; |
34
|
|
|
/** |
35
|
|
|
* @var ArgumentInterface[] |
36
|
|
|
*/ |
37
|
|
|
private $arguments = array(); |
38
|
|
|
/** |
39
|
|
|
* @var integer |
40
|
|
|
*/ |
41
|
|
|
private $line; |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* Initializes step. |
45
|
|
|
* |
46
|
|
|
* @param string $keyword |
47
|
|
|
* @param string $text |
48
|
|
|
* @param ArgumentInterface[] $arguments |
49
|
|
|
* @param integer $line |
50
|
|
|
* @param string $keywordType |
51
|
|
|
*/ |
52
|
236 |
|
public function __construct($keyword, $text, array $arguments, $line, $keywordType = null) |
53
|
|
|
{ |
54
|
236 |
|
if (count($arguments) > 1) { |
55
|
1 |
|
throw new NodeException(sprintf( |
56
|
1 |
|
'Steps could have only one argument, but `%s %s` have %d.', |
57
|
|
|
$keyword, |
58
|
|
|
$text, |
59
|
1 |
|
count($arguments) |
60
|
|
|
)); |
61
|
|
|
} |
62
|
|
|
|
63
|
235 |
|
$this->keyword = $keyword; |
64
|
235 |
|
$this->text = $text; |
65
|
235 |
|
$this->arguments = $arguments; |
66
|
235 |
|
$this->line = $line; |
67
|
235 |
|
$this->keywordType = $keywordType ?: 'Given'; |
68
|
235 |
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* Returns node type string |
72
|
|
|
* |
73
|
|
|
* @return string |
74
|
|
|
*/ |
75
|
1 |
|
public function getNodeType() |
76
|
|
|
{ |
77
|
1 |
|
return 'Step'; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* Returns step keyword in provided language (Given, When, Then, etc.). |
82
|
|
|
* |
83
|
|
|
* @return string |
84
|
|
|
* |
85
|
|
|
* @deprecated use getKeyword() instead |
86
|
|
|
*/ |
87
|
4 |
|
public function getType() |
88
|
|
|
{ |
89
|
4 |
|
return $this->getKeyword(); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* Returns step keyword in provided language (Given, When, Then, etc.). |
94
|
|
|
* |
95
|
|
|
* @return string |
96
|
|
|
* |
97
|
|
|
*/ |
98
|
207 |
|
public function getKeyword() |
99
|
|
|
{ |
100
|
207 |
|
return $this->keyword; |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* Returns step type keyword (Given, When, Then, etc.). |
105
|
|
|
* |
106
|
|
|
* @return string |
107
|
|
|
*/ |
108
|
232 |
|
public function getKeywordType() |
109
|
|
|
{ |
110
|
232 |
|
return $this->keywordType; |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* Returns step text. |
115
|
|
|
* |
116
|
|
|
* @return string |
117
|
|
|
*/ |
118
|
207 |
|
public function getText() |
119
|
|
|
{ |
120
|
207 |
|
return $this->text; |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
/** |
124
|
|
|
* Checks if step has arguments. |
125
|
|
|
* |
126
|
|
|
* @return Boolean |
127
|
|
|
*/ |
128
|
|
|
public function hasArguments() |
129
|
|
|
{ |
130
|
|
|
return 0 < count($this->arguments); |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
/** |
134
|
|
|
* Returns step arguments. |
135
|
|
|
* |
136
|
|
|
* @return ArgumentInterface[] |
137
|
|
|
*/ |
138
|
205 |
|
public function getArguments() |
139
|
|
|
{ |
140
|
205 |
|
return $this->arguments; |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
/** |
144
|
|
|
* Returns step declaration line number. |
145
|
|
|
* |
146
|
|
|
* @return integer |
147
|
|
|
*/ |
148
|
207 |
|
public function getLine() |
149
|
|
|
{ |
150
|
207 |
|
return $this->line; |
151
|
|
|
} |
152
|
|
|
} |
153
|
|
|
|