5
* Copyright (c) 2002-2010, Sebastian Bergmann <sb@sebastian-bergmann.de>.
8
* Redistribution and use in source and binary forms, with or without
9
* modification, are permitted provided that the following conditions
12
* * Redistributions of source code must retain the above copyright
13
* notice, this list of conditions and the following disclaimer.
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
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.
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.
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
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';
52
PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT');
55
* A set of assert methods.
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.14
63
* @link http://www.phpunit.de/
64
* @since Class available since Release 2.0.0
66
abstract class PHPUnit_Framework_Assert
71
private static $count = 0;
74
* Asserts that an array has a specified key.
78
* @param string $message
79
* @since Method available since Release 3.0.0
81
public static function assertArrayHasKey($key, array $array, $message = '')
83
if (!(is_integer($key) || is_string($key))) {
84
throw PHPUnit_Util_InvalidArgumentHelper::factory(
85
1, 'integer or string'
89
$constraint = new PHPUnit_Framework_Constraint_ArrayHasKey($key);
91
self::assertThat($array, $constraint, $message);
95
* Asserts that an array does not have a specified key.
99
* @param string $message
100
* @since Method available since Release 3.0.0
102
public static function assertArrayNotHasKey($key, array $array, $message = '')
104
if (!(is_integer($key) || is_string($key))) {
105
throw PHPUnit_Util_InvalidArgumentHelper::factory(
106
1, 'integer or string'
110
$constraint = new PHPUnit_Framework_Constraint_Not(
111
new PHPUnit_Framework_Constraint_ArrayHasKey($key)
114
self::assertThat($array, $constraint, $message);
118
* Asserts that a haystack contains a needle.
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
126
public static function assertContains($needle, $haystack, $message = '', $ignoreCase = FALSE)
128
if (is_array($haystack) ||
129
is_object($haystack) && $haystack instanceof Traversable) {
130
$constraint = new PHPUnit_Framework_Constraint_TraversableContains(
135
else if (is_string($haystack)) {
136
$constraint = new PHPUnit_Framework_Constraint_StringContains(
142
throw PHPUnit_Util_InvalidArgumentHelper::factory(
143
2, 'array, iterator or string'
147
self::assertThat($haystack, $constraint, $message);
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.
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
161
public static function assertAttributeContains($needle, $haystackAttributeName, $haystackClassOrObject, $message = '', $ignoreCase = FALSE)
163
self::assertContains(
165
self::readAttribute($haystackClassOrObject, $haystackAttributeName),
172
* Asserts that a haystack does not contain a needle.
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
180
public static function assertNotContains($needle, $haystack, $message = '', $ignoreCase = FALSE)
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)
189
else if (is_string($haystack)) {
190
$constraint = new PHPUnit_Framework_Constraint_Not(
191
new PHPUnit_Framework_Constraint_StringContains(
198
throw PHPUnit_Util_InvalidArgumentHelper::factory(
199
2, 'array, iterator or string'
203
self::assertThat($haystack, $constraint, $message);
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.
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
217
public static function assertAttributeNotContains($needle, $haystackAttributeName, $haystackClassOrObject, $message = '', $ignoreCase = FALSE)
219
self::assertNotContains(
221
self::readAttribute($haystackClassOrObject, $haystackAttributeName),
228
* Asserts that a haystack contains only values of a given type.
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
236
public static function assertContainsOnly($type, $haystack, $isNativeType = NULL, $message = '')
238
if (!(is_array($haystack) ||
239
is_object($haystack) && $haystack instanceof Traversable)) {
240
throw PHPUnit_Util_InvalidArgumentHelper::factory(
241
2, 'array or iterator'
245
if ($isNativeType == NULL) {
246
$isNativeType = PHPUnit_Util_Type::isType($type);
251
new PHPUnit_Framework_Constraint_TraversableContainsOnly(
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.
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
269
public static function assertAttributeContainsOnly($type, $haystackAttributeName, $haystackClassOrObject, $isNativeType = NULL, $message = '')
271
self::assertContainsOnly(
273
self::readAttribute($haystackClassOrObject, $haystackAttributeName),
280
* Asserts that a haystack does not contain only values of a given type.
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
288
public static function assertNotContainsOnly($type, $haystack, $isNativeType = NULL, $message = '')
290
if (!(is_array($haystack) ||
291
is_object($haystack) && $haystack instanceof Traversable)) {
292
throw PHPUnit_Util_InvalidArgumentHelper::factory(
293
2, 'array or iterator'
297
if ($isNativeType == NULL) {
298
$isNativeType = PHPUnit_Util_Type::isType($type);
303
new PHPUnit_Framework_Constraint_Not(
304
new PHPUnit_Framework_Constraint_TraversableContainsOnly(
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
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
324
public static function assertAttributeNotContainsOnly($type, $haystackAttributeName, $haystackClassOrObject, $isNativeType = NULL, $message = '')
326
self::assertNotContainsOnly(
328
self::readAttribute($haystackClassOrObject, $haystackAttributeName),
335
* Asserts that two variables are equal.
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
345
public static function assertEquals($expected, $actual, $message = '', $delta = 0, $maxDepth = 10, $canonicalizeEol = FALSE, $ignoreCase = FALSE)
347
$constraint = new PHPUnit_Framework_Constraint_IsEqual(
348
$expected, $delta, $maxDepth, $canonicalizeEol, $ignoreCase
351
self::assertThat($actual, $constraint, $message);
355
* Asserts that a variable is equal to an attribute of an object.
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
366
public static function assertAttributeEquals($expected, $actualAttributeName, $actualClassOrObject, $message = '', $delta = 0, $maxDepth = 10, $canonicalizeEol = FALSE, $ignoreCase = FALSE)
370
self::readAttribute($actualClassOrObject, $actualAttributeName),
380
* Asserts that two variables are not equal.
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
391
public static function assertNotEquals($expected, $actual, $message = '', $delta = 0, $maxDepth = 10, $canonicalizeEol = FALSE, $ignoreCase = FALSE)
393
$constraint = new PHPUnit_Framework_Constraint_Not(
394
new PHPUnit_Framework_Constraint_IsEqual(
395
$expected, $delta, $maxDepth, $canonicalizeEol, $ignoreCase
399
self::assertThat($actual, $constraint, $message);
403
* Asserts that a variable is not equal to an attribute of an object.
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
414
public static function assertAttributeNotEquals($expected, $actualAttributeName, $actualClassOrObject, $message = '', $delta = 0, $maxDepth = 10, $canonicalizeEol = FALSE, $ignoreCase = FALSE)
416
self::assertNotEquals(
418
self::readAttribute($actualClassOrObject, $actualAttributeName),
428
* Asserts that a value is greater than another value.
430
* @param mixed $expected
431
* @param mixed $actual
432
* @param string $message
433
* @since Method available since Release 3.1.0
435
public static function assertGreaterThan($expected, $actual, $message = '')
437
self::assertThat($actual, self::greaterThan($expected), $message);
441
* Asserts that an attribute is greater than another value.
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
449
public static function assertAttributeGreaterThan($expected, $actualAttributeName, $actualClassOrObject, $message = '')
451
self::assertGreaterThan(
453
self::readAttribute($actualClassOrObject, $actualAttributeName),
459
* Asserts that a value is greater than or equal to another value.
461
* @param mixed $expected
462
* @param mixed $actual
463
* @param string $message
464
* @since Method available since Release 3.1.0
466
public static function assertGreaterThanOrEqual($expected, $actual, $message = '')
469
$actual, self::greaterThanOrEqual($expected), $message
474
* Asserts that an attribute is greater than or equal to another value.
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
482
public static function assertAttributeGreaterThanOrEqual($expected, $actualAttributeName, $actualClassOrObject, $message = '')
484
self::assertGreaterThanOrEqual(
486
self::readAttribute($actualClassOrObject, $actualAttributeName),
492
* Asserts that a value is smaller than another value.
494
* @param mixed $expected
495
* @param mixed $actual
496
* @param string $message
497
* @since Method available since Release 3.1.0
499
public static function assertLessThan($expected, $actual, $message = '')
501
self::assertThat($actual, self::lessThan($expected), $message);
505
* Asserts that an attribute is smaller than another value.
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
513
public static function assertAttributeLessThan($expected, $actualAttributeName, $actualClassOrObject, $message = '')
515
self::assertLessThan(
517
self::readAttribute($actualClassOrObject, $actualAttributeName),
523
* Asserts that a value is smaller than or equal to another value.
525
* @param mixed $expected
526
* @param mixed $actual
527
* @param string $message
528
* @since Method available since Release 3.1.0
530
public static function assertLessThanOrEqual($expected, $actual, $message = '')
532
self::assertThat($actual, self::lessThanOrEqual($expected), $message);
536
* Asserts that an attribute is smaller than or equal to another value.
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
544
public static function assertAttributeLessThanOrEqual($expected, $actualAttributeName, $actualClassOrObject, $message = '')
546
self::assertLessThanOrEqual(
548
self::readAttribute($actualClassOrObject, $actualAttributeName),
554
* Asserts that the contents of one file is equal to the contents of another
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
564
public static function assertFileEquals($expected, $actual, $message = '', $canonicalizeEol = FALSE, $ignoreCase = FALSE)
566
self::assertFileExists($expected, $message);
567
self::assertFileExists($actual, $message);
570
file_get_contents($expected),
571
file_get_contents($actual),
581
* Asserts that the contents of one file is not equal to the contents of
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
591
public static function assertFileNotEquals($expected, $actual, $message = '', $canonicalizeEol = FALSE, $ignoreCase = FALSE)
593
self::assertFileExists($expected, $message);
594
self::assertFileExists($actual, $message);
596
self::assertNotEquals(
597
file_get_contents($expected),
598
file_get_contents($actual),
608
* Asserts that the contents of a string is equal
609
* to the contents of a file.
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
618
public static function assertStringEqualsFile($expectedFile, $actualString, $message = '', $canonicalizeEol = FALSE, $ignoreCase = FALSE)
620
self::assertFileExists($expectedFile, $message);
623
file_get_contents($expectedFile),
634
* Asserts that the contents of a string is not equal
635
* to the contents of a file.
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
644
public static function assertStringNotEqualsFile($expectedFile, $actualString, $message = '', $canonicalizeEol = FALSE, $ignoreCase = FALSE)
646
self::assertFileExists($expectedFile, $message);
648
self::assertNotEquals(
649
file_get_contents($expectedFile),
660
* Asserts that a file exists.
662
* @param string $filename
663
* @param string $message
664
* @since Method available since Release 3.0.0
666
public static function assertFileExists($filename, $message = '')
668
if (!is_string($filename)) {
669
throw PHPUnit_Util_InvalidArgumentHelper::factory(1, 'string');
672
$constraint = new PHPUnit_Framework_Constraint_FileExists;
674
self::assertThat($filename, $constraint, $message);
678
* Asserts that a file does not exist.
680
* @param string $filename
681
* @param string $message
682
* @since Method available since Release 3.0.0
684
public static function assertFileNotExists($filename, $message = '')
686
if (!is_string($filename)) {
687
throw PHPUnit_Util_InvalidArgumentHelper::factory(1, 'string');
690
$constraint = new PHPUnit_Framework_Constraint_Not(
691
new PHPUnit_Framework_Constraint_FileExists
694
self::assertThat($filename, $constraint, $message);
698
* Asserts that a condition is true.
700
* @param boolean $condition
701
* @param string $message
702
* @throws PHPUnit_Framework_AssertionFailedError
704
public static function assertTrue($condition, $message = '')
706
self::assertThat($condition, self::isTrue(), $message);
710
* Asserts that a condition is false.
712
* @param boolean $condition
713
* @param string $message
714
* @throws PHPUnit_Framework_AssertionFailedError
716
public static function assertFalse($condition, $message = '')
718
self::assertThat($condition, self::isFalse(), $message);
722
* Asserts that a variable is not NULL.
724
* @param mixed $actual
725
* @param string $message
727
public static function assertNotNull($actual, $message = '')
729
self::assertThat($actual, self::logicalNot(self::isNull()), $message);
733
* Asserts that a variable is NULL.
735
* @param mixed $actual
736
* @param string $message
738
public static function assertNull($actual, $message = '')
740
self::assertThat($actual, self::isNull(), $message);
744
* Asserts that a class has a specified attribute.
746
* @param string $attributeName
747
* @param string $className
748
* @param string $message
749
* @since Method available since Release 3.1.0
751
public static function assertClassHasAttribute($attributeName, $className, $message = '')
753
if (!is_string($attributeName)) {
754
throw PHPUnit_Util_InvalidArgumentHelper::factory(1, 'string');
757
if (!is_string($className) || !class_exists($className, FALSE)) {
758
throw PHPUnit_Util_InvalidArgumentHelper::factory(2, 'class name');
761
$constraint = new PHPUnit_Framework_Constraint_ClassHasAttribute(
765
self::assertThat($className, $constraint, $message);
769
* Asserts that a class does not have a specified attribute.
771
* @param string $attributeName
772
* @param string $className
773
* @param string $message
774
* @since Method available since Release 3.1.0
776
public static function assertClassNotHasAttribute($attributeName, $className, $message = '')
778
if (!is_string($attributeName)) {
779
throw PHPUnit_Util_InvalidArgumentHelper::factory(1, 'string');
782
if (!is_string($className) || !class_exists($className, FALSE)) {
783
throw PHPUnit_Util_InvalidArgumentHelper::factory(2, 'class name');
786
$constraint = new PHPUnit_Framework_Constraint_Not(
787
new PHPUnit_Framework_Constraint_ClassHasAttribute($attributeName)
790
self::assertThat($className, $constraint, $message);
794
* Asserts that a class has a specified static attribute.
796
* @param string $attributeName
797
* @param string $className
798
* @param string $message
799
* @since Method available since Release 3.1.0
801
public static function assertClassHasStaticAttribute($attributeName, $className, $message = '')
803
if (!is_string($attributeName)) {
804
throw PHPUnit_Util_InvalidArgumentHelper::factory(1, 'string');
807
if (!is_string($className) || !class_exists($className, FALSE)) {
808
throw PHPUnit_Util_InvalidArgumentHelper::factory(2, 'class name');
811
$constraint = new PHPUnit_Framework_Constraint_ClassHasStaticAttribute(
815
self::assertThat($className, $constraint, $message);
819
* Asserts that a class does not have a specified static attribute.
821
* @param string $attributeName
822
* @param string $className
823
* @param string $message
824
* @since Method available since Release 3.1.0
826
public static function assertClassNotHasStaticAttribute($attributeName, $className, $message = '')
828
if (!is_string($attributeName)) {
829
throw PHPUnit_Util_InvalidArgumentHelper::factory(1, 'string');
832
if (!is_string($className) || !class_exists($className, FALSE)) {
833
throw PHPUnit_Util_InvalidArgumentHelper::factory(2, 'class name');
836
$constraint = new PHPUnit_Framework_Constraint_Not(
837
new PHPUnit_Framework_Constraint_ClassHasStaticAttribute(
842
self::assertThat($className, $constraint, $message);
846
* Asserts that an object has a specified attribute.
848
* @param string $attributeName
849
* @param object $object
850
* @param string $message
851
* @since Method available since Release 3.0.0
853
public static function assertObjectHasAttribute($attributeName, $object, $message = '')
855
if (!is_string($attributeName)) {
856
throw PHPUnit_Util_InvalidArgumentHelper::factory(1, 'string');
859
if (!is_object($object)) {
860
throw PHPUnit_Util_InvalidArgumentHelper::factory(2, 'object');
863
$constraint = new PHPUnit_Framework_Constraint_ObjectHasAttribute(
867
self::assertThat($object, $constraint, $message);
871
* Asserts that an object does not have a specified attribute.
873
* @param string $attributeName
874
* @param object $object
875
* @param string $message
876
* @since Method available since Release 3.0.0
878
public static function assertObjectNotHasAttribute($attributeName, $object, $message = '')
880
if (!is_string($attributeName)) {
881
throw PHPUnit_Util_InvalidArgumentHelper::factory(1, 'string');
884
if (!is_object($object)) {
885
throw PHPUnit_Util_InvalidArgumentHelper::factory(2, 'object');
888
$constraint = new PHPUnit_Framework_Constraint_Not(
889
new PHPUnit_Framework_Constraint_ObjectHasAttribute($attributeName)
892
self::assertThat($object, $constraint, $message);
896
* Asserts that two variables have the same type and value.
897
* Used on objects, it asserts that two variables reference
900
* @param mixed $expected
901
* @param mixed $actual
902
* @param string $message
904
public static function assertSame($expected, $actual, $message = '')
906
if (is_bool($expected) && is_bool($actual)) {
907
self::assertEquals($expected, $actual, $message);
909
$constraint = new PHPUnit_Framework_Constraint_IsIdentical(
913
self::assertThat($actual, $constraint, $message);
918
* Asserts that a variable and an attribute of an object have the same type
921
* @param mixed $expected
922
* @param string $actualAttributeName
923
* @param object $actualClassOrObject
924
* @param string $message
926
public static function assertAttributeSame($expected, $actualAttributeName, $actualClassOrObject, $message = '')
930
self::readAttribute($actualClassOrObject, $actualAttributeName),
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
940
* @param mixed $expected
941
* @param mixed $actual
942
* @param string $message
944
public static function assertNotSame($expected, $actual, $message = '')
946
if (is_bool($expected) && is_bool($actual)) {
947
self::assertNotEquals($expected, $actual, $message);
949
$constraint = new PHPUnit_Framework_Constraint_Not(
950
new PHPUnit_Framework_Constraint_IsIdentical($expected)
953
self::assertThat($actual, $constraint, $message);
958
* Asserts that a variable and an attribute of an object do not have the
959
* same type and value.
961
* @param mixed $expected
962
* @param string $actualAttributeName
963
* @param object $actualClassOrObject
964
* @param string $message
966
public static function assertAttributeNotSame($expected, $actualAttributeName, $actualClassOrObject, $message = '')
970
self::readAttribute($actualClassOrObject, $actualAttributeName),
976
* Asserts that a variable is of a given type.
978
* @param string $expected
979
* @param mixed $actual
980
* @param string $message
982
public static function assertType($expected, $actual, $message = '')
984
if (is_string($expected)) {
985
if (PHPUnit_Util_Type::isType($expected)) {
986
$constraint = new PHPUnit_Framework_Constraint_IsType(
991
else if (class_exists($expected) || interface_exists($expected)) {
992
$constraint = new PHPUnit_Framework_Constraint_IsInstanceOf(
998
throw PHPUnit_Util_InvalidArgumentHelper::factory(
999
1, 'class or interface name'
1003
throw PHPUnit_Util_InvalidArgumentHelper::factory(1, 'string');
1006
self::assertThat($actual, $constraint, $message);
1010
* Asserts that an attribute is of a given type.
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
1018
public static function assertAttributeType($expected, $attributeName, $classOrObject, $message = '')
1022
self::readAttribute($classOrObject, $attributeName),
1028
* Asserts that a variable is not of a given type.
1030
* @param string $expected
1031
* @param mixed $actual
1032
* @param string $message
1033
* @since Method available since Release 2.2.0
1035
public static function assertNotType($expected, $actual, $message = '')
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)
1044
else if (class_exists($expected) || interface_exists($expected)) {
1045
$constraint = new PHPUnit_Framework_Constraint_Not(
1046
new PHPUnit_Framework_Constraint_IsInstanceOf($expected)
1051
throw PHPUnit_Util_InvalidArgumentHelper::factory(
1052
1, 'class or interface name'
1056
throw PHPUnit_Util_InvalidArgumentHelper::factory(1, 'string');
1059
self::assertThat($actual, $constraint, $message);
1063
* Asserts that an attribute is of a given type.
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
1071
public static function assertAttributeNotType($expected, $attributeName, $classOrObject, $message = '')
1073
self::assertNotType(
1075
self::readAttribute($classOrObject, $attributeName),
1081
* Asserts that a string matches a given regular expression.
1083
* @param string $pattern
1084
* @param string $string
1085
* @param string $message
1087
public static function assertRegExp($pattern, $string, $message = '')
1089
if (!is_string($pattern)) {
1090
throw PHPUnit_Util_InvalidArgumentHelper::factory(1, 'string');
1093
if (!is_string($string)) {
1094
throw PHPUnit_Util_InvalidArgumentHelper::factory(2, 'string');
1097
$constraint = new PHPUnit_Framework_Constraint_PCREMatch($pattern);
1099
self::assertThat($string, $constraint, $message);
1103
* Asserts that a string does not match a given regular expression.
1105
* @param string $pattern
1106
* @param string $string
1107
* @param string $message
1108
* @since Method available since Release 2.1.0
1110
public static function assertNotRegExp($pattern, $string, $message = '')
1112
if (!is_string($pattern)) {
1113
throw PHPUnit_Util_InvalidArgumentHelper::factory(1, 'string');
1116
if (!is_string($string)) {
1117
throw PHPUnit_Util_InvalidArgumentHelper::factory(2, 'string');
1120
$constraint = new PHPUnit_Framework_Constraint_Not(
1121
new PHPUnit_Framework_Constraint_PCREMatch($pattern)
1124
self::assertThat($string, $constraint, $message);
1128
* Asserts that a string starts with a given prefix.
1130
* @param string $prefix
1131
* @param string $string
1132
* @param string $message
1133
* @since Method available since Release 3.4.0
1135
public static function assertStringStartsWith($prefix, $string, $message = '')
1137
if (!is_string($prefix)) {
1138
throw PHPUnit_Util_InvalidArgumentHelper::factory(1, 'string');
1141
if (!is_string($string)) {
1142
throw PHPUnit_Util_InvalidArgumentHelper::factory(2, 'string');
1145
$constraint = new PHPUnit_Framework_Constraint_StringStartsWith(
1149
self::assertThat($string, $constraint, $message);
1153
* Asserts that a string starts not with a given prefix.
1155
* @param string $prefix
1156
* @param string $string
1157
* @param string $message
1158
* @since Method available since Release 3.4.0
1160
public static function assertStringStartsNotWith($prefix, $string, $message = '')
1162
if (!is_string($prefix)) {
1163
throw PHPUnit_Util_InvalidArgumentHelper::factory(1, 'string');
1166
if (!is_string($string)) {
1167
throw PHPUnit_Util_InvalidArgumentHelper::factory(2, 'string');
1170
$constraint = new PHPUnit_Framework_Constraint_Not(
1171
new PHPUnit_Framework_Constraint_StringStartsWith($prefix)
1174
self::assertThat($string, $constraint, $message);
1178
* Asserts that a string ends with a given prefix.
1180
* @param string $suffix
1181
* @param string $string
1182
* @param string $message
1183
* @since Method available since Release 3.4.0
1185
public static function assertStringEndsWith($suffix, $string, $message = '')
1187
if (!is_string($suffix)) {
1188
throw PHPUnit_Util_InvalidArgumentHelper::factory(1, 'string');
1191
if (!is_string($string)) {
1192
throw PHPUnit_Util_InvalidArgumentHelper::factory(2, 'string');
1195
$constraint = new PHPUnit_Framework_Constraint_StringEndsWith($suffix);
1197
self::assertThat($string, $constraint, $message);
1201
* Asserts that a string ends not with a given prefix.
1203
* @param string $suffix
1204
* @param string $string
1205
* @param string $message
1206
* @since Method available since Release 3.4.0
1208
public static function assertStringEndsNotWith($suffix, $string, $message = '')
1210
if (!is_string($suffix)) {
1211
throw PHPUnit_Util_InvalidArgumentHelper::factory(1, 'string');
1214
if (!is_string($string)) {
1215
throw PHPUnit_Util_InvalidArgumentHelper::factory(2, 'string');
1218
$constraint = new PHPUnit_Framework_Constraint_Not(
1219
new PHPUnit_Framework_Constraint_StringEndsWith($suffix)
1222
self::assertThat($string, $constraint, $message);
1226
* Asserts that two XML files are equal.
1228
* @param string $expectedFile
1229
* @param string $actualFile
1230
* @param string $message
1231
* @since Method available since Release 3.1.0
1233
public static function assertXmlFileEqualsXmlFile($expectedFile, $actualFile, $message = '')
1235
self::assertFileExists($expectedFile);
1236
self::assertFileExists($actualFile);
1238
$expected = new DOMDocument;
1239
$expected->preserveWhiteSpace = FALSE;
1240
$expected->load($expectedFile);
1242
$actual = new DOMDocument;
1243
$actual->preserveWhiteSpace = FALSE;
1244
$actual->load($actualFile);
1246
self::assertEquals($expected, $actual, $message);
1250
* Asserts that two XML files are not equal.
1252
* @param string $expectedFile
1253
* @param string $actualFile
1254
* @param string $message
1255
* @since Method available since Release 3.1.0
1257
public static function assertXmlFileNotEqualsXmlFile($expectedFile, $actualFile, $message = '')
1259
self::assertFileExists($expectedFile);
1260
self::assertFileExists($actualFile);
1262
$expected = new DOMDocument;
1263
$expected->preserveWhiteSpace = FALSE;
1264
$expected->load($expectedFile);
1266
$actual = new DOMDocument;
1267
$actual->preserveWhiteSpace = FALSE;
1268
$actual->load($actualFile);
1270
self::assertNotEquals($expected, $actual, $message);
1274
* Asserts that two XML documents are equal.
1276
* @param string $expectedFile
1277
* @param string $actualXml
1278
* @param string $message
1279
* @since Method available since Release 3.3.0
1281
public static function assertXmlStringEqualsXmlFile($expectedFile, $actualXml, $message = '')
1283
self::assertFileExists($expectedFile);
1285
$expected = new DOMDocument;
1286
$expected->preserveWhiteSpace = FALSE;
1287
$expected->load($expectedFile);
1289
$actual = new DOMDocument;
1290
$actual->preserveWhiteSpace = FALSE;
1291
$actual->loadXML($actualXml);
1293
self::assertEquals($expected, $actual, $message);
1297
* Asserts that two XML documents are not equal.
1299
* @param string $expectedFile
1300
* @param string $actualXml
1301
* @param string $message
1302
* @since Method available since Release 3.3.0
1304
public static function assertXmlStringNotEqualsXmlFile($expectedFile, $actualXml, $message = '')
1306
self::assertFileExists($expectedFile);
1308
$expected = new DOMDocument;
1309
$expected->preserveWhiteSpace = FALSE;
1310
$expected->load($expectedFile);
1312
$actual = new DOMDocument;
1313
$actual->preserveWhiteSpace = FALSE;
1314
$actual->loadXML($actualXml);
1316
self::assertNotEquals($expected, $actual, $message);
1320
* Asserts that two XML documents are equal.
1322
* @param string $expectedXml
1323
* @param string $actualXml
1324
* @param string $message
1325
* @since Method available since Release 3.1.0
1327
public static function assertXmlStringEqualsXmlString($expectedXml, $actualXml, $message = '')
1329
$expected = new DOMDocument;
1330
$expected->preserveWhiteSpace = FALSE;
1331
$expected->loadXML($expectedXml);
1333
$actual = new DOMDocument;
1334
$actual->preserveWhiteSpace = FALSE;
1335
$actual->loadXML($actualXml);
1337
self::assertEquals($expected, $actual, $message);
1341
* Asserts that two XML documents are not equal.
1343
* @param string $expectedXml
1344
* @param string $actualXml
1345
* @param string $message
1346
* @since Method available since Release 3.1.0
1348
public static function assertXmlStringNotEqualsXmlString($expectedXml, $actualXml, $message = '')
1350
$expected = new DOMDocument;
1351
$expected->preserveWhiteSpace = FALSE;
1352
$expected->loadXML($expectedXml);
1354
$actual = new DOMDocument;
1355
$actual->preserveWhiteSpace = FALSE;
1356
$actual->loadXML($actualXml);
1358
self::assertNotEquals($expected, $actual, $message);
1362
* Asserts that a hierarchy of DOMNodes matches.
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
1371
public static function assertEqualXMLStructure(DOMNode $expectedNode, DOMNode $actualNode, $checkAttributes = FALSE, $message = '')
1374
$expectedNode->tagName,
1375
$actualNode->tagName,
1379
if ($checkAttributes) {
1381
$expectedNode->attributes->length,
1382
$actualNode->attributes->length,
1384
'%s%sNumber of attributes on node "%s" does not match',
1386
!empty($message) ? "\n" : '',
1387
$expectedNode->tagName
1391
for ($i = 0 ; $i < $expectedNode->attributes->length; $i++) {
1392
$expectedAttribute = $expectedNode->attributes->item($i);
1393
$actualAttribute = $actualNode->attributes->getNamedItem(
1394
$expectedAttribute->name
1397
if (!$actualAttribute) {
1400
'%s%sCould not find attribute "%s" on node "%s"',
1402
!empty($message) ? "\n" : '',
1403
$expectedAttribute->name,
1404
$expectedNode->tagName
1411
PHPUnit_Util_XML::removeCharacterDataNodes($expectedNode);
1412
PHPUnit_Util_XML::removeCharacterDataNodes($actualNode);
1415
$expectedNode->childNodes->length,
1416
$actualNode->childNodes->length,
1418
'%s%sNumber of child nodes of "%s" differs',
1420
!empty($message) ? "\n" : '',
1421
$expectedNode->tagName
1425
for ($i = 0; $i < $expectedNode->childNodes->length; $i++) {
1426
self::assertEqualXMLStructure(
1427
$expectedNode->childNodes->item($i),
1428
$actualNode->childNodes->item($i),
1436
* Assert the presence, absence, or count of elements in a document matching
1437
* the CSS $selector, regardless of the contents of those elements.
1439
* The first argument, $selector, is the CSS selector used to match
1440
* the elements in the $actual document.
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.
1447
* assertSelectCount("#binder", true, $xml); // any?
1448
* assertSelectCount(".binder", 3, $xml); // exactly 3?
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>
1459
public static function assertSelectCount($selector, $count, $actual, $message = '', $isHtml = TRUE)
1461
self::assertSelectEquals(
1462
$selector, TRUE, $count, $actual, $message, $isHtml
1467
* assertSelectRegExp("#binder .name", "/Mike|Derek/", true, $xml); // any?
1468
* assertSelectRegExp("#binder .name", "/Mike|Derek/", 3, $xml); // 3?
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>
1480
public static function assertSelectRegExp($selector, $pattern, $count, $actual, $message = '', $isHtml = TRUE)
1482
self::assertSelectEquals(
1483
$selector, "regexp:$pattern", $count, $actual, $message, $isHtml
1488
* assertSelectEquals("#binder .name", "Chuck", true, $xml); // any?
1489
* assertSelectEquals("#binder .name", "Chuck", false, $xml); // none?
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>
1501
public static function assertSelectEquals($selector, $content, $count, $actual, $message = '', $isHtml = TRUE)
1503
$tags = PHPUnit_Util_XML::cssSelect(
1504
$selector, $content, $actual, $isHtml
1507
// assert specific number of elements
1508
if (is_numeric($count)) {
1509
$counted = $tags ? count($tags) : 0;
1510
self::assertEquals($count, $counted);
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;
1518
self::assertTrue($any, $message);
1520
self::assertFalse($any, $message);
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;
1530
if (isset($count['>'])) {
1531
self::assertTrue($counted > $count['>'], $message);
1534
if (isset($count['>='])) {
1535
self::assertTrue($counted >= $count['>='], $message);
1538
if (isset($count['<'])) {
1539
self::assertTrue($counted < $count['<'], $message);
1542
if (isset($count['<='])) {
1543
self::assertTrue($counted <= $count['<='], $message);
1546
throw new InvalidArgumentException();
1551
* Evaluate an HTML or XML string and assert its structure and/or contents.
1553
* The first argument ($matcher) is an associative array that specifies the
1554
* match criteria for the assertion:
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.
1572
* - `count` : a number which must equal the number of children
1574
* - `less_than` : the number of matching children must be greater
1576
* - `greater_than` : the number of matching children must be less than
1578
* - `only` : another hash consisting of the keys to use to match
1579
* on the children, and only matching children will be
1583
* // Matcher that asserts that there is an element with an id="my_id".
1584
* $matcher = array('id' => 'my_id');
1586
* // Matcher that asserts that there is a "span" tag.
1587
* $matcher = array('tag' => 'span');
1589
* // Matcher that asserts that there is a "span" tag with the content
1591
* $matcher = array('tag' => 'span', 'content' => 'Hello World');
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)/');
1597
* // Matcher that asserts that there is a "span" with an "list" class
1601
* 'attributes' => array('class' => 'list')
1604
* // Matcher that asserts that there is a "span" inside of a "div".
1607
* 'parent' => array('tag' => 'div')
1610
* // Matcher that asserts that there is a "span" somewhere inside a
1614
* 'ancestor' => array('tag' => 'table')
1617
* // Matcher that asserts that there is a "span" with at least one "em"
1621
* 'child' => array('tag' => 'em')
1624
* // Matcher that asserts that there is a "span" containing a (possibly
1625
* // nested) "strong" tag.
1628
* 'descendant' => array('tag' => 'strong')
1631
* // Matcher that asserts that there is a "span" containing 5-10 "em" tags
1632
* // as immediate children.
1635
* 'children' => array(
1636
* 'less_than' => 11,
1637
* 'greater_than' => 4,
1638
* 'only' => array('tag' => 'em')
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".
1647
* 'ancestor' => array('tag' => 'ul'),
1648
* 'parent' => array(
1650
* 'attributes' => array('class' => 'enum')
1652
* 'descendant' => array(
1655
* 'id' => 'my_test',
1656
* 'content' => 'Hello World'
1661
* // Use assertTag() to apply a $matcher to a piece of $html.
1662
* $this->assertTag($matcher, $html);
1664
* // Use assertTag() to apply a $matcher to a piece of $xml.
1665
* $this->assertTag($matcher, $xml, '', FALSE);
1668
* The second argument ($actual) is a string containing either HTML or
1669
* XML text to be tested.
1671
* The third argument ($message) is an optional message that will be
1672
* used if the assertion fails.
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.
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>
1687
public static function assertTag($matcher, $actual, $message = '', $isHtml = TRUE)
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;
1693
self::assertTrue($matched, $message);
1697
* This assertion is the exact opposite of assertTag().
1699
* Rather than asserting that $matcher results in a match, it asserts that
1700
* $matcher does not match.
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>
1710
public static function assertNotTag($matcher, $actual, $message = '', $isHtml = TRUE)
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;
1716
self::assertFalse($matched, $message);
1720
* Evaluates a PHPUnit_Framework_Constraint matcher object.
1722
* @param mixed $value
1723
* @param PHPUnit_Framework_Constraint $constraint
1724
* @param string $message
1725
* @since Method available since Release 3.0.0
1727
public static function assertThat($value, PHPUnit_Framework_Constraint $constraint, $message = '')
1729
self::$count += count($constraint);
1731
if (!$constraint->evaluate($value)) {
1732
$constraint->fail($value, $message);
1737
* Returns a PHPUnit_Framework_Constraint_And matcher object.
1739
* @return PHPUnit_Framework_Constraint_And
1740
* @since Method available since Release 3.0.0
1742
public static function logicalAnd()
1744
$constraints = func_get_args();
1746
$constraint = new PHPUnit_Framework_Constraint_And;
1747
$constraint->setConstraints($constraints);
1753
* Returns a PHPUnit_Framework_Constraint_Or matcher object.
1755
* @return PHPUnit_Framework_Constraint_Or
1756
* @since Method available since Release 3.0.0
1758
public static function logicalOr()
1760
$constraints = func_get_args();
1762
$constraint = new PHPUnit_Framework_Constraint_Or;
1763
$constraint->setConstraints($constraints);
1769
* Returns a PHPUnit_Framework_Constraint_Not matcher object.
1771
* @param PHPUnit_Framework_Constraint $constraint
1772
* @return PHPUnit_Framework_Constraint_Not
1773
* @since Method available since Release 3.0.0
1775
public static function logicalNot(PHPUnit_Framework_Constraint $constraint)
1777
return new PHPUnit_Framework_Constraint_Not($constraint);
1781
* Returns a PHPUnit_Framework_Constraint_Xor matcher object.
1783
* @return PHPUnit_Framework_Constraint_Xor
1784
* @since Method available since Release 3.0.0
1786
public static function logicalXor()
1788
$constraints = func_get_args();
1790
$constraint = new PHPUnit_Framework_Constraint_Xor;
1791
$constraint->setConstraints($constraints);
1797
* Returns a PHPUnit_Framework_Constraint_IsAnything matcher object.
1799
* @return PHPUnit_Framework_Constraint_IsAnything
1800
* @since Method available since Release 3.0.0
1802
public static function anything()
1804
return new PHPUnit_Framework_Constraint_IsAnything;
1808
* Returns a PHPUnit_Framework_Constraint_IsTrue matcher object.
1810
* @return PHPUnit_Framework_Constraint_IsTrue
1811
* @since Method available since Release 3.3.0
1813
public static function isTrue()
1815
return new PHPUnit_Framework_Constraint_IsTrue;
1819
* Returns a PHPUnit_Framework_Constraint_IsFalse matcher object.
1821
* @return PHPUnit_Framework_Constraint_IsFalse
1822
* @since Method available since Release 3.3.0
1824
public static function isFalse()
1826
return new PHPUnit_Framework_Constraint_IsFalse;
1830
* Returns a PHPUnit_Framework_Constraint_IsNull matcher object.
1832
* @return PHPUnit_Framework_Constraint_IsNull
1833
* @since Method available since Release 3.3.0
1835
public static function isNull()
1837
return new PHPUnit_Framework_Constraint_IsNull;
1841
* Returns a PHPUnit_Framework_Constraint_Attribute matcher object.
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
1848
public static function attribute(PHPUnit_Framework_Constraint $constraint, $attributeName)
1850
return new PHPUnit_Framework_Constraint_Attribute(
1851
$constraint, $attributeName
1856
* Returns a PHPUnit_Framework_Constraint_TraversableContains matcher
1859
* @param mixed $value
1860
* @return PHPUnit_Framework_Constraint_TraversableContains
1861
* @since Method available since Release 3.0.0
1863
public static function contains($value)
1865
return new PHPUnit_Framework_Constraint_TraversableContains($value);
1869
* Returns a PHPUnit_Framework_Constraint_TraversableContainsOnly matcher
1872
* @param string $type
1873
* @return PHPUnit_Framework_Constraint_TraversableContainsOnly
1874
* @since Method available since Release 3.1.4
1876
public static function containsOnly($type)
1878
return new PHPUnit_Framework_Constraint_TraversableContainsOnly($type);
1882
* Returns a PHPUnit_Framework_Constraint_ArrayHasKey matcher object.
1885
* @return PHPUnit_Framework_Constraint_ArrayHasKey
1886
* @since Method available since Release 3.0.0
1888
public static function arrayHasKey($key)
1890
return new PHPUnit_Framework_Constraint_ArrayHasKey($key);
1894
* Returns a PHPUnit_Framework_Constraint_IsEqual matcher object.
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
1904
public static function equalTo($value, $delta = 0, $maxDepth = 10, $canonicalizeEol = FALSE, $ignoreCase = FALSE)
1906
return new PHPUnit_Framework_Constraint_IsEqual(
1907
$value, $delta, $maxDepth, $canonicalizeEol, $ignoreCase
1912
* Returns a PHPUnit_Framework_Constraint_IsEqual matcher object
1913
* that is wrapped in a PHPUnit_Framework_Constraint_Attribute matcher
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
1925
public static function attributeEqualTo($attributeName, $value, $delta = 0, $maxDepth = 10, $canonicalizeEol = FALSE, $ignoreCase = FALSE)
1927
return self::attribute(
1929
$value, $delta, $maxDepth, $canonicalizeEol, $ignoreCase
1936
* Returns a PHPUnit_Framework_Constraint_FileExists matcher object.
1938
* @return PHPUnit_Framework_Constraint_FileExists
1939
* @since Method available since Release 3.0.0
1941
public static function fileExists()
1943
return new PHPUnit_Framework_Constraint_FileExists;
1947
* Returns a PHPUnit_Framework_Constraint_GreaterThan matcher object.
1949
* @param mixed $value
1950
* @return PHPUnit_Framework_Constraint_GreaterThan
1951
* @since Method available since Release 3.0.0
1953
public static function greaterThan($value)
1955
return new PHPUnit_Framework_Constraint_GreaterThan($value);
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.
1963
* @param mixed $value
1964
* @return PHPUnit_Framework_Constraint_Or
1965
* @since Method available since Release 3.1.0
1967
public static function greaterThanOrEqual($value)
1969
return self::logicalOr(
1970
new PHPUnit_Framework_Constraint_IsEqual($value),
1971
new PHPUnit_Framework_Constraint_GreaterThan($value)
1976
* Returns a PHPUnit_Framework_Constraint_ClassHasAttribute matcher object.
1978
* @param string $attributeName
1979
* @return PHPUnit_Framework_Constraint_ClassHasAttribute
1980
* @since Method available since Release 3.1.0
1982
public static function classHasAttribute($attributeName)
1984
return new PHPUnit_Framework_Constraint_ClassHasAttribute(
1990
* Returns a PHPUnit_Framework_Constraint_ClassHasStaticAttribute matcher
1993
* @param string $attributeName
1994
* @return PHPUnit_Framework_Constraint_ClassHasStaticAttribute
1995
* @since Method available since Release 3.1.0
1997
public static function classHasStaticAttribute($attributeName)
1999
return new PHPUnit_Framework_Constraint_ClassHasStaticAttribute(
2005
* Returns a PHPUnit_Framework_Constraint_ObjectHasAttribute matcher object.
2007
* @param string $attributeName
2008
* @return PHPUnit_Framework_Constraint_ObjectHasAttribute
2009
* @since Method available since Release 3.0.0
2011
public static function objectHasAttribute($attributeName)
2013
return new PHPUnit_Framework_Constraint_ObjectHasAttribute(
2019
* Returns a PHPUnit_Framework_Constraint_IsIdentical matcher object.
2021
* @param mixed $value
2022
* @return PHPUnit_Framework_Constraint_IsIdentical
2023
* @since Method available since Release 3.0.0
2025
public static function identicalTo($value)
2027
return new PHPUnit_Framework_Constraint_IsIdentical($value);
2031
* Returns a PHPUnit_Framework_Constraint_IsInstanceOf matcher object.
2033
* @param string $className
2034
* @return PHPUnit_Framework_Constraint_IsInstanceOf
2035
* @since Method available since Release 3.0.0
2037
public static function isInstanceOf($className)
2039
return new PHPUnit_Framework_Constraint_IsInstanceOf($className);
2043
* Returns a PHPUnit_Framework_Constraint_IsType matcher object.
2045
* @param string $type
2046
* @return PHPUnit_Framework_Constraint_IsType
2047
* @since Method available since Release 3.0.0
2049
public static function isType($type)
2051
return new PHPUnit_Framework_Constraint_IsType($type);
2055
* Returns a PHPUnit_Framework_Constraint_LessThan matcher object.
2057
* @param mixed $value
2058
* @return PHPUnit_Framework_Constraint_LessThan
2059
* @since Method available since Release 3.0.0
2061
public static function lessThan($value)
2063
return new PHPUnit_Framework_Constraint_LessThan($value);
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.
2071
* @param mixed $value
2072
* @return PHPUnit_Framework_Constraint_Or
2073
* @since Method available since Release 3.1.0
2075
public static function lessThanOrEqual($value)
2077
return self::logicalOr(
2078
new PHPUnit_Framework_Constraint_IsEqual($value),
2079
new PHPUnit_Framework_Constraint_LessThan($value)
2084
* Returns a PHPUnit_Framework_Constraint_PCREMatch matcher object.
2086
* @param string $pattern
2087
* @return PHPUnit_Framework_Constraint_PCREMatch
2088
* @since Method available since Release 3.0.0
2090
public static function matchesRegularExpression($pattern)
2092
return new PHPUnit_Framework_Constraint_PCREMatch($pattern);
2096
* Returns a PHPUnit_Framework_Constraint_StringStartsWith matcher object.
2098
* @param mixed $prefix
2099
* @return PHPUnit_Framework_Constraint_StringStartsWith
2100
* @since Method available since Release 3.4.0
2102
public static function stringStartsWith($prefix)
2104
return new PHPUnit_Framework_Constraint_StringStartsWith($prefix);
2108
* Returns a PHPUnit_Framework_Constraint_StringContains matcher object.
2110
* @param string $string
2111
* @param boolean $case
2112
* @return PHPUnit_Framework_Constraint_StringContains
2113
* @since Method available since Release 3.0.0
2115
public static function stringContains($string, $case = TRUE)
2117
return new PHPUnit_Framework_Constraint_StringContains($string, $case);
2121
* Returns a PHPUnit_Framework_Constraint_StringEndsWith matcher object.
2123
* @param mixed $suffix
2124
* @return PHPUnit_Framework_Constraint_StringEndsWith
2125
* @since Method available since Release 3.4.0
2127
public static function stringEndsWith($suffix)
2129
return new PHPUnit_Framework_Constraint_StringEndsWith($suffix);
2133
* Fails a test with the given message.
2135
* @param string $message
2136
* @throws PHPUnit_Framework_AssertionFailedError
2138
public static function fail($message = '')
2140
throw new PHPUnit_Framework_AssertionFailedError($message);
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.
2147
* @param mixed $classOrObject
2148
* @param string $attributeName
2150
* @throws InvalidArgumentException
2152
public static function readAttribute($classOrObject, $attributeName)
2154
if (!is_string($attributeName)) {
2155
throw PHPUnit_Util_InvalidArgumentHelper::factory(2, 'string');
2158
if (is_string($classOrObject)) {
2159
if (!class_exists($classOrObject)) {
2160
throw PHPUnit_Util_InvalidArgumentHelper::factory(
2165
return PHPUnit_Util_Class::getStaticAttribute(
2171
else if (is_object($classOrObject)) {
2172
return PHPUnit_Util_Class::getObjectAttribute(
2179
throw PHPUnit_Util_InvalidArgumentHelper::factory(
2180
1, 'class name or object'
2186
* Mark the test as incomplete.
2188
* @param string $message
2189
* @throws PHPUnit_Framework_IncompleteTestError
2190
* @since Method available since Release 3.0.0
2192
public static function markTestIncomplete($message = '')
2194
throw new PHPUnit_Framework_IncompleteTestError($message);
2198
* Mark the test as skipped.
2200
* @param string $message
2201
* @throws PHPUnit_Framework_SkippedTestError
2202
* @since Method available since Release 3.0.0
2204
public static function markTestSkipped($message = '')
2206
throw new PHPUnit_Framework_SkippedTestError($message);
2210
* Return the current assertion count.
2213
* @since Method available since Release 3.3.3
2215
public static function getCount()
2217
return self::$count;
2221
* Reset the assertion counter.
2223
* @since Method available since Release 3.3.3
2225
public static function resetCount()
b'\\ No newline at end of file'