1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Kolyunya\Codeception\Lib\MarkupValidator; |
4
|
|
|
|
5
|
|
|
use Kolyunya\Codeception\Lib\MarkupValidator\MarkupValidatorMessageInterface; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Base markup validator message. |
9
|
|
|
*/ |
10
|
|
|
class MarkupValidatorMessage implements MarkupValidatorMessageInterface |
11
|
|
|
{ |
12
|
|
|
/** |
13
|
|
|
* Placeholder for unavailable message data. |
14
|
|
|
*/ |
15
|
|
|
const UNAVAILABLE_DATA_PLACEHOLDER = 'unavailable'; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Message type. |
19
|
|
|
* |
20
|
|
|
* @var string |
21
|
|
|
*/ |
22
|
|
|
protected $type; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Message summary. |
26
|
|
|
* |
27
|
|
|
* @var string |
28
|
|
|
*/ |
29
|
|
|
protected $summary; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* Message details. |
33
|
|
|
* |
34
|
|
|
* @var string |
35
|
|
|
*/ |
36
|
|
|
protected $details; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* A number of the first related markup line. |
40
|
|
|
* |
41
|
|
|
* @var integer |
42
|
|
|
*/ |
43
|
|
|
protected $firstLineNumber; |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* A number of the last related markup line. |
47
|
|
|
* |
48
|
|
|
* @var integer |
49
|
|
|
*/ |
50
|
|
|
protected $lastLineNumber; |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* Related markup. |
54
|
|
|
* |
55
|
|
|
* @var string |
56
|
|
|
*/ |
57
|
|
|
protected $markup; |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* Constructs a new message. Sets message type. |
61
|
|
|
* |
62
|
|
|
* @param string $type Message type. |
63
|
|
|
*/ |
64
|
|
|
public function __construct($type = self::TYPE_UNDEFINED) |
65
|
|
|
{ |
66
|
|
|
$this->setType($type); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* {@inheritDoc} |
71
|
|
|
*/ |
72
|
|
|
public function __toString() |
73
|
|
|
{ |
74
|
|
|
return vsprintf($this->getStringTemplate(), array( |
75
|
|
|
$this->getType(), |
76
|
|
|
$this->getSummary() ?: self::UNAVAILABLE_DATA_PLACEHOLDER, |
77
|
|
|
$this->getDetails() ?: self::UNAVAILABLE_DATA_PLACEHOLDER, |
78
|
|
|
$this->getFirstLineNumber() ?: self::UNAVAILABLE_DATA_PLACEHOLDER, |
79
|
|
|
$this->getLastLineNumber() ?: self::UNAVAILABLE_DATA_PLACEHOLDER, |
80
|
|
|
$this->getMarkup() ?: self::UNAVAILABLE_DATA_PLACEHOLDER, |
81
|
|
|
)); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* Sets message type. |
86
|
|
|
* |
87
|
|
|
* @param string $type Message type. |
88
|
|
|
* |
89
|
|
|
* @return self Returns self. |
90
|
|
|
*/ |
91
|
|
|
public function setType($type) |
92
|
|
|
{ |
93
|
|
|
if ($type === null) { |
94
|
|
|
$type = self::TYPE_UNDEFINED; |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
$this->type = $type; |
98
|
|
|
|
99
|
|
|
return $this; |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* {@inheritDoc} |
104
|
|
|
*/ |
105
|
|
|
public function getType() |
106
|
|
|
{ |
107
|
|
|
return $this->type; |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* Sets message summary. |
112
|
|
|
* |
113
|
|
|
* @param string $summary Message summary. |
114
|
|
|
* |
115
|
|
|
* @return self Returns self. |
116
|
|
|
*/ |
117
|
|
|
public function setSummary($summary) |
118
|
|
|
{ |
119
|
|
|
$this->summary = $summary; |
120
|
|
|
|
121
|
|
|
return $this; |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* {@inheritDoc} |
126
|
|
|
*/ |
127
|
|
|
public function getSummary() |
128
|
|
|
{ |
129
|
|
|
return $this->summary; |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
/** |
133
|
|
|
* Sets message details. |
134
|
|
|
* |
135
|
|
|
* @param string $details Message details. |
136
|
|
|
* |
137
|
|
|
* @return self Returns self. |
138
|
|
|
*/ |
139
|
|
|
public function setDetails($details) |
140
|
|
|
{ |
141
|
|
|
$this->details = $details; |
142
|
|
|
|
143
|
|
|
return $this; |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
/** |
147
|
|
|
* {@inheritDoc} |
148
|
|
|
*/ |
149
|
|
|
public function getDetails() |
150
|
|
|
{ |
151
|
|
|
return $this->details; |
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
/** |
155
|
|
|
* Sets first line number. |
156
|
|
|
* |
157
|
|
|
* @param integer $firstLineNumber First line number. |
158
|
|
|
* |
159
|
|
|
* @return self Returns self. |
160
|
|
|
*/ |
161
|
|
|
public function setFirstLineNumber($firstLineNumber) |
162
|
|
|
{ |
163
|
|
|
$this->firstLineNumber = $firstLineNumber; |
164
|
|
|
|
165
|
|
|
return $this; |
166
|
|
|
} |
167
|
|
|
|
168
|
|
|
/** |
169
|
|
|
* {@inheritDoc} |
170
|
|
|
*/ |
171
|
|
|
public function getFirstLineNumber() |
172
|
|
|
{ |
173
|
|
|
return $this->firstLineNumber; |
174
|
|
|
} |
175
|
|
|
|
176
|
|
|
/** |
177
|
|
|
* Sets last line number. |
178
|
|
|
* |
179
|
|
|
* @param integer $lastLineNumber Last line number. |
180
|
|
|
* |
181
|
|
|
* @return self Returns self. |
182
|
|
|
*/ |
183
|
|
|
public function setLastLineNumber($lastLineNumber) |
184
|
|
|
{ |
185
|
|
|
$this->lastLineNumber = $lastLineNumber; |
186
|
|
|
|
187
|
|
|
return $this; |
188
|
|
|
} |
189
|
|
|
|
190
|
|
|
/** |
191
|
|
|
* {@inheritDoc} |
192
|
|
|
*/ |
193
|
|
|
public function getLastLineNumber() |
194
|
|
|
{ |
195
|
|
|
return $this->lastLineNumber; |
196
|
|
|
} |
197
|
|
|
|
198
|
|
|
/** |
199
|
|
|
* Sets markup. |
200
|
|
|
* |
201
|
|
|
* @param string $markup Markup. |
202
|
|
|
* |
203
|
|
|
* @return self Returns self. |
204
|
|
|
*/ |
205
|
|
|
public function setMarkup($markup) |
206
|
|
|
{ |
207
|
|
|
$this->markup = $markup; |
208
|
|
|
|
209
|
|
|
return $this; |
210
|
|
|
} |
211
|
|
|
|
212
|
|
|
/** |
213
|
|
|
* {@inheritDoc} |
214
|
|
|
*/ |
215
|
|
|
public function getMarkup() |
216
|
|
|
{ |
217
|
|
|
return $this->markup; |
218
|
|
|
} |
219
|
|
|
|
220
|
|
|
/** |
221
|
|
|
* Returns string representation template. |
222
|
|
|
* |
223
|
|
|
* @return string String representation template. |
224
|
|
|
*/ |
225
|
|
|
protected function getStringTemplate() |
226
|
|
|
{ |
227
|
|
|
return |
228
|
|
|
<<<TXT |
229
|
|
|
Markup validator message: |
230
|
|
|
Type: %s |
231
|
|
|
Summary: %s |
232
|
|
|
Details: %s |
233
|
|
|
First Line: %s |
234
|
|
|
Last Line: %s |
235
|
|
|
Markup: %s |
236
|
|
|
|
237
|
|
|
TXT |
238
|
|
|
; |
239
|
|
|
} |
240
|
|
|
} |
241
|
|
|
|