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