| 1 |
lars |
1 |
<?php
|
|
|
2 |
/**
|
|
|
3 |
* PHPUnit
|
|
|
4 |
*
|
|
|
5 |
* Copyright (c) 2002-2010, Sebastian Bergmann <sb@sebastian-bergmann.de>.
|
|
|
6 |
* All rights reserved.
|
|
|
7 |
*
|
|
|
8 |
* Redistribution and use in source and binary forms, with or without
|
|
|
9 |
* modification, are permitted provided that the following conditions
|
|
|
10 |
* are met:
|
|
|
11 |
*
|
|
|
12 |
* * Redistributions of source code must retain the above copyright
|
|
|
13 |
* notice, this list of conditions and the following disclaimer.
|
|
|
14 |
*
|
|
|
15 |
* * Redistributions in binary form must reproduce the above copyright
|
|
|
16 |
* notice, this list of conditions and the following disclaimer in
|
|
|
17 |
* the documentation and/or other materials provided with the
|
|
|
18 |
* distribution.
|
|
|
19 |
*
|
|
|
20 |
* * Neither the name of Sebastian Bergmann nor the names of his
|
|
|
21 |
* contributors may be used to endorse or promote products derived
|
|
|
22 |
* from this software without specific prior written permission.
|
|
|
23 |
*
|
|
|
24 |
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
25 |
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
26 |
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
|
|
27 |
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
|
|
28 |
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
29 |
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
|
|
30 |
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
|
31 |
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
|
32 |
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
33 |
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
|
|
34 |
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
35 |
* POSSIBILITY OF SUCH DAMAGE.
|
|
|
36 |
*
|
|
|
37 |
* @category Testing
|
|
|
38 |
* @package PHPUnit
|
|
|
39 |
* @author Sebastian Bergmann <sb@sebastian-bergmann.de>
|
|
|
40 |
* @copyright 2002-2010 Sebastian Bergmann <sb@sebastian-bergmann.de>
|
|
|
41 |
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
|
|
|
42 |
* @link http://www.phpunit.de/
|
|
|
43 |
* @since File available since Release 2.0.0
|
|
|
44 |
*/
|
|
|
45 |
|
|
|
46 |
require_once 'PHPUnit/Framework.php';
|
|
|
47 |
require_once 'PHPUnit/Util/Class.php';
|
|
|
48 |
require_once 'PHPUnit/Util/InvalidArgumentHelper.php';
|
|
|
49 |
require_once 'PHPUnit/Util/Type.php';
|
|
|
50 |
require_once 'PHPUnit/Util/XML.php';
|
|
|
51 |
|
|
|
52 |
PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT');
|
|
|
53 |
|
|
|
54 |
/**
|
|
|
55 |
* A set of assert methods.
|
|
|
56 |
*
|
|
|
57 |
* @category Testing
|
|
|
58 |
* @package PHPUnit
|
|
|
59 |
* @author Sebastian Bergmann <sb@sebastian-bergmann.de>
|
|
|
60 |
* @copyright 2002-2010 Sebastian Bergmann <sb@sebastian-bergmann.de>
|
|
|
61 |
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
|
|
|
62 |
* @version Release: 3.4.15
|
|
|
63 |
* @link http://www.phpunit.de/
|
|
|
64 |
* @since Class available since Release 2.0.0
|
|
|
65 |
*/
|
|
|
66 |
abstract class PHPUnit_Framework_Assert
|
|
|
67 |
{
|
|
|
68 |
/**
|
|
|
69 |
* @var integer
|
|
|
70 |
*/
|
|
|
71 |
private static $count = 0;
|
|
|
72 |
|
|
|
73 |
/**
|
|
|
74 |
* Asserts that an array has a specified key.
|
|
|
75 |
*
|
|
|
76 |
* @param mixed $key
|
|
|
77 |
* @param array $array
|
|
|
78 |
* @param string $message
|
|
|
79 |
* @since Method available since Release 3.0.0
|
|
|
80 |
*/
|
|
|
81 |
public static function assertArrayHasKey($key, array $array, $message = '')
|
|
|
82 |
{
|
|
|
83 |
if (!(is_integer($key) || is_string($key))) {
|
|
|
84 |
throw PHPUnit_Util_InvalidArgumentHelper::factory(
|
|
|
85 |
1, 'integer or string'
|
|
|
86 |
);
|
|
|
87 |
}
|
|
|
88 |
|
|
|
89 |
$constraint = new PHPUnit_Framework_Constraint_ArrayHasKey($key);
|
|
|
90 |
|
|
|
91 |
self::assertThat($array, $constraint, $message);
|
|
|
92 |
}
|
|
|
93 |
|
|
|
94 |
/**
|
|
|
95 |
* Asserts that an array does not have a specified key.
|
|
|
96 |
*
|
|
|
97 |
* @param mixed $key
|
|
|
98 |
* @param array $array
|
|
|
99 |
* @param string $message
|
|
|
100 |
* @since Method available since Release 3.0.0
|
|
|
101 |
*/
|
|
|
102 |
public static function assertArrayNotHasKey($key, array $array, $message = '')
|
|
|
103 |
{
|
|
|
104 |
if (!(is_integer($key) || is_string($key))) {
|
|
|
105 |
throw PHPUnit_Util_InvalidArgumentHelper::factory(
|
|
|
106 |
1, 'integer or string'
|
|
|
107 |
);
|
|
|
108 |
}
|
|
|
109 |
|
|
|
110 |
$constraint = new PHPUnit_Framework_Constraint_Not(
|
|
|
111 |
new PHPUnit_Framework_Constraint_ArrayHasKey($key)
|
|
|
112 |
);
|
|
|
113 |
|
|
|
114 |
self::assertThat($array, $constraint, $message);
|
|
|
115 |
}
|
|
|
116 |
|
|
|
117 |
/**
|
|
|
118 |
* Asserts that a haystack contains a needle.
|
|
|
119 |
*
|
|
|
120 |
* @param mixed $needle
|
|
|
121 |
* @param mixed $haystack
|
|
|
122 |
* @param string $message
|
|
|
123 |
* @param boolean $ignoreCase
|
|
|
124 |
* @since Method available since Release 2.1.0
|
|
|
125 |
*/
|
|
|
126 |
public static function assertContains($needle, $haystack, $message = '', $ignoreCase = FALSE)
|
|
|
127 |
{
|
|
|
128 |
if (is_array($haystack) ||
|
|
|
129 |
is_object($haystack) && $haystack instanceof Traversable) {
|
|
|
130 |
$constraint = new PHPUnit_Framework_Constraint_TraversableContains(
|
|
|
131 |
$needle
|
|
|
132 |
);
|
|
|
133 |
}
|
|
|
134 |
|
|
|
135 |
else if (is_string($haystack)) {
|
|
|
136 |
$constraint = new PHPUnit_Framework_Constraint_StringContains(
|
|
|
137 |
$needle, $ignoreCase
|
|
|
138 |
);
|
|
|
139 |
}
|
|
|
140 |
|
|
|
141 |
else {
|
|
|
142 |
throw PHPUnit_Util_InvalidArgumentHelper::factory(
|
|
|
143 |
2, 'array, iterator or string'
|
|
|
144 |
);
|
|
|
145 |
}
|
|
|
146 |
|
|
|
147 |
self::assertThat($haystack, $constraint, $message);
|
|
|
148 |
}
|
|
|
149 |
|
|
|
150 |
/**
|
|
|
151 |
* Asserts that a haystack that is stored in a static attribute of a class
|
|
|
152 |
* or an attribute of an object contains a needle.
|
|
|
153 |
*
|
|
|
154 |
* @param mixed $needle
|
|
|
155 |
* @param string $haystackAttributeName
|
|
|
156 |
* @param mixed $haystackClassOrObject
|
|
|
157 |
* @param string $message
|
|
|
158 |
* @param boolean $ignoreCase
|
|
|
159 |
* @since Method available since Release 3.0.0
|
|
|
160 |
*/
|
|
|
161 |
public static function assertAttributeContains($needle, $haystackAttributeName, $haystackClassOrObject, $message = '', $ignoreCase = FALSE)
|
|
|
162 |
{
|
|
|
163 |
self::assertContains(
|
|
|
164 |
$needle,
|
|
|
165 |
self::readAttribute($haystackClassOrObject, $haystackAttributeName),
|
|
|
166 |
$message,
|
|
|
167 |
$ignoreCase
|
|
|
168 |
);
|
|
|
169 |
}
|
|
|
170 |
|
|
|
171 |
/**
|
|
|
172 |
* Asserts that a haystack does not contain a needle.
|
|
|
173 |
*
|
|
|
174 |
* @param mixed $needle
|
|
|
175 |
* @param mixed $haystack
|
|
|
176 |
* @param string $message
|
|
|
177 |
* @param boolean $ignoreCase
|
|
|
178 |
* @since Method available since Release 2.1.0
|
|
|
179 |
*/
|
|
|
180 |
public static function assertNotContains($needle, $haystack, $message = '', $ignoreCase = FALSE)
|
|
|
181 |
{
|
|
|
182 |
if (is_array($haystack) ||
|
|
|
183 |
is_object($haystack) && $haystack instanceof Traversable) {
|
|
|
184 |
$constraint = new PHPUnit_Framework_Constraint_Not(
|
|
|
185 |
new PHPUnit_Framework_Constraint_TraversableContains($needle)
|
|
|
186 |
);
|
|
|
187 |
}
|
|
|
188 |
|
|
|
189 |
else if (is_string($haystack)) {
|
|
|
190 |
$constraint = new PHPUnit_Framework_Constraint_Not(
|
|
|
191 |
new PHPUnit_Framework_Constraint_StringContains(
|
|
|
192 |
$needle, $ignoreCase
|
|
|
193 |
)
|
|
|
194 |
);
|
|
|
195 |
}
|
|
|
196 |
|
|
|
197 |
else {
|
|
|
198 |
throw PHPUnit_Util_InvalidArgumentHelper::factory(
|
|
|
199 |
2, 'array, iterator or string'
|
|
|
200 |
);
|
|
|
201 |
}
|
|
|
202 |
|
|
|
203 |
self::assertThat($haystack, $constraint, $message);
|
|
|
204 |
}
|
|
|
205 |
|
|
|
206 |
/**
|
|
|
207 |
* Asserts that a haystack that is stored in a static attribute of a class
|
|
|
208 |
* or an attribute of an object does not contain a needle.
|
|
|
209 |
*
|
|
|
210 |
* @param mixed $needle
|
|
|
211 |
* @param string $haystackAttributeName
|
|
|
212 |
* @param mixed $haystackClassOrObject
|
|
|
213 |
* @param string $message
|
|
|
214 |
* @param boolean $ignoreCase
|
|
|
215 |
* @since Method available since Release 3.0.0
|
|
|
216 |
*/
|
|
|
217 |
public static function assertAttributeNotContains($needle, $haystackAttributeName, $haystackClassOrObject, $message = '', $ignoreCase = FALSE)
|
|
|
218 |
{
|
|
|
219 |
self::assertNotContains(
|
|
|
220 |
$needle,
|
|
|
221 |
self::readAttribute($haystackClassOrObject, $haystackAttributeName),
|
|
|
222 |
$message,
|
|
|
223 |
$ignoreCase
|
|
|
224 |
);
|
|
|
225 |
}
|
|
|
226 |
|
|
|
227 |
/**
|
|
|
228 |
* Asserts that a haystack contains only values of a given type.
|
|
|
229 |
*
|
|
|
230 |
* @param string $type
|
|
|
231 |
* @param mixed $haystack
|
|
|
232 |
* @param boolean $isNativeType
|
|
|
233 |
* @param string $message
|
|
|
234 |
* @since Method available since Release 3.1.4
|
|
|
235 |
*/
|
|
|
236 |
public static function assertContainsOnly($type, $haystack, $isNativeType = NULL, $message = '')
|
|
|
237 |
{
|
|
|
238 |
if (!(is_array($haystack) ||
|
|
|
239 |
is_object($haystack) && $haystack instanceof Traversable)) {
|
|
|
240 |
throw PHPUnit_Util_InvalidArgumentHelper::factory(
|
|
|
241 |
2, 'array or iterator'
|
|
|
242 |
);
|
|
|
243 |
}
|
|
|
244 |
|
|
|
245 |
if ($isNativeType == NULL) {
|
|
|
246 |
$isNativeType = PHPUnit_Util_Type::isType($type);
|
|
|
247 |
}
|
|
|
248 |
|
|
|
249 |
self::assertThat(
|
|
|
250 |
$haystack,
|
|
|
251 |
new PHPUnit_Framework_Constraint_TraversableContainsOnly(
|
|
|
252 |
$type, $isNativeType
|
|
|
253 |
),
|
|
|
254 |
$message
|
|
|
255 |
);
|
|
|
256 |
}
|
|
|
257 |
|
|
|
258 |
/**
|
|
|
259 |
* Asserts that a haystack that is stored in a static attribute of a class
|
|
|
260 |
* or an attribute of an object contains only values of a given type.
|
|
|
261 |
*
|
|
|
262 |
* @param string $type
|
|
|
263 |
* @param string $haystackAttributeName
|
|
|
264 |
* @param mixed $haystackClassOrObject
|
|
|
265 |
* @param boolean $isNativeType
|
|
|
266 |
* @param string $message
|
|
|
267 |
* @since Method available since Release 3.1.4
|
|
|
268 |
*/
|
|
|
269 |
public static function assertAttributeContainsOnly($type, $haystackAttributeName, $haystackClassOrObject, $isNativeType = NULL, $message = '')
|
|
|
270 |
{
|
|
|
271 |
self::assertContainsOnly(
|
|
|
272 |
$type,
|
|
|
273 |
self::readAttribute($haystackClassOrObject, $haystackAttributeName),
|
|
|
274 |
$isNativeType,
|
|
|
275 |
$message
|
|
|
276 |
);
|
|
|
277 |
}
|
|
|
278 |
|
|
|
279 |
/**
|
|
|
280 |
* Asserts that a haystack does not contain only values of a given type.
|
|
|
281 |
*
|
|
|
282 |
* @param string $type
|
|
|
283 |
* @param mixed $haystack
|
|
|
284 |
* @param boolean $isNativeType
|
|
|
285 |
* @param string $message
|
|
|
286 |
* @since Method available since Release 3.1.4
|
|
|
287 |
*/
|
|
|
288 |
public static function assertNotContainsOnly($type, $haystack, $isNativeType = NULL, $message = '')
|
|
|
289 |
{
|
|
|
290 |
if (!(is_array($haystack) ||
|
|
|
291 |
is_object($haystack) && $haystack instanceof Traversable)) {
|
|
|
292 |
throw PHPUnit_Util_InvalidArgumentHelper::factory(
|
|
|
293 |
2, 'array or iterator'
|
|
|
294 |
);
|
|
|
295 |
}
|
|
|
296 |
|
|
|
297 |
if ($isNativeType == NULL) {
|
|
|
298 |
$isNativeType = PHPUnit_Util_Type::isType($type);
|
|
|
299 |
}
|
|
|
300 |
|
|
|
301 |
self::assertThat(
|
|
|
302 |
$haystack,
|
|
|
303 |
new PHPUnit_Framework_Constraint_Not(
|
|
|
304 |
new PHPUnit_Framework_Constraint_TraversableContainsOnly(
|
|
|
305 |
$type, $isNativeType
|
|
|
306 |
)
|
|
|
307 |
),
|
|
|
308 |
$message
|
|
|
309 |
);
|
|
|
310 |
}
|
|
|
311 |
|
|
|
312 |
/**
|
|
|
313 |
* Asserts that a haystack that is stored in a static attribute of a class
|
|
|
314 |
* or an attribute of an object does not contain only values of a given
|
|
|
315 |
* type.
|
|
|
316 |
*
|
|
|
317 |
* @param string $type
|
|
|
318 |
* @param string $haystackAttributeName
|
|
|
319 |
* @param mixed $haystackClassOrObject
|
|
|
320 |
* @param boolean $isNativeType
|
|
|
321 |
* @param string $message
|
|
|
322 |
* @since Method available since Release 3.1.4
|
|
|
323 |
*/
|
|
|
324 |
public static function assertAttributeNotContainsOnly($type, $haystackAttributeName, $haystackClassOrObject, $isNativeType = NULL, $message = '')
|
|
|
325 |
{
|
|
|
326 |
self::assertNotContainsOnly(
|
|
|
327 |
$type,
|
|
|
328 |
self::readAttribute($haystackClassOrObject, $haystackAttributeName),
|
|
|
329 |
$isNativeType,
|
|
|
330 |
$message
|
|
|
331 |
);
|
|
|
332 |
}
|
|
|
333 |
|
|
|
334 |
/**
|
|
|
335 |
* Asserts that two variables are equal.
|
|
|
336 |
*
|
|
|
337 |
* @param mixed $expected
|
|
|
338 |
* @param mixed $actual
|
|
|
339 |
* @param string $message
|
|
|
340 |
* @param float $delta
|
|
|
341 |
* @param integer $maxDepth
|
|
|
342 |
* @param boolean $canonicalizeEol
|
|
|
343 |
* @param boolean $ignoreCase
|
|
|
344 |
*/
|
|
|
345 |
public static function assertEquals($expected, $actual, $message = '', $delta = 0, $maxDepth = 10, $canonicalizeEol = FALSE, $ignoreCase = FALSE)
|
|
|
346 |
{
|
|
|
347 |
$constraint = new PHPUnit_Framework_Constraint_IsEqual(
|
|
|
348 |
$expected, $delta, $maxDepth, $canonicalizeEol, $ignoreCase
|
|
|
349 |
);
|
|
|
350 |
|
|
|
351 |
self::assertThat($actual, $constraint, $message);
|
|
|
352 |
}
|
|
|
353 |
|
|
|
354 |
/**
|
|
|
355 |
* Asserts that a variable is equal to an attribute of an object.
|
|
|
356 |
*
|
|
|
357 |
* @param mixed $expected
|
|
|
358 |
* @param string $actualAttributeName
|
|
|
359 |
* @param string $actualClassOrObject
|
|
|
360 |
* @param string $message
|
|
|
361 |
* @param float $delta
|
|
|
362 |
* @param integer $maxDepth
|
|
|
363 |
* @param boolean $canonicalizeEol
|
|
|
364 |
* @param boolean $ignoreCase
|
|
|
365 |
*/
|
|
|
366 |
public static function assertAttributeEquals($expected, $actualAttributeName, $actualClassOrObject, $message = '', $delta = 0, $maxDepth = 10, $canonicalizeEol = FALSE, $ignoreCase = FALSE)
|
|
|
367 |
{
|
|
|
368 |
self::assertEquals(
|
|
|
369 |
$expected,
|
|
|
370 |
self::readAttribute($actualClassOrObject, $actualAttributeName),
|
|
|
371 |
$message,
|
|
|
372 |
$delta,
|
|
|
373 |
$maxDepth,
|
|
|
374 |
$canonicalizeEol,
|
|
|
375 |
$ignoreCase
|
|
|
376 |
);
|
|
|
377 |
}
|
|
|
378 |
|
|
|
379 |
/**
|
|
|
380 |
* Asserts that two variables are not equal.
|
|
|
381 |
*
|
|
|
382 |
* @param mixed $expected
|
|
|
383 |
* @param mixed $actual
|
|
|
384 |
* @param string $message
|
|
|
385 |
* @param float $delta
|
|
|
386 |
* @param integer $maxDepth
|
|
|
387 |
* @param boolean $canonicalizeEol
|
|
|
388 |
* @param boolean $ignoreCase
|
|
|
389 |
* @since Method available since Release 2.3.0
|
|
|
390 |
*/
|
|
|
391 |
public static function assertNotEquals($expected, $actual, $message = '', $delta = 0, $maxDepth = 10, $canonicalizeEol = FALSE, $ignoreCase = FALSE)
|
|
|
392 |
{
|
|
|
393 |
$constraint = new PHPUnit_Framework_Constraint_Not(
|
|
|
394 |
new PHPUnit_Framework_Constraint_IsEqual(
|
|
|
395 |
$expected, $delta, $maxDepth, $canonicalizeEol, $ignoreCase
|
|
|
396 |
)
|
|
|
397 |
);
|
|
|
398 |
|
|
|
399 |
self::assertThat($actual, $constraint, $message);
|
|
|
400 |
}
|
|
|
401 |
|
|
|
402 |
/**
|
|
|
403 |
* Asserts that a variable is not equal to an attribute of an object.
|
|
|
404 |
*
|
|
|
405 |
* @param mixed $expected
|
|
|
406 |
* @param string $actualAttributeName
|
|
|
407 |
* @param string $actualClassOrObject
|
|
|
408 |
* @param string $message
|
|
|
409 |
* @param float $delta
|
|
|
410 |
* @param integer $maxDepth
|
|
|
411 |
* @param boolean $canonicalizeEol
|
|
|
412 |
* @param boolean $ignoreCase
|
|
|
413 |
*/
|
|
|
414 |
public static function assertAttributeNotEquals($expected, $actualAttributeName, $actualClassOrObject, $message = '', $delta = 0, $maxDepth = 10, $canonicalizeEol = FALSE, $ignoreCase = FALSE)
|
|
|
415 |
{
|
|
|
416 |
self::assertNotEquals(
|
|
|
417 |
$expected,
|
|
|
418 |
self::readAttribute($actualClassOrObject, $actualAttributeName),
|
|
|
419 |
$message,
|
|
|
420 |
$delta,
|
|
|
421 |
$maxDepth,
|
|
|
422 |
$canonicalizeEol,
|
|
|
423 |
$ignoreCase
|
|
|
424 |
);
|
|
|
425 |
}
|
|
|
426 |
|
|
|
427 |
/**
|
|
|
428 |
* Asserts that a value is greater than another value.
|
|
|
429 |
*
|
|
|
430 |
* @param mixed $expected
|
|
|
431 |
* @param mixed $actual
|
|
|
432 |
* @param string $message
|
|
|
433 |
* @since Method available since Release 3.1.0
|
|
|
434 |
*/
|
|
|
435 |
public static function assertGreaterThan($expected, $actual, $message = '')
|
|
|
436 |
{
|
|
|
437 |
self::assertThat($actual, self::greaterThan($expected), $message);
|
|
|
438 |
}
|
|
|
439 |
|
|
|
440 |
/**
|
|
|
441 |
* Asserts that an attribute is greater than another value.
|
|
|
442 |
*
|
|
|
443 |
* @param mixed $expected
|
|
|
444 |
* @param string $actualAttributeName
|
|
|
445 |
* @param string $actualClassOrObject
|
|
|
446 |
* @param string $message
|
|
|
447 |
* @since Method available since Release 3.1.0
|
|
|
448 |
*/
|
|
|
449 |
public static function assertAttributeGreaterThan($expected, $actualAttributeName, $actualClassOrObject, $message = '')
|
|
|
450 |
{
|
|
|
451 |
self::assertGreaterThan(
|
|
|
452 |
$expected,
|
|
|
453 |
self::readAttribute($actualClassOrObject, $actualAttributeName),
|
|
|
454 |
$message
|
|
|
455 |
);
|
|
|
456 |
}
|
|
|
457 |
|
|
|
458 |
/**
|
|
|
459 |
* Asserts that a value is greater than or equal to another value.
|
|
|
460 |
*
|
|
|
461 |
* @param mixed $expected
|
|
|
462 |
* @param mixed $actual
|
|
|
463 |
* @param string $message
|
|
|
464 |
* @since Method available since Release 3.1.0
|
|
|
465 |
*/
|
|
|
466 |
public static function assertGreaterThanOrEqual($expected, $actual, $message = '')
|
|
|
467 |
{
|
|
|
468 |
self::assertThat(
|
|
|
469 |
$actual, self::greaterThanOrEqual($expected), $message
|
|
|
470 |
);
|
|
|
471 |
}
|
|
|
472 |
|
|
|
473 |
/**
|
|
|
474 |
* Asserts that an attribute is greater than or equal to another value.
|
|
|
475 |
*
|
|
|
476 |
* @param mixed $expected
|
|
|
477 |
* @param string $actualAttributeName
|
|
|
478 |
* @param string $actualClassOrObject
|
|
|
479 |
* @param string $message
|
|
|
480 |
* @since Method available since Release 3.1.0
|
|
|
481 |
*/
|
|
|
482 |
public static function assertAttributeGreaterThanOrEqual($expected, $actualAttributeName, $actualClassOrObject, $message = '')
|
|
|
483 |
{
|
|
|
484 |
self::assertGreaterThanOrEqual(
|
|
|
485 |
$expected,
|
|
|
486 |
self::readAttribute($actualClassOrObject, $actualAttributeName),
|
|
|
487 |
$message
|
|
|
488 |
);
|
|
|
489 |
}
|
|
|
490 |
|
|
|
491 |
/**
|
|
|
492 |
* Asserts that a value is smaller than another value.
|
|
|
493 |
*
|
|
|
494 |
* @param mixed $expected
|
|
|
495 |
* @param mixed $actual
|
|
|
496 |
* @param string $message
|
|
|
497 |
* @since Method available since Release 3.1.0
|
|
|
498 |
*/
|
|
|
499 |
public static function assertLessThan($expected, $actual, $message = '')
|
|
|
500 |
{
|
|
|
501 |
self::assertThat($actual, self::lessThan($expected), $message);
|
|
|
502 |
}
|
|
|
503 |
|
|
|
504 |
/**
|
|
|
505 |
* Asserts that an attribute is smaller than another value.
|
|
|
506 |
*
|
|
|
507 |
* @param mixed $expected
|
|
|
508 |
* @param string $actualAttributeName
|
|
|
509 |
* @param string $actualClassOrObject
|
|
|
510 |
* @param string $message
|
|
|
511 |
* @since Method available since Release 3.1.0
|
|
|
512 |
*/
|
|
|
513 |
public static function assertAttributeLessThan($expected, $actualAttributeName, $actualClassOrObject, $message = '')
|
|
|
514 |
{
|
|
|
515 |
self::assertLessThan(
|
|
|
516 |
$expected,
|
|
|
517 |
self::readAttribute($actualClassOrObject, $actualAttributeName),
|
|
|
518 |
$message
|
|
|
519 |
);
|
|
|
520 |
}
|
|
|
521 |
|
|
|
522 |
/**
|
|
|
523 |
* Asserts that a value is smaller than or equal to another value.
|
|
|
524 |
*
|
|
|
525 |
* @param mixed $expected
|
|
|
526 |
* @param mixed $actual
|
|
|
527 |
* @param string $message
|
|
|
528 |
* @since Method available since Release 3.1.0
|
|
|
529 |
*/
|
|
|
530 |
public static function assertLessThanOrEqual($expected, $actual, $message = '')
|
|
|
531 |
{
|
|
|
532 |
self::assertThat($actual, self::lessThanOrEqual($expected), $message);
|
|
|
533 |
}
|
|
|
534 |
|
|
|
535 |
/**
|
|
|
536 |
* Asserts that an attribute is smaller than or equal to another value.
|
|
|
537 |
*
|
|
|
538 |
* @param mixed $expected
|
|
|
539 |
* @param string $actualAttributeName
|
|
|
540 |
* @param string $actualClassOrObject
|
|
|
541 |
* @param string $message
|
|
|
542 |
* @since Method available since Release 3.1.0
|
|
|
543 |
*/
|
|
|
544 |
public static function assertAttributeLessThanOrEqual($expected, $actualAttributeName, $actualClassOrObject, $message = '')
|
|
|
545 |
{
|
|
|
546 |
self::assertLessThanOrEqual(
|
|
|
547 |
$expected,
|
|
|
548 |
self::readAttribute($actualClassOrObject, $actualAttributeName),
|
|
|
549 |
$message
|
|
|
550 |
);
|
|
|
551 |
}
|
|
|
552 |
|
|
|
553 |
/**
|
|
|
554 |
* Asserts that the contents of one file is equal to the contents of another
|
|
|
555 |
* file.
|
|
|
556 |
*
|
|
|
557 |
* @param string $expected
|
|
|
558 |
* @param string $actual
|
|
|
559 |
* @param string $message
|
|
|
560 |
* @param boolean $canonicalizeEol
|
|
|
561 |
* @param boolean $ignoreCase
|
|
|
562 |
* @since Method available since Release 3.2.14
|
|
|
563 |
*/
|
|
|
564 |
public static function assertFileEquals($expected, $actual, $message = '', $canonicalizeEol = FALSE, $ignoreCase = FALSE)
|
|
|
565 |
{
|
|
|
566 |
self::assertFileExists($expected, $message);
|
|
|
567 |
self::assertFileExists($actual, $message);
|
|
|
568 |
|
|
|
569 |
self::assertEquals(
|
|
|
570 |
file_get_contents($expected),
|
|
|
571 |
file_get_contents($actual),
|
|
|
572 |
$message,
|
|
|
573 |
0,
|
|
|
574 |
10,
|
|
|
575 |
$canonicalizeEol,
|
|
|
576 |
$ignoreCase
|
|
|
577 |
);
|
|
|
578 |
}
|
|
|
579 |
|
|
|
580 |
/**
|
|
|
581 |
* Asserts that the contents of one file is not equal to the contents of
|
|
|
582 |
* another file.
|
|
|
583 |
*
|
|
|
584 |
* @param string $expected
|
|
|
585 |
* @param string $actual
|
|
|
586 |
* @param string $message
|
|
|
587 |
* @param boolean $canonicalizeEol
|
|
|
588 |
* @param boolean $ignoreCase
|
|
|
589 |
* @since Method available since Release 3.2.14
|
|
|
590 |
*/
|
|
|
591 |
public static function assertFileNotEquals($expected, $actual, $message = '', $canonicalizeEol = FALSE, $ignoreCase = FALSE)
|
|
|
592 |
{
|
|
|
593 |
self::assertFileExists($expected, $message);
|
|
|
594 |
self::assertFileExists($actual, $message);
|
|
|
595 |
|
|
|
596 |
self::assertNotEquals(
|
|
|
597 |
file_get_contents($expected),
|
|
|
598 |
file_get_contents($actual),
|
|
|
599 |
$message,
|
|
|
600 |
0,
|
|
|
601 |
10,
|
|
|
602 |
$canonicalizeEol,
|
|
|
603 |
$ignoreCase
|
|
|
604 |
);
|
|
|
605 |
}
|
|
|
606 |
|
|
|
607 |
/**
|
|
|
608 |
* Asserts that the contents of a string is equal
|
|
|
609 |
* to the contents of a file.
|
|
|
610 |
*
|
|
|
611 |
* @param string $expectedFile
|
|
|
612 |
* @param string $actualString
|
|
|
613 |
* @param string $message
|
|
|
614 |
* @param boolean $canonicalizeEol
|
|
|
615 |
* @param boolean $ignoreCase
|
|
|
616 |
* @since Method available since Release 3.3.0
|
|
|
617 |
*/
|
|
|
618 |
public static function assertStringEqualsFile($expectedFile, $actualString, $message = '', $canonicalizeEol = FALSE, $ignoreCase = FALSE)
|
|
|
619 |
{
|
|
|
620 |
self::assertFileExists($expectedFile, $message);
|
|
|
621 |
|
|
|
622 |
self::assertEquals(
|
|
|
623 |
file_get_contents($expectedFile),
|
|
|
624 |
$actualString,
|
|
|
625 |
$message,
|
|
|
626 |
0,
|
|
|
627 |
10,
|
|
|
628 |
$canonicalizeEol,
|
|
|
629 |
$ignoreCase
|
|
|
630 |
);
|
|
|
631 |
}
|
|
|
632 |
|
|
|
633 |
/**
|
|
|
634 |
* Asserts that the contents of a string is not equal
|
|
|
635 |
* to the contents of a file.
|
|
|
636 |
*
|
|
|
637 |
* @param string $expectedFile
|
|
|
638 |
* @param string $actualString
|
|
|
639 |
* @param string $message
|
|
|
640 |
* @param boolean $canonicalizeEol
|
|
|
641 |
* @param boolean $ignoreCase
|
|
|
642 |
* @since Method available since Release 3.3.0
|
|
|
643 |
*/
|
|
|
644 |
public static function assertStringNotEqualsFile($expectedFile, $actualString, $message = '', $canonicalizeEol = FALSE, $ignoreCase = FALSE)
|
|
|
645 |
{
|
|
|
646 |
self::assertFileExists($expectedFile, $message);
|
|
|
647 |
|
|
|
648 |
self::assertNotEquals(
|
|
|
649 |
file_get_contents($expectedFile),
|
|
|
650 |
$actualString,
|
|
|
651 |
$message,
|
|
|
652 |
0,
|
|
|
653 |
10,
|
|
|
654 |
$canonicalizeEol,
|
|
|
655 |
$ignoreCase
|
|
|
656 |
);
|
|
|
657 |
}
|
|
|
658 |
|
|
|
659 |
/**
|
|
|
660 |
* Asserts that a file exists.
|
|
|
661 |
*
|
|
|
662 |
* @param string $filename
|
|
|
663 |
* @param string $message
|
|
|
664 |
* @since Method available since Release 3.0.0
|
|
|
665 |
*/
|
|
|
666 |
public static function assertFileExists($filename, $message = '')
|
|
|
667 |
{
|
|
|
668 |
if (!is_string($filename)) {
|
|
|
669 |
throw PHPUnit_Util_InvalidArgumentHelper::factory(1, 'string');
|
|
|
670 |
}
|
|
|
671 |
|
|
|
672 |
$constraint = new PHPUnit_Framework_Constraint_FileExists;
|
|
|
673 |
|
|
|
674 |
self::assertThat($filename, $constraint, $message);
|
|
|
675 |
}
|
|
|
676 |
|
|
|
677 |
/**
|
|
|
678 |
* Asserts that a file does not exist.
|
|
|
679 |
*
|
|
|
680 |
* @param string $filename
|
|
|
681 |
* @param string $message
|
|
|
682 |
* @since Method available since Release 3.0.0
|
|
|
683 |
*/
|
|
|
684 |
public static function assertFileNotExists($filename, $message = '')
|
|
|
685 |
{
|
|
|
686 |
if (!is_string($filename)) {
|
|
|
687 |
throw PHPUnit_Util_InvalidArgumentHelper::factory(1, 'string');
|
|
|
688 |
}
|
|
|
689 |
|
|
|
690 |
$constraint = new PHPUnit_Framework_Constraint_Not(
|
|
|
691 |
new PHPUnit_Framework_Constraint_FileExists
|
|
|
692 |
);
|
|
|
693 |
|
|
|
694 |
self::assertThat($filename, $constraint, $message);
|
|
|
695 |
}
|
|
|
696 |
|
|
|
697 |
/**
|
|
|
698 |
* Asserts that a condition is true.
|
|
|
699 |
*
|
|
|
700 |
* @param boolean $condition
|
|
|
701 |
* @param string $message
|
|
|
702 |
* @throws PHPUnit_Framework_AssertionFailedError
|
|
|
703 |
*/
|
|
|
704 |
public static function assertTrue($condition, $message = '')
|
|
|
705 |
{
|
|
|
706 |
self::assertThat($condition, self::isTrue(), $message);
|
|
|
707 |
}
|
|
|
708 |
|
|
|
709 |
/**
|
|
|
710 |
* Asserts that a condition is false.
|
|
|
711 |
*
|
|
|
712 |
* @param boolean $condition
|
|
|
713 |
* @param string $message
|
|
|
714 |
* @throws PHPUnit_Framework_AssertionFailedError
|
|
|
715 |
*/
|
|
|
716 |
public static function assertFalse($condition, $message = '')
|
|
|
717 |
{
|
|
|
718 |
self::assertThat($condition, self::isFalse(), $message);
|
|
|
719 |
}
|
|
|
720 |
|
|
|
721 |
/**
|
|
|
722 |
* Asserts that a variable is not NULL.
|
|
|
723 |
*
|
|
|
724 |
* @param mixed $actual
|
|
|
725 |
* @param string $message
|
|
|
726 |
*/
|
|
|
727 |
public static function assertNotNull($actual, $message = '')
|
|
|
728 |
{
|
|
|
729 |
self::assertThat($actual, self::logicalNot(self::isNull()), $message);
|
|
|
730 |
}
|
|
|
731 |
|
|
|
732 |
/**
|
|
|
733 |
* Asserts that a variable is NULL.
|
|
|
734 |
*
|
|
|
735 |
* @param mixed $actual
|
|
|
736 |
* @param string $message
|
|
|
737 |
*/
|
|
|
738 |
public static function assertNull($actual, $message = '')
|
|
|
739 |
{
|
|
|
740 |
self::assertThat($actual, self::isNull(), $message);
|
|
|
741 |
}
|
|
|
742 |
|
|
|
743 |
/**
|
|
|
744 |
* Asserts that a class has a specified attribute.
|
|
|
745 |
*
|
|
|
746 |
* @param string $attributeName
|
|
|
747 |
* @param string $className
|
|
|
748 |
* @param string $message
|
|
|
749 |
* @since Method available since Release 3.1.0
|
|
|
750 |
*/
|
|
|
751 |
public static function assertClassHasAttribute($attributeName, $className, $message = '')
|
|
|
752 |
{
|
|
|
753 |
if (!is_string($attributeName)) {
|
|
|
754 |
throw PHPUnit_Util_InvalidArgumentHelper::factory(1, 'string');
|
|
|
755 |
}
|
|
|
756 |
|
|
|
757 |
if (!is_string($className) || !class_exists($className, FALSE)) {
|
|
|
758 |
throw PHPUnit_Util_InvalidArgumentHelper::factory(2, 'class name');
|
|
|
759 |
}
|
|
|
760 |
|
|
|
761 |
$constraint = new PHPUnit_Framework_Constraint_ClassHasAttribute(
|
|
|
762 |
$attributeName
|
|
|
763 |
);
|
|
|
764 |
|
|
|
765 |
self::assertThat($className, $constraint, $message);
|
|
|
766 |
}
|
|
|
767 |
|
|
|
768 |
/**
|
|
|
769 |
* Asserts that a class does not have a specified attribute.
|
|
|
770 |
*
|
|
|
771 |
* @param string $attributeName
|
|
|
772 |
* @param string $className
|
|
|
773 |
* @param string $message
|
|
|
774 |
* @since Method available since Release 3.1.0
|
|
|
775 |
*/
|
|
|
776 |
public static function assertClassNotHasAttribute($attributeName, $className, $message = '')
|
|
|
777 |
{
|
|
|
778 |
if (!is_string($attributeName)) {
|
|
|
779 |
throw PHPUnit_Util_InvalidArgumentHelper::factory(1, 'string');
|
|
|
780 |
}
|
|
|
781 |
|
|
|
782 |
if (!is_string($className) || !class_exists($className, FALSE)) {
|
|
|
783 |
throw PHPUnit_Util_InvalidArgumentHelper::factory(2, 'class name');
|
|
|
784 |
}
|
|
|
785 |
|
|
|
786 |
$constraint = new PHPUnit_Framework_Constraint_Not(
|
|
|
787 |
new PHPUnit_Framework_Constraint_ClassHasAttribute($attributeName)
|
|
|
788 |
);
|
|
|
789 |
|
|
|
790 |
self::assertThat($className, $constraint, $message);
|
|
|
791 |
}
|
|
|
792 |
|
|
|
793 |
/**
|
|
|
794 |
* Asserts that a class has a specified static attribute.
|
|
|
795 |
*
|
|
|
796 |
* @param string $attributeName
|
|
|
797 |
* @param string $className
|
|
|
798 |
* @param string $message
|
|
|
799 |
* @since Method available since Release 3.1.0
|
|
|
800 |
*/
|
|
|
801 |
public static function assertClassHasStaticAttribute($attributeName, $className, $message = '')
|
|
|
802 |
{
|
|
|
803 |
if (!is_string($attributeName)) {
|
|
|
804 |
throw PHPUnit_Util_InvalidArgumentHelper::factory(1, 'string');
|
|
|
805 |
}
|
|
|
806 |
|
|
|
807 |
if (!is_string($className) || !class_exists($className, FALSE)) {
|
|
|
808 |
throw PHPUnit_Util_InvalidArgumentHelper::factory(2, 'class name');
|
|
|
809 |
}
|
|
|
810 |
|
|
|
811 |
$constraint = new PHPUnit_Framework_Constraint_ClassHasStaticAttribute(
|
|
|
812 |
$attributeName
|
|
|
813 |
);
|
|
|
814 |
|
|
|
815 |
self::assertThat($className, $constraint, $message);
|
|
|
816 |
}
|
|
|
817 |
|
|
|
818 |
/**
|
|
|
819 |
* Asserts that a class does not have a specified static attribute.
|
|
|
820 |
*
|
|
|
821 |
* @param string $attributeName
|
|
|
822 |
* @param string $className
|
|
|
823 |
* @param string $message
|
|
|
824 |
* @since Method available since Release 3.1.0
|
|
|
825 |
*/
|
|
|
826 |
public static function assertClassNotHasStaticAttribute($attributeName, $className, $message = '')
|
|
|
827 |
{
|
|
|
828 |
if (!is_string($attributeName)) {
|
|
|
829 |
throw PHPUnit_Util_InvalidArgumentHelper::factory(1, 'string');
|
|
|
830 |
}
|
|
|
831 |
|
|
|
832 |
if (!is_string($className) || !class_exists($className, FALSE)) {
|
|
|
833 |
throw PHPUnit_Util_InvalidArgumentHelper::factory(2, 'class name');
|
|
|
834 |
}
|
|
|
835 |
|
|
|
836 |
$constraint = new PHPUnit_Framework_Constraint_Not(
|
|
|
837 |
new PHPUnit_Framework_Constraint_ClassHasStaticAttribute(
|
|
|
838 |
$attributeName
|
|
|
839 |
)
|
|
|
840 |
);
|
|
|
841 |
|
|
|
842 |
self::assertThat($className, $constraint, $message);
|
|
|
843 |
}
|
|
|
844 |
|
|
|
845 |
/**
|
|
|
846 |
* Asserts that an object has a specified attribute.
|
|
|
847 |
*
|
|
|
848 |
* @param string $attributeName
|
|
|
849 |
* @param object $object
|
|
|
850 |
* @param string $message
|
|
|
851 |
* @since Method available since Release 3.0.0
|
|
|
852 |
*/
|
|
|
853 |
public static function assertObjectHasAttribute($attributeName, $object, $message = '')
|
|
|
854 |
{
|
|
|
855 |
if (!is_string($attributeName)) {
|
|
|
856 |
throw PHPUnit_Util_InvalidArgumentHelper::factory(1, 'string');
|
|
|
857 |
}
|
|
|
858 |
|
|
|
859 |
if (!is_object($object)) {
|
|
|
860 |
throw PHPUnit_Util_InvalidArgumentHelper::factory(2, 'object');
|
|
|
861 |
}
|
|
|
862 |
|
|
|
863 |
$constraint = new PHPUnit_Framework_Constraint_ObjectHasAttribute(
|
|
|
864 |
$attributeName
|
|
|
865 |
);
|
|
|
866 |
|
|
|
867 |
self::assertThat($object, $constraint, $message);
|
|
|
868 |
}
|
|
|
869 |
|
|
|
870 |
/**
|
|
|
871 |
* Asserts that an object does not have a specified attribute.
|
|
|
872 |
*
|
|
|
873 |
* @param string $attributeName
|
|
|
874 |
* @param object $object
|
|
|
875 |
* @param string $message
|
|
|
876 |
* @since Method available since Release 3.0.0
|
|
|
877 |
*/
|
|
|
878 |
public static function assertObjectNotHasAttribute($attributeName, $object, $message = '')
|
|
|
879 |
{
|
|
|
880 |
if (!is_string($attributeName)) {
|
|
|
881 |
throw PHPUnit_Util_InvalidArgumentHelper::factory(1, 'string');
|
|
|
882 |
}
|
|
|
883 |
|
|
|
884 |
if (!is_object($object)) {
|
|
|
885 |
throw PHPUnit_Util_InvalidArgumentHelper::factory(2, 'object');
|
|
|
886 |
}
|
|
|
887 |
|
|
|
888 |
$constraint = new PHPUnit_Framework_Constraint_Not(
|
|
|
889 |
new PHPUnit_Framework_Constraint_ObjectHasAttribute($attributeName)
|
|
|
890 |
);
|
|
|
891 |
|
|
|
892 |
self::assertThat($object, $constraint, $message);
|
|
|
893 |
}
|
|
|
894 |
|
|
|
895 |
/**
|
|
|
896 |
* Asserts that two variables have the same type and value.
|
|
|
897 |
* Used on objects, it asserts that two variables reference
|
|
|
898 |
* the same object.
|
|
|
899 |
*
|
|
|
900 |
* @param mixed $expected
|
|
|
901 |
* @param mixed $actual
|
|
|
902 |
* @param string $message
|
|
|
903 |
*/
|
|
|
904 |
public static function assertSame($expected, $actual, $message = '')
|
|
|
905 |
{
|
|
|
906 |
if (is_bool($expected) && is_bool($actual)) {
|
|
|
907 |
self::assertEquals($expected, $actual, $message);
|
|
|
908 |
} else {
|
|
|
909 |
$constraint = new PHPUnit_Framework_Constraint_IsIdentical(
|
|
|
910 |
$expected
|
|
|
911 |
);
|
|
|
912 |
|
|
|
913 |
self::assertThat($actual, $constraint, $message);
|
|
|
914 |
}
|
|
|
915 |
}
|
|
|
916 |
|
|
|
917 |
/**
|
|
|
918 |
* Asserts that a variable and an attribute of an object have the same type
|
|
|
919 |
* and value.
|
|
|
920 |
*
|
|
|
921 |
* @param mixed $expected
|
|
|
922 |
* @param string $actualAttributeName
|
|
|
923 |
* @param object $actualClassOrObject
|
|
|
924 |
* @param string $message
|
|
|
925 |
*/
|
|
|
926 |
public static function assertAttributeSame($expected, $actualAttributeName, $actualClassOrObject, $message = '')
|
|
|
927 |
{
|
|
|
928 |
self::assertSame(
|
|
|
929 |
$expected,
|
|
|
930 |
self::readAttribute($actualClassOrObject, $actualAttributeName),
|
|
|
931 |
$message
|
|
|
932 |
);
|
|
|
933 |
}
|
|
|
934 |
|
|
|
935 |
/**
|
|
|
936 |
* Asserts that two variables do not have the same type and value.
|
|
|
937 |
* Used on objects, it asserts that two variables do not reference
|
|
|
938 |
* the same object.
|
|
|
939 |
*
|
|
|
940 |
* @param mixed $expected
|
|
|
941 |
* @param mixed $actual
|
|
|
942 |
* @param string $message
|
|
|
943 |
*/
|
|
|
944 |
public static function assertNotSame($expected, $actual, $message = '')
|
|
|
945 |
{
|
|
|
946 |
if (is_bool($expected) && is_bool($actual)) {
|
|
|
947 |
self::assertNotEquals($expected, $actual, $message);
|
|
|
948 |
} else {
|
|
|
949 |
$constraint = new PHPUnit_Framework_Constraint_Not(
|
|
|
950 |
new PHPUnit_Framework_Constraint_IsIdentical($expected)
|
|
|
951 |
);
|
|
|
952 |
|
|
|
953 |
self::assertThat($actual, $constraint, $message);
|
|
|
954 |
}
|
|
|
955 |
}
|
|
|
956 |
|
|
|
957 |
/**
|
|
|
958 |
* Asserts that a variable and an attribute of an object do not have the
|
|
|
959 |
* same type and value.
|
|
|
960 |
*
|
|
|
961 |
* @param mixed $expected
|
|
|
962 |
* @param string $actualAttributeName
|
|
|
963 |
* @param object $actualClassOrObject
|
|
|
964 |
* @param string $message
|
|
|
965 |
*/
|
|
|
966 |
public static function assertAttributeNotSame($expected, $actualAttributeName, $actualClassOrObject, $message = '')
|
|
|
967 |
{
|
|
|
968 |
self::assertNotSame(
|
|
|
969 |
$expected,
|
|
|
970 |
self::readAttribute($actualClassOrObject, $actualAttributeName),
|
|
|
971 |
$message
|
|
|
972 |
);
|
|
|
973 |
}
|
|
|
974 |
|
|
|
975 |
/**
|
|
|
976 |
* Asserts that a variable is of a given type.
|
|
|
977 |
*
|
|
|
978 |
* @param string $expected
|
|
|
979 |
* @param mixed $actual
|
|
|
980 |
* @param string $message
|
|
|
981 |
*/
|
|
|
982 |
public static function assertType($expected, $actual, $message = '')
|
|
|
983 |
{
|
|
|
984 |
if (is_string($expected)) {
|
|
|
985 |
if (PHPUnit_Util_Type::isType($expected)) {
|
|
|
986 |
$constraint = new PHPUnit_Framework_Constraint_IsType(
|
|
|
987 |
$expected
|
|
|
988 |
);
|
|
|
989 |
}
|
|
|
990 |
|
|
|
991 |
else if (class_exists($expected) || interface_exists($expected)) {
|
|
|
992 |
$constraint = new PHPUnit_Framework_Constraint_IsInstanceOf(
|
|
|
993 |
$expected
|
|
|
994 |
);
|
|
|
995 |
}
|
|
|
996 |
|
|
|
997 |
else {
|
|
|
998 |
throw PHPUnit_Util_InvalidArgumentHelper::factory(
|
|
|
999 |
1, 'class or interface name'
|
|
|
1000 |
);
|
|
|
1001 |
}
|
|
|
1002 |
} else {
|
|
|
1003 |
throw PHPUnit_Util_InvalidArgumentHelper::factory(1, 'string');
|
|
|
1004 |
}
|
|
|
1005 |
|
|
|
1006 |
self::assertThat($actual, $constraint, $message);
|
|
|
1007 |
}
|
|
|
1008 |
|
|
|
1009 |
/**
|
|
|
1010 |
* Asserts that an attribute is of a given type.
|
|
|
1011 |
*
|
|
|
1012 |
* @param string $expected
|
|
|
1013 |
* @param string $attributeName
|
|
|
1014 |
* @param mixed $classOrObject
|
|
|
1015 |
* @param string $message
|
|
|
1016 |
* @since Method available since Release 3.4.0
|
|
|
1017 |
*/
|
|
|
1018 |
public static function assertAttributeType($expected, $attributeName, $classOrObject, $message = '')
|
|
|
1019 |
{
|
|
|
1020 |
self::assertType(
|
|
|
1021 |
$expected,
|
|
|
1022 |
self::readAttribute($classOrObject, $attributeName),
|
|
|
1023 |
$message
|
|
|
1024 |
);
|
|
|
1025 |
}
|
|
|
1026 |
|
|
|
1027 |
/**
|
|
|
1028 |
* Asserts that a variable is not of a given type.
|
|
|
1029 |
*
|
|
|
1030 |
* @param string $expected
|
|
|
1031 |
* @param mixed $actual
|
|
|
1032 |
* @param string $message
|
|
|
1033 |
* @since Method available since Release 2.2.0
|
|
|
1034 |
*/
|
|
|
1035 |
public static function assertNotType($expected, $actual, $message = '')
|
|
|
1036 |
{
|
|
|
1037 |
if (is_string($expected)) {
|
|
|
1038 |
if (PHPUnit_Util_Type::isType($expected)) {
|
|
|
1039 |
$constraint = new PHPUnit_Framework_Constraint_Not(
|
|
|
1040 |
new PHPUnit_Framework_Constraint_IsType($expected)
|
|
|
1041 |
);
|
|
|
1042 |
}
|
|
|
1043 |
|
|
|
1044 |
else if (class_exists($expected) || interface_exists($expected)) {
|
|
|
1045 |
$constraint = new PHPUnit_Framework_Constraint_Not(
|
|
|
1046 |
new PHPUnit_Framework_Constraint_IsInstanceOf($expected)
|
|
|
1047 |
);
|
|
|
1048 |
}
|
|
|
1049 |
|
|
|
1050 |
else {
|
|
|
1051 |
throw PHPUnit_Util_InvalidArgumentHelper::factory(
|
|
|
1052 |
1, 'class or interface name'
|
|
|
1053 |
);
|
|
|
1054 |
}
|
|
|
1055 |
} else {
|
|
|
1056 |
throw PHPUnit_Util_InvalidArgumentHelper::factory(1, 'string');
|
|
|
1057 |
}
|
|
|
1058 |
|
|
|
1059 |
self::assertThat($actual, $constraint, $message);
|
|
|
1060 |
}
|
|
|
1061 |
|
|
|
1062 |
/**
|
|
|
1063 |
* Asserts that an attribute is of a given type.
|
|
|
1064 |
*
|
|
|
1065 |
* @param string $expected
|
|
|
1066 |
* @param string $attributeName
|
|
|
1067 |
* @param mixed $classOrObject
|
|
|
1068 |
* @param string $message
|
|
|
1069 |
* @since Method available since Release 3.4.0
|
|
|
1070 |
*/
|
|
|
1071 |
public static function assertAttributeNotType($expected, $attributeName, $classOrObject, $message = '')
|
|
|
1072 |
{
|
|
|
1073 |
self::assertNotType(
|
|
|
1074 |
$expected,
|
|
|
1075 |
self::readAttribute($classOrObject, $attributeName),
|
|
|
1076 |
$message
|
|
|
1077 |
);
|
|
|
1078 |
}
|
|
|
1079 |
|
|
|
1080 |
/**
|
|
|
1081 |
* Asserts that a string matches a given regular expression.
|
|
|
1082 |
*
|
|
|
1083 |
* @param string $pattern
|
|
|
1084 |
* @param string $string
|
|
|
1085 |
* @param string $message
|
|
|
1086 |
*/
|
|
|
1087 |
public static function assertRegExp($pattern, $string, $message = '')
|
|
|
1088 |
{
|
|
|
1089 |
if (!is_string($pattern)) {
|
|
|
1090 |
throw PHPUnit_Util_InvalidArgumentHelper::factory(1, 'string');
|
|
|
1091 |
}
|
|
|
1092 |
|
|
|
1093 |
if (!is_string($string)) {
|
|
|
1094 |
throw PHPUnit_Util_InvalidArgumentHelper::factory(2, 'string');
|
|
|
1095 |
}
|
|
|
1096 |
|
|
|
1097 |
$constraint = new PHPUnit_Framework_Constraint_PCREMatch($pattern);
|
|
|
1098 |
|
|
|
1099 |
self::assertThat($string, $constraint, $message);
|
|
|
1100 |
}
|
|
|
1101 |
|
|
|
1102 |
/**
|
|
|
1103 |
* Asserts that a string does not match a given regular expression.
|
|
|
1104 |
*
|
|
|
1105 |
* @param string $pattern
|
|
|
1106 |
* @param string $string
|
|
|
1107 |
* @param string $message
|
|
|
1108 |
* @since Method available since Release 2.1.0
|
|
|
1109 |
*/
|
|
|
1110 |
public static function assertNotRegExp($pattern, $string, $message = '')
|
|
|
1111 |
{
|
|
|
1112 |
if (!is_string($pattern)) {
|
|
|
1113 |
throw PHPUnit_Util_InvalidArgumentHelper::factory(1, 'string');
|
|
|
1114 |
}
|
|
|
1115 |
|
|
|
1116 |
if (!is_string($string)) {
|
|
|
1117 |
throw PHPUnit_Util_InvalidArgumentHelper::factory(2, 'string');
|
|
|
1118 |
}
|
|
|
1119 |
|
|
|
1120 |
$constraint = new PHPUnit_Framework_Constraint_Not(
|
|
|
1121 |
new PHPUnit_Framework_Constraint_PCREMatch($pattern)
|
|
|
1122 |
);
|
|
|
1123 |
|
|
|
1124 |
self::assertThat($string, $constraint, $message);
|
|
|
1125 |
}
|
|
|
1126 |
|
|
|
1127 |
/**
|
|
|
1128 |
* Asserts that a string starts with a given prefix.
|
|
|
1129 |
*
|
|
|
1130 |
* @param string $prefix
|
|
|
1131 |
* @param string $string
|
|
|
1132 |
* @param string $message
|
|
|
1133 |
* @since Method available since Release 3.4.0
|
|
|
1134 |
*/
|
|
|
1135 |
public static function assertStringStartsWith($prefix, $string, $message = '')
|
|
|
1136 |
{
|
|
|
1137 |
if (!is_string($prefix)) {
|
|
|
1138 |
throw PHPUnit_Util_InvalidArgumentHelper::factory(1, 'string');
|
|
|
1139 |
}
|
|
|
1140 |
|
|
|
1141 |
if (!is_string($string)) {
|
|
|
1142 |
throw PHPUnit_Util_InvalidArgumentHelper::factory(2, 'string');
|
|
|
1143 |
}
|
|
|
1144 |
|
|
|
1145 |
$constraint = new PHPUnit_Framework_Constraint_StringStartsWith(
|
|
|
1146 |
$prefix
|
|
|
1147 |
);
|
|
|
1148 |
|
|
|
1149 |
self::assertThat($string, $constraint, $message);
|
|
|
1150 |
}
|
|
|
1151 |
|
|
|
1152 |
/**
|
|
|
1153 |
* Asserts that a string starts not with a given prefix.
|
|
|
1154 |
*
|
|
|
1155 |
* @param string $prefix
|
|
|
1156 |
* @param string $string
|
|
|
1157 |
* @param string $message
|
|
|
1158 |
* @since Method available since Release 3.4.0
|
|
|
1159 |
*/
|
|
|
1160 |
public static function assertStringStartsNotWith($prefix, $string, $message = '')
|
|
|
1161 |
{
|
|
|
1162 |
if (!is_string($prefix)) {
|
|
|
1163 |
throw PHPUnit_Util_InvalidArgumentHelper::factory(1, 'string');
|
|
|
1164 |
}
|
|
|
1165 |
|
|
|
1166 |
if (!is_string($string)) {
|
|
|
1167 |
throw PHPUnit_Util_InvalidArgumentHelper::factory(2, 'string');
|
|
|
1168 |
}
|
|
|
1169 |
|
|
|
1170 |
$constraint = new PHPUnit_Framework_Constraint_Not(
|
|
|
1171 |
new PHPUnit_Framework_Constraint_StringStartsWith($prefix)
|
|
|
1172 |
);
|
|
|
1173 |
|
|
|
1174 |
self::assertThat($string, $constraint, $message);
|
|
|
1175 |
}
|
|
|
1176 |
|
|
|
1177 |
/**
|
|
|
1178 |
* Asserts that a string ends with a given prefix.
|
|
|
1179 |
*
|
|
|
1180 |
* @param string $suffix
|
|
|
1181 |
* @param string $string
|
|
|
1182 |
* @param string $message
|
|
|
1183 |
* @since Method available since Release 3.4.0
|
|
|
1184 |
*/
|
|
|
1185 |
public static function assertStringEndsWith($suffix, $string, $message = '')
|
|
|
1186 |
{
|
|
|
1187 |
if (!is_string($suffix)) {
|
|
|
1188 |
throw PHPUnit_Util_InvalidArgumentHelper::factory(1, 'string');
|
|
|
1189 |
}
|
|
|
1190 |
|
|
|
1191 |
if (!is_string($string)) {
|
|
|
1192 |
throw PHPUnit_Util_InvalidArgumentHelper::factory(2, 'string');
|
|
|
1193 |
}
|
|
|
1194 |
|
|
|
1195 |
$constraint = new PHPUnit_Framework_Constraint_StringEndsWith($suffix);
|
|
|
1196 |
|
|
|
1197 |
self::assertThat($string, $constraint, $message);
|
|
|
1198 |
}
|
|
|
1199 |
|
|
|
1200 |
/**
|
|
|
1201 |
* Asserts that a string ends not with a given prefix.
|
|
|
1202 |
*
|
|
|
1203 |
* @param string $suffix
|
|
|
1204 |
* @param string $string
|
|
|
1205 |
* @param string $message
|
|
|
1206 |
* @since Method available since Release 3.4.0
|
|
|
1207 |
*/
|
|
|
1208 |
public static function assertStringEndsNotWith($suffix, $string, $message = '')
|
|
|
1209 |
{
|
|
|
1210 |
if (!is_string($suffix)) {
|
|
|
1211 |
throw PHPUnit_Util_InvalidArgumentHelper::factory(1, 'string');
|
|
|
1212 |
}
|
|
|
1213 |
|
|
|
1214 |
if (!is_string($string)) {
|
|
|
1215 |
throw PHPUnit_Util_InvalidArgumentHelper::factory(2, 'string');
|
|
|
1216 |
}
|
|
|
1217 |
|
|
|
1218 |
$constraint = new PHPUnit_Framework_Constraint_Not(
|
|
|
1219 |
new PHPUnit_Framework_Constraint_StringEndsWith($suffix)
|
|
|
1220 |
);
|
|
|
1221 |
|
|
|
1222 |
self::assertThat($string, $constraint, $message);
|
|
|
1223 |
}
|
|
|
1224 |
|
|
|
1225 |
/**
|
|
|
1226 |
* Asserts that two XML files are equal.
|
|
|
1227 |
*
|
|
|
1228 |
* @param string $expectedFile
|
|
|
1229 |
* @param string $actualFile
|
|
|
1230 |
* @param string $message
|
|
|
1231 |
* @since Method available since Release 3.1.0
|
|
|
1232 |
*/
|
|
|
1233 |
public static function assertXmlFileEqualsXmlFile($expectedFile, $actualFile, $message = '')
|
|
|
1234 |
{
|
|
|
1235 |
self::assertFileExists($expectedFile);
|
|
|
1236 |
self::assertFileExists($actualFile);
|
|
|
1237 |
|
|
|
1238 |
$expected = new DOMDocument;
|
|
|
1239 |
$expected->preserveWhiteSpace = FALSE;
|
|
|
1240 |
$expected->load($expectedFile);
|
|
|
1241 |
|
|
|
1242 |
$actual = new DOMDocument;
|
|
|
1243 |
$actual->preserveWhiteSpace = FALSE;
|
|
|
1244 |
$actual->load($actualFile);
|
|
|
1245 |
|
|
|
1246 |
self::assertEquals($expected, $actual, $message);
|
|
|
1247 |
}
|
|
|
1248 |
|
|
|
1249 |
/**
|
|
|
1250 |
* Asserts that two XML files are not equal.
|
|
|
1251 |
*
|
|
|
1252 |
* @param string $expectedFile
|
|
|
1253 |
* @param string $actualFile
|
|
|
1254 |
* @param string $message
|
|
|
1255 |
* @since Method available since Release 3.1.0
|
|
|
1256 |
*/
|
|
|
1257 |
public static function assertXmlFileNotEqualsXmlFile($expectedFile, $actualFile, $message = '')
|
|
|
1258 |
{
|
|
|
1259 |
self::assertFileExists($expectedFile);
|
|
|
1260 |
self::assertFileExists($actualFile);
|
|
|
1261 |
|
|
|
1262 |
$expected = new DOMDocument;
|
|
|
1263 |
$expected->preserveWhiteSpace = FALSE;
|
|
|
1264 |
$expected->load($expectedFile);
|
|
|
1265 |
|
|
|
1266 |
$actual = new DOMDocument;
|
|
|
1267 |
$actual->preserveWhiteSpace = FALSE;
|
|
|
1268 |
$actual->load($actualFile);
|
|
|
1269 |
|
|
|
1270 |
self::assertNotEquals($expected, $actual, $message);
|
|
|
1271 |
}
|
|
|
1272 |
|
|
|
1273 |
/**
|
|
|
1274 |
* Asserts that two XML documents are equal.
|
|
|
1275 |
*
|
|
|
1276 |
* @param string $expectedFile
|
|
|
1277 |
* @param string $actualXml
|
|
|
1278 |
* @param string $message
|
|
|
1279 |
* @since Method available since Release 3.3.0
|
|
|
1280 |
*/
|
|
|
1281 |
public static function assertXmlStringEqualsXmlFile($expectedFile, $actualXml, $message = '')
|
|
|
1282 |
{
|
|
|
1283 |
self::assertFileExists($expectedFile);
|
|
|
1284 |
|
|
|
1285 |
$expected = new DOMDocument;
|
|
|
1286 |
$expected->preserveWhiteSpace = FALSE;
|
|
|
1287 |
$expected->load($expectedFile);
|
|
|
1288 |
|
|
|
1289 |
$actual = new DOMDocument;
|
|
|
1290 |
$actual->preserveWhiteSpace = FALSE;
|
|
|
1291 |
$actual->loadXML($actualXml);
|
|
|
1292 |
|
|
|
1293 |
self::assertEquals($expected, $actual, $message);
|
|
|
1294 |
}
|
|
|
1295 |
|
|
|
1296 |
/**
|
|
|
1297 |
* Asserts that two XML documents are not equal.
|
|
|
1298 |
*
|
|
|
1299 |
* @param string $expectedFile
|
|
|
1300 |
* @param string $actualXml
|
|
|
1301 |
* @param string $message
|
|
|
1302 |
* @since Method available since Release 3.3.0
|
|
|
1303 |
*/
|
|
|
1304 |
public static function assertXmlStringNotEqualsXmlFile($expectedFile, $actualXml, $message = '')
|
|
|
1305 |
{
|
|
|
1306 |
self::assertFileExists($expectedFile);
|
|
|
1307 |
|
|
|
1308 |
$expected = new DOMDocument;
|
|
|
1309 |
$expected->preserveWhiteSpace = FALSE;
|
|
|
1310 |
$expected->load($expectedFile);
|
|
|
1311 |
|
|
|
1312 |
$actual = new DOMDocument;
|
|
|
1313 |
$actual->preserveWhiteSpace = FALSE;
|
|
|
1314 |
$actual->loadXML($actualXml);
|
|
|
1315 |
|
|
|
1316 |
self::assertNotEquals($expected, $actual, $message);
|
|
|
1317 |
}
|
|
|
1318 |
|
|
|
1319 |
/**
|
|
|
1320 |
* Asserts that two XML documents are equal.
|
|
|
1321 |
*
|
|
|
1322 |
* @param string $expectedXml
|
|
|
1323 |
* @param string $actualXml
|
|
|
1324 |
* @param string $message
|
|
|
1325 |
* @since Method available since Release 3.1.0
|
|
|
1326 |
*/
|
|
|
1327 |
public static function assertXmlStringEqualsXmlString($expectedXml, $actualXml, $message = '')
|
|
|
1328 |
{
|
|
|
1329 |
$expected = new DOMDocument;
|
|
|
1330 |
$expected->preserveWhiteSpace = FALSE;
|
|
|
1331 |
$expected->loadXML($expectedXml);
|
|
|
1332 |
|
|
|
1333 |
$actual = new DOMDocument;
|
|
|
1334 |
$actual->preserveWhiteSpace = FALSE;
|
|
|
1335 |
$actual->loadXML($actualXml);
|
|
|
1336 |
|
|
|
1337 |
self::assertEquals($expected, $actual, $message);
|
|
|
1338 |
}
|
|
|
1339 |
|
|
|
1340 |
/**
|
|
|
1341 |
* Asserts that two XML documents are not equal.
|
|
|
1342 |
*
|
|
|
1343 |
* @param string $expectedXml
|
|
|
1344 |
* @param string $actualXml
|
|
|
1345 |
* @param string $message
|
|
|
1346 |
* @since Method available since Release 3.1.0
|
|
|
1347 |
*/
|
|
|
1348 |
public static function assertXmlStringNotEqualsXmlString($expectedXml, $actualXml, $message = '')
|
|
|
1349 |
{
|
|
|
1350 |
$expected = new DOMDocument;
|
|
|
1351 |
$expected->preserveWhiteSpace = FALSE;
|
|
|
1352 |
$expected->loadXML($expectedXml);
|
|
|
1353 |
|
|
|
1354 |
$actual = new DOMDocument;
|
|
|
1355 |
$actual->preserveWhiteSpace = FALSE;
|
|
|
1356 |
$actual->loadXML($actualXml);
|
|
|
1357 |
|
|
|
1358 |
self::assertNotEquals($expected, $actual, $message);
|
|
|
1359 |
}
|
|
|
1360 |
|
|
|
1361 |
/**
|
|
|
1362 |
* Asserts that a hierarchy of DOMNodes matches.
|
|
|
1363 |
*
|
|
|
1364 |
* @param DOMNode $expectedNode
|
|
|
1365 |
* @param DOMNode $actualNode
|
|
|
1366 |
* @param boolean $checkAttributes
|
|
|
1367 |
* @param string $message
|
|
|
1368 |
* @author Mattis Stordalen Flister <mattis@xait.no>
|
|
|
1369 |
* @since Method available since Release 3.3.0
|
|
|
1370 |
*/
|
|
|
1371 |
public static function assertEqualXMLStructure(DOMNode $expectedNode, DOMNode $actualNode, $checkAttributes = FALSE, $message = '')
|
|
|
1372 |
{
|
|
|
1373 |
self::assertEquals(
|
|
|
1374 |
$expectedNode->tagName,
|
|
|
1375 |
$actualNode->tagName,
|
|
|
1376 |
$message
|
|
|
1377 |
);
|
|
|
1378 |
|
|
|
1379 |
if ($checkAttributes) {
|
|
|
1380 |
self::assertEquals(
|
|
|
1381 |
$expectedNode->attributes->length,
|
|
|
1382 |
$actualNode->attributes->length,
|
|
|
1383 |
sprintf(
|
|
|
1384 |
'%s%sNumber of attributes on node "%s" does not match',
|
|
|
1385 |
$message,
|
|
|
1386 |
!empty($message) ? "\n" : '',
|
|
|
1387 |
$expectedNode->tagName
|
|
|
1388 |
)
|
|
|
1389 |
);
|
|
|
1390 |
|
|
|
1391 |
for ($i = 0 ; $i < $expectedNode->attributes->length; $i++) {
|
|
|
1392 |
$expectedAttribute = $expectedNode->attributes->item($i);
|
|
|
1393 |
$actualAttribute = $actualNode->attributes->getNamedItem(
|
|
|
1394 |
$expectedAttribute->name
|
|
|
1395 |
);
|
|
|
1396 |
|
|
|
1397 |
if (!$actualAttribute) {
|
|
|
1398 |
self::fail(
|
|
|
1399 |
sprintf(
|
|
|
1400 |
'%s%sCould not find attribute "%s" on node "%s"',
|
|
|
1401 |
$message,
|
|
|
1402 |
!empty($message) ? "\n" : '',
|
|
|
1403 |
$expectedAttribute->name,
|
|
|
1404 |
$expectedNode->tagName
|
|
|
1405 |
)
|
|
|
1406 |
);
|
|
|
1407 |
}
|
|
|
1408 |
}
|
|
|
1409 |
}
|
|
|
1410 |
|
|
|
1411 |
PHPUnit_Util_XML::removeCharacterDataNodes($expectedNode);
|
|
|
1412 |
PHPUnit_Util_XML::removeCharacterDataNodes($actualNode);
|
|
|
1413 |
|
|
|
1414 |
self::assertEquals(
|
|
|
1415 |
$expectedNode->childNodes->length,
|
|
|
1416 |
$actualNode->childNodes->length,
|
|
|
1417 |
sprintf(
|
|
|
1418 |
'%s%sNumber of child nodes of "%s" differs',
|
|
|
1419 |
$message,
|
|
|
1420 |
!empty($message) ? "\n" : '',
|
|
|
1421 |
$expectedNode->tagName
|
|
|
1422 |
)
|
|
|
1423 |
);
|
|
|
1424 |
|
|
|
1425 |
for ($i = 0; $i < $expectedNode->childNodes->length; $i++) {
|
|
|
1426 |
self::assertEqualXMLStructure(
|
|
|
1427 |
$expectedNode->childNodes->item($i),
|
|
|
1428 |
$actualNode->childNodes->item($i),
|
|
|
1429 |
$checkAttributes,
|
|
|
1430 |
$message
|
|
|
1431 |
);
|
|
|
1432 |
}
|
|
|
1433 |
}
|
|
|
1434 |
|
|
|
1435 |
/**
|
|
|
1436 |
* Assert the presence, absence, or count of elements in a document matching
|
|
|
1437 |
* the CSS $selector, regardless of the contents of those elements.
|
|
|
1438 |
*
|
|
|
1439 |
* The first argument, $selector, is the CSS selector used to match
|
|
|
1440 |
* the elements in the $actual document.
|
|
|
1441 |
*
|
|
|
1442 |
* The second argument, $count, can be either boolean or numeric.
|
|
|
1443 |
* When boolean, it asserts for presence of elements matching the selector
|
|
|
1444 |
* (TRUE) or absence of elements (FALSE).
|
|
|
1445 |
* When numeric, it asserts the count of elements.
|
|
|
1446 |
*
|
|
|
1447 |
* assertSelectCount("#binder", true, $xml); // any?
|
|
|
1448 |
* assertSelectCount(".binder", 3, $xml); // exactly 3?
|
|
|
1449 |
*
|
|
|
1450 |
* @param array $selector
|
|
|
1451 |
* @param integer $count
|
|
|
1452 |
* @param mixed $actual
|
|
|
1453 |
* @param string $message
|
|
|
1454 |
* @param boolean $isHtml
|
|
|
1455 |
* @since Method available since Release 3.3.0
|
|
|
1456 |
* @author Mike Naberezny <mike@maintainable.com>
|
|
|
1457 |
* @author Derek DeVries <derek@maintainable.com>
|
|
|
1458 |
*/
|
|
|
1459 |
public static function assertSelectCount($selector, $count, $actual, $message = '', $isHtml = TRUE)
|
|
|
1460 |
{
|
|
|
1461 |
self::assertSelectEquals(
|
|
|
1462 |
$selector, TRUE, $count, $actual, $message, $isHtml
|
|
|
1463 |
);
|
|
|
1464 |
}
|
|
|
1465 |
|
|
|
1466 |
/**
|
|
|
1467 |
* assertSelectRegExp("#binder .name", "/Mike|Derek/", true, $xml); // any?
|
|
|
1468 |
* assertSelectRegExp("#binder .name", "/Mike|Derek/", 3, $xml); // 3?
|
|
|
1469 |
*
|
|
|
1470 |
* @param array $selector
|
|
|
1471 |
* @param string $pattern
|
|
|
1472 |
* @param integer $count
|
|
|
1473 |
* @param mixed $actual
|
|
|
1474 |
* @param string $message
|
|
|
1475 |
* @param boolean $isHtml
|
|
|
1476 |
* @since Method available since Release 3.3.0
|
|
|
1477 |
* @author Mike Naberezny <mike@maintainable.com>
|
|
|
1478 |
* @author Derek DeVries <derek@maintainable.com>
|
|
|
1479 |
*/
|
|
|
1480 |
public static function assertSelectRegExp($selector, $pattern, $count, $actual, $message = '', $isHtml = TRUE)
|
|
|
1481 |
{
|
|
|
1482 |
self::assertSelectEquals(
|
|
|
1483 |
$selector, "regexp:$pattern", $count, $actual, $message, $isHtml
|
|
|
1484 |
);
|
|
|
1485 |
}
|
|
|
1486 |
|
|
|
1487 |
/**
|
|
|
1488 |
* assertSelectEquals("#binder .name", "Chuck", true, $xml); // any?
|
|
|
1489 |
* assertSelectEquals("#binder .name", "Chuck", false, $xml); // none?
|
|
|
1490 |
*
|
|
|
1491 |
* @param array $selector
|
|
|
1492 |
* @param string $content
|
|
|
1493 |
* @param integer $count
|
|
|
1494 |
* @param mixed $actual
|
|
|
1495 |
* @param string $message
|
|
|
1496 |
* @param boolean $isHtml
|
|
|
1497 |
* @since Method available since Release 3.3.0
|
|
|
1498 |
* @author Mike Naberezny <mike@maintainable.com>
|
|
|
1499 |
* @author Derek DeVries <derek@maintainable.com>
|
|
|
1500 |
*/
|
|
|
1501 |
public static function assertSelectEquals($selector, $content, $count, $actual, $message = '', $isHtml = TRUE)
|
|
|
1502 |
{
|
|
|
1503 |
$tags = PHPUnit_Util_XML::cssSelect(
|
|
|
1504 |
$selector, $content, $actual, $isHtml
|
|
|
1505 |
);
|
|
|
1506 |
|
|
|
1507 |
// assert specific number of elements
|
|
|
1508 |
if (is_numeric($count)) {
|
|
|
1509 |
$counted = $tags ? count($tags) : 0;
|
|
|
1510 |
self::assertEquals($count, $counted);
|
|
|
1511 |
}
|
|
|
1512 |
|
|
|
1513 |
// assert any elements exist if true, assert no elements exist if false
|
|
|
1514 |
else if (is_bool($count)) {
|
|
|
1515 |
$any = count($tags) > 0 && $tags[0] instanceof DOMNode;
|
|
|
1516 |
|
|
|
1517 |
if ($count) {
|
|
|
1518 |
self::assertTrue($any, $message);
|
|
|
1519 |
} else {
|
|
|
1520 |
self::assertFalse($any, $message);
|
|
|
1521 |
}
|
|
|
1522 |
}
|
|
|
1523 |
|
|
|
1524 |
// check for range number of elements
|
|
|
1525 |
else if (is_array($count) &&
|
|
|
1526 |
(isset($count['>']) || isset($count['<']) ||
|
|
|
1527 |
isset($count['>=']) || isset($count['<=']))) {
|
|
|
1528 |
$counted = $tags ? count($tags) : 0;
|
|
|
1529 |
|
|
|
1530 |
if (isset($count['>'])) {
|
|
|
1531 |
self::assertTrue($counted > $count['>'], $message);
|
|
|
1532 |
}
|
|
|
1533 |
|
|
|
1534 |
if (isset($count['>='])) {
|
|
|
1535 |
self::assertTrue($counted >= $count['>='], $message);
|
|
|
1536 |
}
|
|
|
1537 |
|
|
|
1538 |
if (isset($count['<'])) {
|
|
|
1539 |
self::assertTrue($counted < $count['<'], $message);
|
|
|
1540 |
}
|
|
|
1541 |
|
|
|
1542 |
if (isset($count['<='])) {
|
|
|
1543 |
self::assertTrue($counted <= $count['<='], $message);
|
|
|
1544 |
}
|
|
|
1545 |
} else {
|
|
|
1546 |
throw new InvalidArgumentException();
|
|
|
1547 |
}
|
|
|
1548 |
}
|
|
|
1549 |
|
|
|
1550 |
/**
|
|
|
1551 |
* Evaluate an HTML or XML string and assert its structure and/or contents.
|
|
|
1552 |
*
|
|
|
1553 |
* The first argument ($matcher) is an associative array that specifies the
|
|
|
1554 |
* match criteria for the assertion:
|
|
|
1555 |
*
|
|
|
1556 |
* - `id` : the node with the given id attribute must match the
|
|
|
1557 |
* corresponsing value.
|
|
|
1558 |
* - `tag` : the node type must match the corresponding value.
|
|
|
1559 |
* - `attributes` : a hash. The node's attributres must match the
|
|
|
1560 |
* corresponsing values in the hash.
|
|
|
1561 |
* - `content` : The text content must match the given value.
|
|
|
1562 |
* - `parent` : a hash. The node's parent must match the
|
|
|
1563 |
* corresponsing hash.
|
|
|
1564 |
* - `child` : a hash. At least one of the node's immediate children
|
|
|
1565 |
* must meet the criteria described by the hash.
|
|
|
1566 |
* - `ancestor` : a hash. At least one of the node's ancestors must
|
|
|
1567 |
* meet the criteria described by the hash.
|
|
|
1568 |
* - `descendant` : a hash. At least one of the node's descendants must
|
|
|
1569 |
* meet the criteria described by the hash.
|
|
|
1570 |
* - `children` : a hash, for counting children of a node.
|
|
|
1571 |
* Accepts the keys:
|
|
|
1572 |
* - `count` : a number which must equal the number of children
|
|
|
1573 |
* that match
|
|
|
1574 |
* - `less_than` : the number of matching children must be greater
|
|
|
1575 |
* than this number
|
|
|
1576 |
* - `greater_than` : the number of matching children must be less than
|
|
|
1577 |
* this number
|
|
|
1578 |
* - `only` : another hash consisting of the keys to use to match
|
|
|
1579 |
* on the children, and only matching children will be
|
|
|
1580 |
* counted
|
|
|
1581 |
*
|
|
|
1582 |
* <code>
|
|
|
1583 |
* // Matcher that asserts that there is an element with an id="my_id".
|
|
|
1584 |
* $matcher = array('id' => 'my_id');
|
|
|
1585 |
*
|
|
|
1586 |
* // Matcher that asserts that there is a "span" tag.
|
|
|
1587 |
* $matcher = array('tag' => 'span');
|
|
|
1588 |
*
|
|
|
1589 |
* // Matcher that asserts that there is a "span" tag with the content
|
|
|
1590 |
* // "Hello World".
|
|
|
1591 |
* $matcher = array('tag' => 'span', 'content' => 'Hello World');
|
|
|
1592 |
*
|
|
|
1593 |
* // Matcher that asserts that there is a "span" tag with content matching
|
|
|
1594 |
* // the regular expression pattern.
|
|
|
1595 |
* $matcher = array('tag' => 'span', 'content' => '/Try P(HP|ython)/');
|
|
|
1596 |
*
|
|
|
1597 |
* // Matcher that asserts that there is a "span" with an "list" class
|
|
|
1598 |
* // attribute.
|
|
|
1599 |
* $matcher = array(
|
|
|
1600 |
* 'tag' => 'span',
|
|
|
1601 |
* 'attributes' => array('class' => 'list')
|
|
|
1602 |
* );
|
|
|
1603 |
*
|
|
|
1604 |
* // Matcher that asserts that there is a "span" inside of a "div".
|
|
|
1605 |
* $matcher = array(
|
|
|
1606 |
* 'tag' => 'span',
|
|
|
1607 |
* 'parent' => array('tag' => 'div')
|
|
|
1608 |
* );
|
|
|
1609 |
*
|
|
|
1610 |
* // Matcher that asserts that there is a "span" somewhere inside a
|
|
|
1611 |
* // "table".
|
|
|
1612 |
* $matcher = array(
|
|
|
1613 |
* 'tag' => 'span',
|
|
|
1614 |
* 'ancestor' => array('tag' => 'table')
|
|
|
1615 |
* );
|
|
|
1616 |
*
|
|
|
1617 |
* // Matcher that asserts that there is a "span" with at least one "em"
|
|
|
1618 |
* // child.
|
|
|
1619 |
* $matcher = array(
|
|
|
1620 |
* 'tag' => 'span',
|
|
|
1621 |
* 'child' => array('tag' => 'em')
|
|
|
1622 |
* );
|
|
|
1623 |
*
|
|
|
1624 |
* // Matcher that asserts that there is a "span" containing a (possibly
|
|
|
1625 |
* // nested) "strong" tag.
|
|
|
1626 |
* $matcher = array(
|
|
|
1627 |
* 'tag' => 'span',
|
|
|
1628 |
* 'descendant' => array('tag' => 'strong')
|
|
|
1629 |
* );
|
|
|
1630 |
*
|
|
|
1631 |
* // Matcher that asserts that there is a "span" containing 5-10 "em" tags
|
|
|
1632 |
* // as immediate children.
|
|
|
1633 |
* $matcher = array(
|
|
|
1634 |
* 'tag' => 'span',
|
|
|
1635 |
* 'children' => array(
|
|
|
1636 |
* 'less_than' => 11,
|
|
|
1637 |
* 'greater_than' => 4,
|
|
|
1638 |
* 'only' => array('tag' => 'em')
|
|
|
1639 |
* )
|
|
|
1640 |
* );
|
|
|
1641 |
*
|
|
|
1642 |
* // Matcher that asserts that there is a "div", with an "ul" ancestor and
|
|
|
1643 |
* // a "li" parent (with class="enum"), and containing a "span" descendant
|
|
|
1644 |
* // that contains an element with id="my_test" and the text "Hello World".
|
|
|
1645 |
* $matcher = array(
|
|
|
1646 |
* 'tag' => 'div',
|
|
|
1647 |
* 'ancestor' => array('tag' => 'ul'),
|
|
|
1648 |
* 'parent' => array(
|
|
|
1649 |
* 'tag' => 'li',
|
|
|
1650 |
* 'attributes' => array('class' => 'enum')
|
|
|
1651 |
* ),
|
|
|
1652 |
* 'descendant' => array(
|
|
|
1653 |
* 'tag' => 'span',
|
|
|
1654 |
* 'child' => array(
|
|
|
1655 |
* 'id' => 'my_test',
|
|
|
1656 |
* 'content' => 'Hello World'
|
|
|
1657 |
* )
|
|
|
1658 |
* )
|
|
|
1659 |
* );
|
|
|
1660 |
*
|
|
|
1661 |
* // Use assertTag() to apply a $matcher to a piece of $html.
|
|
|
1662 |
* $this->assertTag($matcher, $html);
|
|
|
1663 |
*
|
|
|
1664 |
* // Use assertTag() to apply a $matcher to a piece of $xml.
|
|
|
1665 |
* $this->assertTag($matcher, $xml, '', FALSE);
|
|
|
1666 |
* </code>
|
|
|
1667 |
*
|
|
|
1668 |
* The second argument ($actual) is a string containing either HTML or
|
|
|
1669 |
* XML text to be tested.
|
|
|
1670 |
*
|
|
|
1671 |
* The third argument ($message) is an optional message that will be
|
|
|
1672 |
* used if the assertion fails.
|
|
|
1673 |
*
|
|
|
1674 |
* The fourth argument ($html) is an optional flag specifying whether
|
|
|
1675 |
* to load the $actual string into a DOMDocument using the HTML or
|
|
|
1676 |
* XML load strategy. It is TRUE by default, which assumes the HTML
|
|
|
1677 |
* load strategy. In many cases, this will be acceptable for XML as well.
|
|
|
1678 |
*
|
|
|
1679 |
* @param array $matcher
|
|
|
1680 |
* @param string $actual
|
|
|
1681 |
* @param string $message
|
|
|
1682 |
* @param boolean $isHtml
|
|
|
1683 |
* @since Method available since Release 3.3.0
|
|
|
1684 |
* @author Mike Naberezny <mike@maintainable.com>
|
|
|
1685 |
* @author Derek DeVries <derek@maintainable.com>
|
|
|
1686 |
*/
|
|
|
1687 |
public static function assertTag($matcher, $actual, $message = '', $isHtml = TRUE)
|
|
|
1688 |
{
|
|
|
1689 |
$dom = PHPUnit_Util_XML::load($actual, $isHtml);
|
|
|
1690 |
$tags = PHPUnit_Util_XML::findNodes($dom, $matcher, $isHtml);
|
|
|
1691 |
$matched = count($tags) > 0 && $tags[0] instanceof DOMNode;
|
|
|
1692 |
|
|
|
1693 |
self::assertTrue($matched, $message);
|
|
|
1694 |
}
|
|
|
1695 |
|
|
|
1696 |
/**
|
|
|
1697 |
* This assertion is the exact opposite of assertTag().
|
|
|
1698 |
*
|
|
|
1699 |
* Rather than asserting that $matcher results in a match, it asserts that
|
|
|
1700 |
* $matcher does not match.
|
|
|
1701 |
*
|
|
|
1702 |
* @param array $matcher
|
|
|
1703 |
* @param string $actual
|
|
|
1704 |
* @param string $message
|
|
|
1705 |
* @param boolean $isHtml
|
|
|
1706 |
* @since Method available since Release 3.3.0
|
|
|
1707 |
* @author Mike Naberezny <mike@maintainable.com>
|
|
|
1708 |
* @author Derek DeVries <derek@maintainable.com>
|
|
|
1709 |
*/
|
|
|
1710 |
public static function assertNotTag($matcher, $actual, $message = '', $isHtml = TRUE)
|
|
|
1711 |
{
|
|
|
1712 |
$dom = PHPUnit_Util_XML::load($actual, $isHtml);
|
|
|
1713 |
$tags = PHPUnit_Util_XML::findNodes($dom, $matcher, $isHtml);
|
|
|
1714 |
$matched = count($tags) > 0 && $tags[0] instanceof DOMNode;
|
|
|
1715 |
|
|
|
1716 |
self::assertFalse($matched, $message);
|
|
|
1717 |
}
|
|
|
1718 |
|
|
|
1719 |
/**
|
|
|
1720 |
* Evaluates a PHPUnit_Framework_Constraint matcher object.
|
|
|
1721 |
*
|
|
|
1722 |
* @param mixed $value
|
|
|
1723 |
* @param PHPUnit_Framework_Constraint $constraint
|
|
|
1724 |
* @param string $message
|
|
|
1725 |
* @since Method available since Release 3.0.0
|
|
|
1726 |
*/
|
|
|
1727 |
public static function assertThat($value, PHPUnit_Framework_Constraint $constraint, $message = '')
|
|
|
1728 |
{
|
|
|
1729 |
self::$count += count($constraint);
|
|
|
1730 |
|
|
|
1731 |
if (!$constraint->evaluate($value)) {
|
|
|
1732 |
$constraint->fail($value, $message);
|
|
|
1733 |
}
|
|
|
1734 |
}
|
|
|
1735 |
|
|
|
1736 |
/**
|
|
|
1737 |
* Returns a PHPUnit_Framework_Constraint_And matcher object.
|
|
|
1738 |
*
|
|
|
1739 |
* @return PHPUnit_Framework_Constraint_And
|
|
|
1740 |
* @since Method available since Release 3.0.0
|
|
|
1741 |
*/
|
|
|
1742 |
public static function logicalAnd()
|
|
|
1743 |
{
|
|
|
1744 |
$constraints = func_get_args();
|
|
|
1745 |
|
|
|
1746 |
$constraint = new PHPUnit_Framework_Constraint_And;
|
|
|
1747 |
$constraint->setConstraints($constraints);
|
|
|
1748 |
|
|
|
1749 |
return $constraint;
|
|
|
1750 |
}
|
|
|
1751 |
|
|
|
1752 |
/**
|
|
|
1753 |
* Returns a PHPUnit_Framework_Constraint_Or matcher object.
|
|
|
1754 |
*
|
|
|
1755 |
* @return PHPUnit_Framework_Constraint_Or
|
|
|
1756 |
* @since Method available since Release 3.0.0
|
|
|
1757 |
*/
|
|
|
1758 |
public static function logicalOr()
|
|
|
1759 |
{
|
|
|
1760 |
$constraints = func_get_args();
|
|
|
1761 |
|
|
|
1762 |
$constraint = new PHPUnit_Framework_Constraint_Or;
|
|
|
1763 |
$constraint->setConstraints($constraints);
|
|
|
1764 |
|
|
|
1765 |
return $constraint;
|
|
|
1766 |
}
|
|
|
1767 |
|
|
|
1768 |
/**
|
|
|
1769 |
* Returns a PHPUnit_Framework_Constraint_Not matcher object.
|
|
|
1770 |
*
|
|
|
1771 |
* @param PHPUnit_Framework_Constraint $constraint
|
|
|
1772 |
* @return PHPUnit_Framework_Constraint_Not
|
|
|
1773 |
* @since Method available since Release 3.0.0
|
|
|
1774 |
*/
|
|
|
1775 |
public static function logicalNot(PHPUnit_Framework_Constraint $constraint)
|
|
|
1776 |
{
|
|
|
1777 |
return new PHPUnit_Framework_Constraint_Not($constraint);
|
|
|
1778 |
}
|
|
|
1779 |
|
|
|
1780 |
/**
|
|
|
1781 |
* Returns a PHPUnit_Framework_Constraint_Xor matcher object.
|
|
|
1782 |
*
|
|
|
1783 |
* @return PHPUnit_Framework_Constraint_Xor
|
|
|
1784 |
* @since Method available since Release 3.0.0
|
|
|
1785 |
*/
|
|
|
1786 |
public static function logicalXor()
|
|
|
1787 |
{
|
|
|
1788 |
$constraints = func_get_args();
|
|
|
1789 |
|
|
|
1790 |
$constraint = new PHPUnit_Framework_Constraint_Xor;
|
|
|
1791 |
$constraint->setConstraints($constraints);
|
|
|
1792 |
|
|
|
1793 |
return $constraint;
|
|
|
1794 |
}
|
|
|
1795 |
|
|
|
1796 |
/**
|
|
|
1797 |
* Returns a PHPUnit_Framework_Constraint_IsAnything matcher object.
|
|
|
1798 |
*
|
|
|
1799 |
* @return PHPUnit_Framework_Constraint_IsAnything
|
|
|
1800 |
* @since Method available since Release 3.0.0
|
|
|
1801 |
*/
|
|
|
1802 |
public static function anything()
|
|
|
1803 |
{
|
|
|
1804 |
return new PHPUnit_Framework_Constraint_IsAnything;
|
|
|
1805 |
}
|
|
|
1806 |
|
|
|
1807 |
/**
|
|
|
1808 |
* Returns a PHPUnit_Framework_Constraint_IsTrue matcher object.
|
|
|
1809 |
*
|
|
|
1810 |
* @return PHPUnit_Framework_Constraint_IsTrue
|
|
|
1811 |
* @since Method available since Release 3.3.0
|
|
|
1812 |
*/
|
|
|
1813 |
public static function isTrue()
|
|
|
1814 |
{
|
|
|
1815 |
return new PHPUnit_Framework_Constraint_IsTrue;
|
|
|
1816 |
}
|
|
|
1817 |
|
|
|
1818 |
/**
|
|
|
1819 |
* Returns a PHPUnit_Framework_Constraint_IsFalse matcher object.
|
|
|
1820 |
*
|
|
|
1821 |
* @return PHPUnit_Framework_Constraint_IsFalse
|
|
|
1822 |
* @since Method available since Release 3.3.0
|
|
|
1823 |
*/
|
|
|
1824 |
public static function isFalse()
|
|
|
1825 |
{
|
|
|
1826 |
return new PHPUnit_Framework_Constraint_IsFalse;
|
|
|
1827 |
}
|
|
|
1828 |
|
|
|
1829 |
/**
|
|
|
1830 |
* Returns a PHPUnit_Framework_Constraint_IsNull matcher object.
|
|
|
1831 |
*
|
|
|
1832 |
* @return PHPUnit_Framework_Constraint_IsNull
|
|
|
1833 |
* @since Method available since Release 3.3.0
|
|
|
1834 |
*/
|
|
|
1835 |
public static function isNull()
|
|
|
1836 |
{
|
|
|
1837 |
return new PHPUnit_Framework_Constraint_IsNull;
|
|
|
1838 |
}
|
|
|
1839 |
|
|
|
1840 |
/**
|
|
|
1841 |
* Returns a PHPUnit_Framework_Constraint_Attribute matcher object.
|
|
|
1842 |
*
|
|
|
1843 |
* @param PHPUnit_Framework_Constraint $constraint
|
|
|
1844 |
* @param string $attributeName
|
|
|
1845 |
* @return PHPUnit_Framework_Constraint_Attribute
|
|
|
1846 |
* @since Method available since Release 3.1.0
|
|
|
1847 |
*/
|
|
|
1848 |
public static function attribute(PHPUnit_Framework_Constraint $constraint, $attributeName)
|
|
|
1849 |
{
|
|
|
1850 |
return new PHPUnit_Framework_Constraint_Attribute(
|
|
|
1851 |
$constraint, $attributeName
|
|
|
1852 |
);
|
|
|
1853 |
}
|
|
|
1854 |
|
|
|
1855 |
/**
|
|
|
1856 |
* Returns a PHPUnit_Framework_Constraint_TraversableContains matcher
|
|
|
1857 |
* object.
|
|
|
1858 |
*
|
|
|
1859 |
* @param mixed $value
|
|
|
1860 |
* @return PHPUnit_Framework_Constraint_TraversableContains
|
|
|
1861 |
* @since Method available since Release 3.0.0
|
|
|
1862 |
*/
|
|
|
1863 |
public static function contains($value)
|
|
|
1864 |
{
|
|
|
1865 |
return new PHPUnit_Framework_Constraint_TraversableContains($value);
|
|
|
1866 |
}
|
|
|
1867 |
|
|
|
1868 |
/**
|
|
|
1869 |
* Returns a PHPUnit_Framework_Constraint_TraversableContainsOnly matcher
|
|
|
1870 |
* object.
|
|
|
1871 |
*
|
|
|
1872 |
* @param string $type
|
|
|
1873 |
* @return PHPUnit_Framework_Constraint_TraversableContainsOnly
|
|
|
1874 |
* @since Method available since Release 3.1.4
|
|
|
1875 |
*/
|
|
|
1876 |
public static function containsOnly($type)
|
|
|
1877 |
{
|
|
|
1878 |
return new PHPUnit_Framework_Constraint_TraversableContainsOnly($type);
|
|
|
1879 |
}
|
|
|
1880 |
|
|
|
1881 |
/**
|
|
|
1882 |
* Returns a PHPUnit_Framework_Constraint_ArrayHasKey matcher object.
|
|
|
1883 |
*
|
|
|
1884 |
* @param mixed $key
|
|
|
1885 |
* @return PHPUnit_Framework_Constraint_ArrayHasKey
|
|
|
1886 |
* @since Method available since Release 3.0.0
|
|
|
1887 |
*/
|
|
|
1888 |
public static function arrayHasKey($key)
|
|
|
1889 |
{
|
|
|
1890 |
return new PHPUnit_Framework_Constraint_ArrayHasKey($key);
|
|
|
1891 |
}
|
|
|
1892 |
|
|
|
1893 |
/**
|
|
|
1894 |
* Returns a PHPUnit_Framework_Constraint_IsEqual matcher object.
|
|
|
1895 |
*
|
|
|
1896 |
* @param mixed $value
|
|
|
1897 |
* @param float $delta
|
|
|
1898 |
* @param integer $maxDepth
|
|
|
1899 |
* @param boolean $canonicalizeEol
|
|
|
1900 |
* @param boolean $ignoreCase
|
|
|
1901 |
* @return PHPUnit_Framework_Constraint_IsEqual
|
|
|
1902 |
* @since Method available since Release 3.0.0
|
|
|
1903 |
*/
|
|
|
1904 |
public static function equalTo($value, $delta = 0, $maxDepth = 10, $canonicalizeEol = FALSE, $ignoreCase = FALSE)
|
|
|
1905 |
{
|
|
|
1906 |
return new PHPUnit_Framework_Constraint_IsEqual(
|
|
|
1907 |
$value, $delta, $maxDepth, $canonicalizeEol, $ignoreCase
|
|
|
1908 |
);
|
|
|
1909 |
}
|
|
|
1910 |
|
|
|
1911 |
/**
|
|
|
1912 |
* Returns a PHPUnit_Framework_Constraint_IsEqual matcher object
|
|
|
1913 |
* that is wrapped in a PHPUnit_Framework_Constraint_Attribute matcher
|
|
|
1914 |
* object.
|
|
|
1915 |
*
|
|
|
1916 |
* @param string $attributeName
|
|
|
1917 |
* @param mixed $value
|
|
|
1918 |
* @param float $delta
|
|
|
1919 |
* @param integer $maxDepth
|
|
|
1920 |
* @param boolean $canonicalizeEol
|
|
|
1921 |
* @param boolean $ignoreCase
|
|
|
1922 |
* @return PHPUnit_Framework_Constraint_Attribute
|
|
|
1923 |
* @since Method available since Release 3.1.0
|
|
|
1924 |
*/
|
|
|
1925 |
public static function attributeEqualTo($attributeName, $value, $delta = 0, $maxDepth = 10, $canonicalizeEol = FALSE, $ignoreCase = FALSE)
|
|
|
1926 |
{
|
|
|
1927 |
return self::attribute(
|
|
|
1928 |
self::equalTo(
|
|
|
1929 |
$value, $delta, $maxDepth, $canonicalizeEol, $ignoreCase
|
|
|
1930 |
),
|
|
|
1931 |
$attributeName
|
|
|
1932 |
);
|
|
|
1933 |
}
|
|
|
1934 |
|
|
|
1935 |
/**
|
|
|
1936 |
* Returns a PHPUnit_Framework_Constraint_FileExists matcher object.
|
|
|
1937 |
*
|
|
|
1938 |
* @return PHPUnit_Framework_Constraint_FileExists
|
|
|
1939 |
* @since Method available since Release 3.0.0
|
|
|
1940 |
*/
|
|
|
1941 |
public static function fileExists()
|
|
|
1942 |
{
|
|
|
1943 |
return new PHPUnit_Framework_Constraint_FileExists;
|
|
|
1944 |
}
|
|
|
1945 |
|
|
|
1946 |
/**
|
|
|
1947 |
* Returns a PHPUnit_Framework_Constraint_GreaterThan matcher object.
|
|
|
1948 |
*
|
|
|
1949 |
* @param mixed $value
|
|
|
1950 |
* @return PHPUnit_Framework_Constraint_GreaterThan
|
|
|
1951 |
* @since Method available since Release 3.0.0
|
|
|
1952 |
*/
|
|
|
1953 |
public static function greaterThan($value)
|
|
|
1954 |
{
|
|
|
1955 |
return new PHPUnit_Framework_Constraint_GreaterThan($value);
|
|
|
1956 |
}
|
|
|
1957 |
|
|
|
1958 |
/**
|
|
|
1959 |
* Returns a PHPUnit_Framework_Constraint_Or matcher object that wraps
|
|
|
1960 |
* a PHPUnit_Framework_Constraint_IsEqual and a
|
|
|
1961 |
* PHPUnit_Framework_Constraint_GreaterThan matcher object.
|
|
|
1962 |
*
|
|
|
1963 |
* @param mixed $value
|
|
|
1964 |
* @return PHPUnit_Framework_Constraint_Or
|
|
|
1965 |
* @since Method available since Release 3.1.0
|
|
|
1966 |
*/
|
|
|
1967 |
public static function greaterThanOrEqual($value)
|
|
|
1968 |
{
|
|
|
1969 |
return self::logicalOr(
|
|
|
1970 |
new PHPUnit_Framework_Constraint_IsEqual($value),
|
|
|
1971 |
new PHPUnit_Framework_Constraint_GreaterThan($value)
|
|
|
1972 |
);
|
|
|
1973 |
}
|
|
|
1974 |
|
|
|
1975 |
/**
|
|
|
1976 |
* Returns a PHPUnit_Framework_Constraint_ClassHasAttribute matcher object.
|
|
|
1977 |
*
|
|
|
1978 |
* @param string $attributeName
|
|
|
1979 |
* @return PHPUnit_Framework_Constraint_ClassHasAttribute
|
|
|
1980 |
* @since Method available since Release 3.1.0
|
|
|
1981 |
*/
|
|
|
1982 |
public static function classHasAttribute($attributeName)
|
|
|
1983 |
{
|
|
|
1984 |
return new PHPUnit_Framework_Constraint_ClassHasAttribute(
|
|
|
1985 |
$attributeName
|
|
|
1986 |
);
|
|
|
1987 |
}
|
|
|
1988 |
|
|
|
1989 |
/**
|
|
|
1990 |
* Returns a PHPUnit_Framework_Constraint_ClassHasStaticAttribute matcher
|
|
|
1991 |
* object.
|
|
|
1992 |
*
|
|
|
1993 |
* @param string $attributeName
|
|
|
1994 |
* @return PHPUnit_Framework_Constraint_ClassHasStaticAttribute
|
|
|
1995 |
* @since Method available since Release 3.1.0
|
|
|
1996 |
*/
|
|
|
1997 |
public static function classHasStaticAttribute($attributeName)
|
|
|
1998 |
{
|
|
|
1999 |
return new PHPUnit_Framework_Constraint_ClassHasStaticAttribute(
|
|
|
2000 |
$attributeName
|
|
|
2001 |
);
|
|
|
2002 |
}
|
|
|
2003 |
|
|
|
2004 |
/**
|
|
|
2005 |
* Returns a PHPUnit_Framework_Constraint_ObjectHasAttribute matcher object.
|
|
|
2006 |
*
|
|
|
2007 |
* @param string $attributeName
|
|
|
2008 |
* @return PHPUnit_Framework_Constraint_ObjectHasAttribute
|
|
|
2009 |
* @since Method available since Release 3.0.0
|
|
|
2010 |
*/
|
|
|
2011 |
public static function objectHasAttribute($attributeName)
|
|
|
2012 |
{
|
|
|
2013 |
return new PHPUnit_Framework_Constraint_ObjectHasAttribute(
|
|
|
2014 |
$attributeName
|
|
|
2015 |
);
|
|
|
2016 |
}
|
|
|
2017 |
|
|
|
2018 |
/**
|
|
|
2019 |
* Returns a PHPUnit_Framework_Constraint_IsIdentical matcher object.
|
|
|
2020 |
*
|
|
|
2021 |
* @param mixed $value
|
|
|
2022 |
* @return PHPUnit_Framework_Constraint_IsIdentical
|
|
|
2023 |
* @since Method available since Release 3.0.0
|
|
|
2024 |
*/
|
|
|
2025 |
public static function identicalTo($value)
|
|
|
2026 |
{
|
|
|
2027 |
return new PHPUnit_Framework_Constraint_IsIdentical($value);
|
|
|
2028 |
}
|
|
|
2029 |
|
|
|
2030 |
/**
|
|
|
2031 |
* Returns a PHPUnit_Framework_Constraint_IsInstanceOf matcher object.
|
|
|
2032 |
*
|
|
|
2033 |
* @param string $className
|
|
|
2034 |
* @return PHPUnit_Framework_Constraint_IsInstanceOf
|
|
|
2035 |
* @since Method available since Release 3.0.0
|
|
|
2036 |
*/
|
|
|
2037 |
public static function isInstanceOf($className)
|
|
|
2038 |
{
|
|
|
2039 |
return new PHPUnit_Framework_Constraint_IsInstanceOf($className);
|
|
|
2040 |
}
|
|
|
2041 |
|
|
|
2042 |
/**
|
|
|
2043 |
* Returns a PHPUnit_Framework_Constraint_IsType matcher object.
|
|
|
2044 |
*
|
|
|
2045 |
* @param string $type
|
|
|
2046 |
* @return PHPUnit_Framework_Constraint_IsType
|
|
|
2047 |
* @since Method available since Release 3.0.0
|
|
|
2048 |
*/
|
|
|
2049 |
public static function isType($type)
|
|
|
2050 |
{
|
|
|
2051 |
return new PHPUnit_Framework_Constraint_IsType($type);
|
|
|
2052 |
}
|
|
|
2053 |
|
|
|
2054 |
/**
|
|
|
2055 |
* Returns a PHPUnit_Framework_Constraint_LessThan matcher object.
|
|
|
2056 |
*
|
|
|
2057 |
* @param mixed $value
|
|
|
2058 |
* @return PHPUnit_Framework_Constraint_LessThan
|
|
|
2059 |
* @since Method available since Release 3.0.0
|
|
|
2060 |
*/
|
|
|
2061 |
public static function lessThan($value)
|
|
|
2062 |
{
|
|
|
2063 |
return new PHPUnit_Framework_Constraint_LessThan($value);
|
|
|
2064 |
}
|
|
|
2065 |
|
|
|
2066 |
/**
|
|
|
2067 |
* Returns a PHPUnit_Framework_Constraint_Or matcher object that wraps
|
|
|
2068 |
* a PHPUnit_Framework_Constraint_IsEqual and a
|
|
|
2069 |
* PHPUnit_Framework_Constraint_LessThan matcher object.
|
|
|
2070 |
*
|
|
|
2071 |
* @param mixed $value
|
|
|
2072 |
* @return PHPUnit_Framework_Constraint_Or
|
|
|
2073 |
* @since Method available since Release 3.1.0
|
|
|
2074 |
*/
|
|
|
2075 |
public static function lessThanOrEqual($value)
|
|
|
2076 |
{
|
|
|
2077 |
return self::logicalOr(
|
|
|
2078 |
new PHPUnit_Framework_Constraint_IsEqual($value),
|
|
|
2079 |
new PHPUnit_Framework_Constraint_LessThan($value)
|
|
|
2080 |
);
|
|
|
2081 |
}
|
|
|
2082 |
|
|
|
2083 |
/**
|
|
|
2084 |
* Returns a PHPUnit_Framework_Constraint_PCREMatch matcher object.
|
|
|
2085 |
*
|
|
|
2086 |
* @param string $pattern
|
|
|
2087 |
* @return PHPUnit_Framework_Constraint_PCREMatch
|
|
|
2088 |
* @since Method available since Release 3.0.0
|
|
|
2089 |
*/
|
|
|
2090 |
public static function matchesRegularExpression($pattern)
|
|
|
2091 |
{
|
|
|
2092 |
return new PHPUnit_Framework_Constraint_PCREMatch($pattern);
|
|
|
2093 |
}
|
|
|
2094 |
|
|
|
2095 |
/**
|
|
|
2096 |
* Returns a PHPUnit_Framework_Constraint_StringStartsWith matcher object.
|
|
|
2097 |
*
|
|
|
2098 |
* @param mixed $prefix
|
|
|
2099 |
* @return PHPUnit_Framework_Constraint_StringStartsWith
|
|
|
2100 |
* @since Method available since Release 3.4.0
|
|
|
2101 |
*/
|
|
|
2102 |
public static function stringStartsWith($prefix)
|
|
|
2103 |
{
|
|
|
2104 |
return new PHPUnit_Framework_Constraint_StringStartsWith($prefix);
|
|
|
2105 |
}
|
|
|
2106 |
|
|
|
2107 |
/**
|
|
|
2108 |
* Returns a PHPUnit_Framework_Constraint_StringContains matcher object.
|
|
|
2109 |
*
|
|
|
2110 |
* @param string $string
|
|
|
2111 |
* @param boolean $case
|
|
|
2112 |
* @return PHPUnit_Framework_Constraint_StringContains
|
|
|
2113 |
* @since Method available since Release 3.0.0
|
|
|
2114 |
*/
|
|
|
2115 |
public static function stringContains($string, $case = TRUE)
|
|
|
2116 |
{
|
|
|
2117 |
return new PHPUnit_Framework_Constraint_StringContains($string, $case);
|
|
|
2118 |
}
|
|
|
2119 |
|
|
|
2120 |
/**
|
|
|
2121 |
* Returns a PHPUnit_Framework_Constraint_StringEndsWith matcher object.
|
|
|
2122 |
*
|
|
|
2123 |
* @param mixed $suffix
|
|
|
2124 |
* @return PHPUnit_Framework_Constraint_StringEndsWith
|
|
|
2125 |
* @since Method available since Release 3.4.0
|
|
|
2126 |
*/
|
|
|
2127 |
public static function stringEndsWith($suffix)
|
|
|
2128 |
{
|
|
|
2129 |
return new PHPUnit_Framework_Constraint_StringEndsWith($suffix);
|
|
|
2130 |
}
|
|
|
2131 |
|
|
|
2132 |
/**
|
|
|
2133 |
* Fails a test with the given message.
|
|
|
2134 |
*
|
|
|
2135 |
* @param string $message
|
|
|
2136 |
* @throws PHPUnit_Framework_AssertionFailedError
|
|
|
2137 |
*/
|
|
|
2138 |
public static function fail($message = '')
|
|
|
2139 |
{
|
|
|
2140 |
throw new PHPUnit_Framework_AssertionFailedError($message);
|
|
|
2141 |
}
|
|
|
2142 |
|
|
|
2143 |
/**
|
|
|
2144 |
* Returns the value of an attribute of a class or an object.
|
|
|
2145 |
* This also works for attributes that are declared protected or private.
|
|
|
2146 |
*
|
|
|
2147 |
* @param mixed $classOrObject
|
|
|
2148 |
* @param string $attributeName
|
|
|
2149 |
* @return mixed
|
|
|
2150 |
* @throws InvalidArgumentException
|
|
|
2151 |
*/
|
|
|
2152 |
public static function readAttribute($classOrObject, $attributeName)
|
|
|
2153 |
{
|
|
|
2154 |
if (!is_string($attributeName)) {
|
|
|
2155 |
throw PHPUnit_Util_InvalidArgumentHelper::factory(2, 'string');
|
|
|
2156 |
}
|
|
|
2157 |
|
|
|
2158 |
if (is_string($classOrObject)) {
|
|
|
2159 |
if (!class_exists($classOrObject)) {
|
|
|
2160 |
throw PHPUnit_Util_InvalidArgumentHelper::factory(
|
|
|
2161 |
1, 'class name'
|
|
|
2162 |
);
|
|
|
2163 |
}
|
|
|
2164 |
|
|
|
2165 |
return PHPUnit_Util_Class::getStaticAttribute(
|
|
|
2166 |
$classOrObject,
|
|
|
2167 |
$attributeName
|
|
|
2168 |
);
|
|
|
2169 |
}
|
|
|
2170 |
|
|
|
2171 |
else if (is_object($classOrObject)) {
|
|
|
2172 |
return PHPUnit_Util_Class::getObjectAttribute(
|
|
|
2173 |
$classOrObject,
|
|
|
2174 |
$attributeName
|
|
|
2175 |
);
|
|
|
2176 |
}
|
|
|
2177 |
|
|
|
2178 |
else {
|
|
|
2179 |
throw PHPUnit_Util_InvalidArgumentHelper::factory(
|
|
|
2180 |
1, 'class name or object'
|
|
|
2181 |
);
|
|
|
2182 |
}
|
|
|
2183 |
}
|
|
|
2184 |
|
|
|
2185 |
/**
|
|
|
2186 |
* Mark the test as incomplete.
|
|
|
2187 |
*
|
|
|
2188 |
* @param string $message
|
|
|
2189 |
* @throws PHPUnit_Framework_IncompleteTestError
|
|
|
2190 |
* @since Method available since Release 3.0.0
|
|
|
2191 |
*/
|
|
|
2192 |
public static function markTestIncomplete($message = '')
|
|
|
2193 |
{
|
|
|
2194 |
throw new PHPUnit_Framework_IncompleteTestError($message);
|
|
|
2195 |
}
|
|
|
2196 |
|
|
|
2197 |
/**
|
|
|
2198 |
* Mark the test as skipped.
|
|
|
2199 |
*
|
|
|
2200 |
* @param string $message
|
|
|
2201 |
* @throws PHPUnit_Framework_SkippedTestError
|
|
|
2202 |
* @since Method available since Release 3.0.0
|
|
|
2203 |
*/
|
|
|
2204 |
public static function markTestSkipped($message = '')
|
|
|
2205 |
{
|
|
|
2206 |
throw new PHPUnit_Framework_SkippedTestError($message);
|
|
|
2207 |
}
|
|
|
2208 |
|
|
|
2209 |
/**
|
|
|
2210 |
* Return the current assertion count.
|
|
|
2211 |
*
|
|
|
2212 |
* @return integer
|
|
|
2213 |
* @since Method available since Release 3.3.3
|
|
|
2214 |
*/
|
|
|
2215 |
public static function getCount()
|
|
|
2216 |
{
|
|
|
2217 |
return self::$count;
|
|
|
2218 |
}
|
|
|
2219 |
|
|
|
2220 |
/**
|
|
|
2221 |
* Reset the assertion counter.
|
|
|
2222 |
*
|
|
|
2223 |
* @since Method available since Release 3.3.3
|
|
|
2224 |
*/
|
|
|
2225 |
public static function resetCount()
|
|
|
2226 |
{
|
|
|
2227 |
self::$count = 0;
|
|
|
2228 |
}
|
|
|
2229 |
}
|
|
|
2230 |
?>
|