3 * This file is part of PHPUnit.
5 * (c) Sebastian Bergmann <sebastian@phpunit.de>
7 * For the full copyright and license information, please view the LICENSE
8 * file that was distributed with this source code.
12 * @since Class available since Release 3.0.0
14 class Framework_ConstraintTest extends PHPUnit_Framework_TestCase
17 * @covers PHPUnit_Framework_Constraint_ArrayHasKey
18 * @covers PHPUnit_Framework_Assert::arrayHasKey
19 * @covers PHPUnit_Framework_Constraint::count
20 * @covers PHPUnit_Framework_TestFailure::exceptionToString
22 public function testConstraintArrayHasKey()
24 $constraint = PHPUnit_Framework_Assert::arrayHasKey(0);
26 $this->assertFalse($constraint->evaluate(array(), '', true));
27 $this->assertEquals('has the key 0', $constraint->toString());
28 $this->assertEquals(1, count($constraint));
31 $constraint->evaluate(array());
32 } catch (PHPUnit_Framework_ExpectationFailedException $e) {
33 $this->assertEquals(<<<EOF
34 Failed asserting that an array has the key 0.
38 PHPUnit_Framework_TestFailure::exceptionToString($e)
48 * @covers PHPUnit_Framework_Constraint_ArrayHasKey
49 * @covers PHPUnit_Framework_Assert::arrayHasKey
50 * @covers PHPUnit_Framework_TestFailure::exceptionToString
52 public function testConstraintArrayHasKey2()
54 $constraint = PHPUnit_Framework_Assert::arrayHasKey(0);
57 $constraint->evaluate(array(), 'custom message');
58 } catch (PHPUnit_Framework_ExpectationFailedException $e) {
61 custom message\nFailed asserting that an array has the key 0.
65 PHPUnit_Framework_TestFailure::exceptionToString($e)
75 * @covers PHPUnit_Framework_Constraint_ArrayHasKey
76 * @covers PHPUnit_Framework_Constraint_Not
77 * @covers PHPUnit_Framework_Assert::arrayHasKey
78 * @covers PHPUnit_Framework_Assert::logicalNot
79 * @covers PHPUnit_Framework_TestFailure::exceptionToString
81 public function testConstraintArrayNotHasKey()
83 $constraint = PHPUnit_Framework_Assert::logicalNot(
84 PHPUnit_Framework_Assert::arrayHasKey(0)
87 $this->assertFalse($constraint->evaluate(array(0 => 1), '', true));
88 $this->assertEquals('does not have the key 0', $constraint->toString());
89 $this->assertEquals(1, count($constraint));
92 $constraint->evaluate(array(0 => 1));
93 } catch (PHPUnit_Framework_ExpectationFailedException $e) {
96 Failed asserting that an array does not have the key 0.
100 PHPUnit_Framework_TestFailure::exceptionToString($e)
110 * @covers PHPUnit_Framework_Constraint_ArrayHasKey
111 * @covers PHPUnit_Framework_Constraint_Not
112 * @covers PHPUnit_Framework_Assert::arrayHasKey
113 * @covers PHPUnit_Framework_Assert::logicalNot
114 * @covers PHPUnit_Framework_TestFailure::exceptionToString
116 public function testConstraintArrayNotHasKey2()
118 $constraint = PHPUnit_Framework_Assert::logicalNot(
119 PHPUnit_Framework_Assert::arrayHasKey(0)
123 $constraint->evaluate(array(0), 'custom message');
124 } catch (PHPUnit_Framework_ExpectationFailedException $e) {
128 Failed asserting that an array does not have the key 0.
132 PHPUnit_Framework_TestFailure::exceptionToString($e)
142 * @covers PHPUnit_Framework_Constraint_FileExists
143 * @covers PHPUnit_Framework_Assert::fileExists
144 * @covers PHPUnit_Framework_Constraint::count
145 * @covers PHPUnit_Framework_TestFailure::exceptionToString
147 public function testConstraintFileExists()
149 $constraint = PHPUnit_Framework_Assert::fileExists();
151 $this->assertFalse($constraint->evaluate('foo', '', true));
152 $this->assertEquals('file exists', $constraint->toString());
153 $this->assertEquals(1, count($constraint));
156 $constraint->evaluate('foo');
157 } catch (PHPUnit_Framework_ExpectationFailedException $e) {
160 Failed asserting that file "foo" exists.
164 PHPUnit_Framework_TestFailure::exceptionToString($e)
174 * @covers PHPUnit_Framework_Constraint_FileExists
175 * @covers PHPUnit_Framework_Assert::fileExists
176 * @covers PHPUnit_Framework_TestFailure::exceptionToString
178 public function testConstraintFileExists2()
180 $constraint = PHPUnit_Framework_Assert::fileExists();
183 $constraint->evaluate('foo', 'custom message');
184 } catch (PHPUnit_Framework_ExpectationFailedException $e) {
185 $this->assertEquals(<<<EOF
187 Failed asserting that file "foo" exists.
191 PHPUnit_Framework_TestFailure::exceptionToString($e)
201 * @covers PHPUnit_Framework_Constraint_FileExists
202 * @covers PHPUnit_Framework_Constraint_Not
203 * @covers PHPUnit_Framework_Assert::logicalNot
204 * @covers PHPUnit_Framework_Assert::fileExists
205 * @covers PHPUnit_Framework_TestFailure::exceptionToString
207 public function testConstraintFileNotExists()
209 $file = dirname(__DIR__) . DIRECTORY_SEPARATOR . '_files' . DIRECTORY_SEPARATOR . 'ClassWithNonPublicAttributes.php';
211 $constraint = PHPUnit_Framework_Assert::logicalNot(
212 PHPUnit_Framework_Assert::fileExists()
215 $this->assertFalse($constraint->evaluate($file, '', true));
216 $this->assertEquals('file does not exist', $constraint->toString());
217 $this->assertEquals(1, count($constraint));
220 $constraint->evaluate($file);
221 } catch (PHPUnit_Framework_ExpectationFailedException $e) {
224 Failed asserting that file "$file" does not exist.
228 PHPUnit_Framework_TestFailure::exceptionToString($e)
238 * @covers PHPUnit_Framework_Constraint_FileExists
239 * @covers PHPUnit_Framework_Constraint_Not
240 * @covers PHPUnit_Framework_Assert::logicalNot
241 * @covers PHPUnit_Framework_Assert::fileExists
242 * @covers PHPUnit_Framework_TestFailure::exceptionToString
244 public function testConstraintFileNotExists2()
246 $file = dirname(__DIR__) . DIRECTORY_SEPARATOR . '_files' . DIRECTORY_SEPARATOR . 'ClassWithNonPublicAttributes.php';
248 $constraint = PHPUnit_Framework_Assert::logicalNot(
249 PHPUnit_Framework_Assert::fileExists()
253 $constraint->evaluate($file, 'custom message');
254 } catch (PHPUnit_Framework_ExpectationFailedException $e) {
255 $this->assertEquals(<<<EOF
257 Failed asserting that file "$file" does not exist.
261 PHPUnit_Framework_TestFailure::exceptionToString($e)
271 * @covers PHPUnit_Framework_Constraint_GreaterThan
272 * @covers PHPUnit_Framework_Assert::greaterThan
273 * @covers PHPUnit_Framework_Constraint::count
274 * @covers PHPUnit_Framework_TestFailure::exceptionToString
276 public function testConstraintGreaterThan()
278 $constraint = PHPUnit_Framework_Assert::greaterThan(1);
280 $this->assertFalse($constraint->evaluate(0, '', true));
281 $this->assertTrue($constraint->evaluate(2, '', true));
282 $this->assertEquals('is greater than 1', $constraint->toString());
283 $this->assertEquals(1, count($constraint));
286 $constraint->evaluate(0);
287 } catch (PHPUnit_Framework_ExpectationFailedException $e) {
290 Failed asserting that 0 is greater than 1.
294 PHPUnit_Framework_TestFailure::exceptionToString($e)
304 * @covers PHPUnit_Framework_Constraint_GreaterThan
305 * @covers PHPUnit_Framework_Assert::greaterThan
306 * @covers PHPUnit_Framework_TestFailure::exceptionToString
308 public function testConstraintGreaterThan2()
310 $constraint = PHPUnit_Framework_Assert::greaterThan(1);
313 $constraint->evaluate(0, 'custom message');
314 } catch (PHPUnit_Framework_ExpectationFailedException $e) {
318 Failed asserting that 0 is greater than 1.
322 PHPUnit_Framework_TestFailure::exceptionToString($e)
332 * @covers PHPUnit_Framework_Constraint_GreaterThan
333 * @covers PHPUnit_Framework_Constraint_Not
334 * @covers PHPUnit_Framework_Assert::greaterThan
335 * @covers PHPUnit_Framework_Assert::logicalNot
336 * @covers PHPUnit_Framework_TestFailure::exceptionToString
338 public function testConstraintNotGreaterThan()
340 $constraint = PHPUnit_Framework_Assert::logicalNot(
341 PHPUnit_Framework_Assert::greaterThan(1)
344 $this->assertTrue($constraint->evaluate(1, '', true));
345 $this->assertEquals('is not greater than 1', $constraint->toString());
346 $this->assertEquals(1, count($constraint));
349 $constraint->evaluate(2);
350 } catch (PHPUnit_Framework_ExpectationFailedException $e) {
353 Failed asserting that 2 is not greater than 1.
357 PHPUnit_Framework_TestFailure::exceptionToString($e)
367 * @covers PHPUnit_Framework_Constraint_GreaterThan
368 * @covers PHPUnit_Framework_Constraint_Not
369 * @covers PHPUnit_Framework_Assert::greaterThan
370 * @covers PHPUnit_Framework_Assert::logicalNot
371 * @covers PHPUnit_Framework_TestFailure::exceptionToString
373 public function testConstraintNotGreaterThan2()
375 $constraint = PHPUnit_Framework_Assert::logicalNot(
376 PHPUnit_Framework_Assert::greaterThan(1)
380 $constraint->evaluate(2, 'custom message');
381 } catch (PHPUnit_Framework_ExpectationFailedException $e) {
385 Failed asserting that 2 is not greater than 1.
389 PHPUnit_Framework_TestFailure::exceptionToString($e)
399 * @covers PHPUnit_Framework_Constraint_IsEqual
400 * @covers PHPUnit_Framework_Constraint_GreaterThan
401 * @covers PHPUnit_Framework_Constraint_Or
402 * @covers PHPUnit_Framework_Assert::greaterThanOrEqual
403 * @covers PHPUnit_Framework_TestFailure::exceptionToString
405 public function testConstraintGreaterThanOrEqual()
407 $constraint = PHPUnit_Framework_Assert::greaterThanOrEqual(1);
409 $this->assertTrue($constraint->evaluate(1, '', true));
410 $this->assertFalse($constraint->evaluate(0, '', true));
411 $this->assertEquals('is equal to 1 or is greater than 1', $constraint->toString());
412 $this->assertEquals(2, count($constraint));
415 $constraint->evaluate(0);
416 } catch (PHPUnit_Framework_ExpectationFailedException $e) {
419 Failed asserting that 0 is equal to 1 or is greater than 1.
423 PHPUnit_Framework_TestFailure::exceptionToString($e)
433 * @covers PHPUnit_Framework_Constraint_IsEqual
434 * @covers PHPUnit_Framework_Constraint_GreaterThan
435 * @covers PHPUnit_Framework_Constraint_Or
436 * @covers PHPUnit_Framework_Assert::greaterThanOrEqual
437 * @covers PHPUnit_Framework_TestFailure::exceptionToString
439 public function testConstraintGreaterThanOrEqual2()
441 $constraint = PHPUnit_Framework_Assert::greaterThanOrEqual(1);
444 $constraint->evaluate(0, 'custom message');
445 } catch (PHPUnit_Framework_ExpectationFailedException $e) {
449 Failed asserting that 0 is equal to 1 or is greater than 1.
453 PHPUnit_Framework_TestFailure::exceptionToString($e)
463 * @covers PHPUnit_Framework_Constraint_IsEqual
464 * @covers PHPUnit_Framework_Constraint_GreaterThan
465 * @covers PHPUnit_Framework_Constraint_Or
466 * @covers PHPUnit_Framework_Constraint_Not
467 * @covers PHPUnit_Framework_Assert::greaterThanOrEqual
468 * @covers PHPUnit_Framework_Assert::logicalNot
469 * @covers PHPUnit_Framework_TestFailure::exceptionToString
471 public function testConstraintNotGreaterThanOrEqual()
473 $constraint = PHPUnit_Framework_Assert::logicalNot(
474 PHPUnit_Framework_Assert::greaterThanOrEqual(1)
477 $this->assertFalse($constraint->evaluate(1, '', true));
478 $this->assertEquals('not( is equal to 1 or is greater than 1 )', $constraint->toString());
479 $this->assertEquals(2, count($constraint));
482 $constraint->evaluate(1);
483 } catch (PHPUnit_Framework_ExpectationFailedException $e) {
486 Failed asserting that not( 1 is equal to 1 or is greater than 1 ).
490 PHPUnit_Framework_TestFailure::exceptionToString($e)
500 * @covers PHPUnit_Framework_Constraint_IsEqual
501 * @covers PHPUnit_Framework_Constraint_GreaterThan
502 * @covers PHPUnit_Framework_Constraint_Or
503 * @covers PHPUnit_Framework_Constraint_Not
504 * @covers PHPUnit_Framework_Assert::greaterThanOrEqual
505 * @covers PHPUnit_Framework_Assert::logicalNot
506 * @covers PHPUnit_Framework_TestFailure::exceptionToString
508 public function testConstraintNotGreaterThanOrEqual2()
510 $constraint = PHPUnit_Framework_Assert::logicalNot(
511 PHPUnit_Framework_Assert::greaterThanOrEqual(1)
515 $constraint->evaluate(1, 'custom message');
516 } catch (PHPUnit_Framework_ExpectationFailedException $e) {
520 Failed asserting that not( 1 is equal to 1 or is greater than 1 ).
524 PHPUnit_Framework_TestFailure::exceptionToString($e)
534 * @covers PHPUnit_Framework_Constraint_IsAnything
535 * @covers PHPUnit_Framework_Assert::anything
536 * @covers PHPUnit_Framework_Constraint::count
537 * @covers PHPUnit_Framework_TestFailure::exceptionToString
539 public function testConstraintIsAnything()
541 $constraint = PHPUnit_Framework_Assert::anything();
543 $this->assertTrue($constraint->evaluate(null, '', true));
544 $this->assertNull($constraint->evaluate(null));
545 $this->assertEquals('is anything', $constraint->toString());
546 $this->assertEquals(0, count($constraint));
550 * @covers PHPUnit_Framework_Constraint_IsAnything
551 * @covers PHPUnit_Framework_Constraint_Not
552 * @covers PHPUnit_Framework_Assert::anything
553 * @covers PHPUnit_Framework_Assert::logicalNot
554 * @covers PHPUnit_Framework_TestFailure::exceptionToString
556 public function testConstraintNotIsAnything()
558 $constraint = PHPUnit_Framework_Assert::logicalNot(
559 PHPUnit_Framework_Assert::anything()
562 $this->assertFalse($constraint->evaluate(null, '', true));
563 $this->assertEquals('is not anything', $constraint->toString());
564 $this->assertEquals(0, count($constraint));
567 $constraint->evaluate(null);
568 } catch (PHPUnit_Framework_ExpectationFailedException $e) {
571 Failed asserting that null is not anything.
575 PHPUnit_Framework_TestFailure::exceptionToString($e)
585 * @covers PHPUnit_Framework_Constraint_IsEqual
586 * @covers PHPUnit_Framework_Assert::equalTo
587 * @covers PHPUnit_Framework_Constraint::count
588 * @covers PHPUnit_Framework_TestFailure::exceptionToString
590 public function testConstraintIsEqual()
592 $constraint = PHPUnit_Framework_Assert::equalTo(1);
594 $this->assertTrue($constraint->evaluate(1, '', true));
595 $this->assertFalse($constraint->evaluate(0, '', true));
596 $this->assertEquals('is equal to 1', $constraint->toString());
597 $this->assertEquals(1, count($constraint));
600 $constraint->evaluate(0);
601 } catch (PHPUnit_Framework_ExpectationFailedException $e) {
604 Failed asserting that 0 matches expected 1.
608 PHPUnit_Framework_TestFailure::exceptionToString($e)
617 public function isEqualProvider()
622 $ahash = spl_object_hash($a);
623 $bhash = spl_object_hash($b);
628 $c->array = array(0, array(1), array(2), 3);
629 $c->related = new stdClass;
630 $c->related->foo = "a\nb\nc\nd\ne\nf\ng\nh\ni\nj\nk";
636 $d->array = array(0, array(4), array(2), 3);
637 $d->related = new stdClass;
638 $d->related->foo = "a\np\nc\nd\ne\nf\ng\nh\ni\nw\nk";
642 $storage1 = new SplObjectStorage;
643 $storage1->attach($a);
644 $storage1->attach($b);
645 $storage2 = new SplObjectStorage;
646 $storage2->attach($b);
647 $storage1hash = spl_object_hash($storage1);
648 $storage2hash = spl_object_hash($storage2);
650 $dom1 = new DOMDocument;
651 $dom1->preserveWhiteSpace = false;
652 $dom1->loadXML('<root></root>');
653 $dom2 = new DOMDocument;
654 $dom2->preserveWhiteSpace = false;
655 $dom2->loadXML('<root><foo/></root>');
659 Failed asserting that 0 matches expected 1.
664 Failed asserting that 0 matches expected 1.1.
668 array('a', 'b', <<<EOF
669 Failed asserting that two strings are equal.
678 array("a\nb\nc\nd\ne\nf\ng\nh\ni\nj\nk", "a\np\nc\nd\ne\nf\ng\nh\ni\nw\nk", <<<EOF
679 Failed asserting that two strings are equal.
695 array(1, array(0), <<<EOF
696 Array (...) does not match expected type "integer".
700 array(array(0), 1, <<<EOF
701 1 does not match expected type "array".
705 array(array(0), array(1), <<<EOF
706 Failed asserting that two arrays are equal.
717 array(array(true), array('true'), <<<EOF
718 Failed asserting that two arrays are equal.
729 array(array(0, array(1), array(2), 3), array(0, array(4), array(2), 3), <<<EOF
730 Failed asserting that two arrays are equal.
746 array($a, array(0), <<<EOF
747 Array (...) does not match expected type "object".
751 array(array(0), $a, <<<EOF
752 stdClass Object (...) does not match expected type "array".
757 Failed asserting that two objects are equal.
768 Failed asserting that two objects are equal.
793 'self' => stdClass Object (...)
794 'c' => stdClass Object (...)
799 array($dom1, $dom2, <<<EOF
800 Failed asserting that two DOM documents are equal.
804 <?xml version="1.0"?>
813 new DateTime('2013-03-29 04:13:35', new DateTimeZone('America/New_York')),
814 new DateTime('2013-03-29 04:13:35', new DateTimeZone('America/Chicago')),
816 Failed asserting that two DateTime objects are equal.
820 -2013-03-29T04:13:35.000000-0400
821 +2013-03-29T04:13:35.000000-0500
827 if (PHP_MAJOR_VERSION < 7) {
828 $data[] = array($storage1, $storage2, <<<EOF
829 Failed asserting that two objects are equal.
833 -SplObjectStorage Object &$storage1hash (
834 - '$ahash' => Array &0 (
835 - 'obj' => stdClass Object &$ahash (
838 +SplObjectStorage Object &$storage2hash (
839 + '$bhash' => Array &0 (
840 + 'obj' => stdClass Object &$bhash ()
843 - '$bhash' => Array &0
849 $data[] = array($storage1, $storage2, <<<EOF
850 Failed asserting that two objects are equal.
854 -SplObjectStorage Object &$storage1hash (
855 - '$ahash' => Array &0 (
856 - 'obj' => stdClass Object &$ahash (
859 +SplObjectStorage Object &$storage2hash (
860 + '$bhash' => Array &0 (
861 + 'obj' => stdClass Object &$bhash ()
864 - '$bhash' => Array &0
875 * @dataProvider isEqualProvider
876 * @covers PHPUnit_Framework_Constraint_IsEqual
877 * @covers PHPUnit_Framework_Assert::equalTo
878 * @covers PHPUnit_Framework_TestFailure::exceptionToString
880 public function testConstraintIsEqual2($expected, $actual, $message)
882 $constraint = PHPUnit_Framework_Assert::equalTo($expected);
885 $constraint->evaluate($actual, 'custom message');
886 } catch (PHPUnit_Framework_ExpectationFailedException $e) {
888 "custom message\n$message",
889 $this->trimnl(PHPUnit_Framework_TestFailure::exceptionToString($e))
899 * @covers PHPUnit_Framework_Constraint_IsEqual
900 * @covers PHPUnit_Framework_Constraint_Not
901 * @covers PHPUnit_Framework_Assert::equalTo
902 * @covers PHPUnit_Framework_Assert::logicalNot
903 * @covers PHPUnit_Framework_TestFailure::exceptionToString
905 public function testConstraintIsNotEqual()
907 $constraint = PHPUnit_Framework_Assert::logicalNot(
908 PHPUnit_Framework_Assert::equalTo(1)
911 $this->assertTrue($constraint->evaluate(0, '', true));
912 $this->assertFalse($constraint->evaluate(1, '', true));
913 $this->assertEquals('is not equal to 1', $constraint->toString());
914 $this->assertEquals(1, count($constraint));
917 $constraint->evaluate(1);
918 } catch (PHPUnit_Framework_ExpectationFailedException $e) {
921 Failed asserting that 1 is not equal to 1.
925 PHPUnit_Framework_TestFailure::exceptionToString($e)
935 * @covers PHPUnit_Framework_Constraint_IsEqual
936 * @covers PHPUnit_Framework_Constraint_Not
937 * @covers PHPUnit_Framework_Assert::equalTo
938 * @covers PHPUnit_Framework_Assert::logicalNot
939 * @covers PHPUnit_Framework_TestFailure::exceptionToString
941 public function testConstraintIsNotEqual2()
943 $constraint = PHPUnit_Framework_Assert::logicalNot(
944 PHPUnit_Framework_Assert::equalTo(1)
948 $constraint->evaluate(1, 'custom message');
949 } catch (PHPUnit_Framework_ExpectationFailedException $e) {
953 Failed asserting that 1 is not equal to 1.
957 PHPUnit_Framework_TestFailure::exceptionToString($e)
967 * @covers PHPUnit_Framework_Constraint_IsIdentical
968 * @covers PHPUnit_Framework_Assert::identicalTo
969 * @covers PHPUnit_Framework_Constraint::count
970 * @covers PHPUnit_Framework_TestFailure::exceptionToString
972 public function testConstraintIsIdentical()
977 $constraint = PHPUnit_Framework_Assert::identicalTo($a);
979 $this->assertFalse($constraint->evaluate($b, '', true));
980 $this->assertTrue($constraint->evaluate($a, '', true));
981 $this->assertEquals('is identical to an object of class "stdClass"', $constraint->toString());
982 $this->assertEquals(1, count($constraint));
985 $constraint->evaluate($b);
986 } catch (PHPUnit_Framework_ExpectationFailedException $e) {
987 $this->assertEquals(<<<EOF
988 Failed asserting that two variables reference the same object.
992 PHPUnit_Framework_TestFailure::exceptionToString($e)
1002 * @covers PHPUnit_Framework_Constraint_IsIdentical
1003 * @covers PHPUnit_Framework_Assert::identicalTo
1004 * @covers PHPUnit_Framework_TestFailure::exceptionToString
1006 public function testConstraintIsIdentical2()
1011 $constraint = PHPUnit_Framework_Assert::identicalTo($a);
1014 $constraint->evaluate($b, 'custom message');
1015 } catch (PHPUnit_Framework_ExpectationFailedException $e) {
1016 $this->assertEquals(<<<EOF
1018 Failed asserting that two variables reference the same object.
1022 PHPUnit_Framework_TestFailure::exceptionToString($e)
1032 * @covers PHPUnit_Framework_Constraint_IsIdentical
1033 * @covers PHPUnit_Framework_Assert::identicalTo
1034 * @covers PHPUnit_Framework_TestFailure::exceptionToString
1036 public function testConstraintIsIdentical3()
1038 $constraint = PHPUnit_Framework_Assert::identicalTo('a');
1041 $constraint->evaluate('b', 'custom message');
1042 } catch (PHPUnit_Framework_ExpectationFailedException $e) {
1043 $this->assertEquals(<<<EOF
1045 Failed asserting that two strings are identical.
1054 PHPUnit_Framework_TestFailure::exceptionToString($e)
1064 * @covers PHPUnit_Framework_Constraint_IsIdentical
1065 * @covers PHPUnit_Framework_Constraint_Not
1066 * @covers PHPUnit_Framework_Assert::identicalTo
1067 * @covers PHPUnit_Framework_Assert::logicalNot
1068 * @covers PHPUnit_Framework_TestFailure::exceptionToString
1070 public function testConstraintIsNotIdentical()
1075 $constraint = PHPUnit_Framework_Assert::logicalNot(
1076 PHPUnit_Framework_Assert::identicalTo($a)
1079 $this->assertTrue($constraint->evaluate($b, '', true));
1080 $this->assertFalse($constraint->evaluate($a, '', true));
1081 $this->assertEquals('is not identical to an object of class "stdClass"', $constraint->toString());
1082 $this->assertEquals(1, count($constraint));
1085 $constraint->evaluate($a);
1086 } catch (PHPUnit_Framework_ExpectationFailedException $e) {
1087 $this->assertEquals(<<<EOF
1088 Failed asserting that two variables don't reference the same object.
1092 $this->trimnl(PHPUnit_Framework_TestFailure::exceptionToString($e))
1102 * @covers PHPUnit_Framework_Constraint_IsIdentical
1103 * @covers PHPUnit_Framework_Constraint_Not
1104 * @covers PHPUnit_Framework_Assert::identicalTo
1105 * @covers PHPUnit_Framework_Assert::logicalNot
1106 * @covers PHPUnit_Framework_TestFailure::exceptionToString
1108 public function testConstraintIsNotIdentical2()
1112 $constraint = PHPUnit_Framework_Assert::logicalNot(
1113 PHPUnit_Framework_Assert::identicalTo($a)
1117 $constraint->evaluate($a, 'custom message');
1118 } catch (PHPUnit_Framework_ExpectationFailedException $e) {
1119 $this->assertEquals(<<<EOF
1121 Failed asserting that two variables don't reference the same object.
1125 PHPUnit_Framework_TestFailure::exceptionToString($e)
1135 * @covers PHPUnit_Framework_Constraint_IsIdentical
1136 * @covers PHPUnit_Framework_Constraint_Not
1137 * @covers PHPUnit_Framework_Assert::identicalTo
1138 * @covers PHPUnit_Framework_Assert::logicalNot
1139 * @covers PHPUnit_Framework_TestFailure::exceptionToString
1141 public function testConstraintIsNotIdentical3()
1143 $constraint = PHPUnit_Framework_Assert::logicalNot(
1144 PHPUnit_Framework_Assert::identicalTo('a')
1148 $constraint->evaluate('a', 'custom message');
1149 } catch (PHPUnit_Framework_ExpectationFailedException $e) {
1150 $this->assertEquals(<<<EOF
1152 Failed asserting that two strings are not identical.
1156 $this->trimnl(PHPUnit_Framework_TestFailure::exceptionToString($e))
1166 * @covers PHPUnit_Framework_Constraint_IsInstanceOf
1167 * @covers PHPUnit_Framework_Assert::isInstanceOf
1168 * @covers PHPUnit_Framework_Constraint::count
1169 * @covers PHPUnit_Framework_TestFailure::exceptionToString
1171 public function testConstraintIsInstanceOf()
1173 $constraint = PHPUnit_Framework_Assert::isInstanceOf('Exception');
1175 $this->assertFalse($constraint->evaluate(new stdClass, '', true));
1176 $this->assertTrue($constraint->evaluate(new Exception, '', true));
1177 $this->assertEquals('is instance of class "Exception"', $constraint->toString());
1178 $this->assertEquals(1, count($constraint));
1180 $interfaceConstraint = PHPUnit_Framework_Assert::isInstanceOf('Countable');
1181 $this->assertFalse($interfaceConstraint->evaluate(new stdClass, '', true));
1182 $this->assertTrue($interfaceConstraint->evaluate(new ArrayObject, '', true));
1183 $this->assertEquals('is instance of interface "Countable"', $interfaceConstraint->toString());
1186 $constraint->evaluate(new stdClass);
1187 } catch (PHPUnit_Framework_ExpectationFailedException $e) {
1188 $this->assertEquals(
1190 Failed asserting that stdClass Object () is an instance of class "Exception".
1194 PHPUnit_Framework_TestFailure::exceptionToString($e)
1204 * @covers PHPUnit_Framework_Constraint_IsInstanceOf
1205 * @covers PHPUnit_Framework_Assert::isInstanceOf
1206 * @covers PHPUnit_Framework_TestFailure::exceptionToString
1208 public function testConstraintIsInstanceOf2()
1210 $constraint = PHPUnit_Framework_Assert::isInstanceOf('Exception');
1213 $constraint->evaluate(new stdClass, 'custom message');
1214 } catch (PHPUnit_Framework_ExpectationFailedException $e) {
1215 $this->assertEquals(<<<EOF
1217 Failed asserting that stdClass Object () is an instance of class "Exception".
1221 PHPUnit_Framework_TestFailure::exceptionToString($e)
1231 * @covers PHPUnit_Framework_Constraint_IsInstanceOf
1232 * @covers PHPUnit_Framework_Constraint_Not
1233 * @covers PHPUnit_Framework_Assert::isInstanceOf
1234 * @covers PHPUnit_Framework_Assert::logicalNot
1235 * @covers PHPUnit_Framework_TestFailure::exceptionToString
1237 public function testConstraintIsNotInstanceOf()
1239 $constraint = PHPUnit_Framework_Assert::logicalNot(
1240 PHPUnit_Framework_Assert::isInstanceOf('stdClass')
1243 $this->assertFalse($constraint->evaluate(new stdClass, '', true));
1244 $this->assertTrue($constraint->evaluate(new Exception, '', true));
1245 $this->assertEquals('is not instance of class "stdClass"', $constraint->toString());
1246 $this->assertEquals(1, count($constraint));
1249 $constraint->evaluate(new stdClass);
1250 } catch (PHPUnit_Framework_ExpectationFailedException $e) {
1251 $this->assertEquals(
1253 Failed asserting that stdClass Object () is not an instance of class "stdClass".
1257 PHPUnit_Framework_TestFailure::exceptionToString($e)
1267 * @covers PHPUnit_Framework_Constraint_IsInstanceOf
1268 * @covers PHPUnit_Framework_Constraint_Not
1269 * @covers PHPUnit_Framework_Assert::isInstanceOf
1270 * @covers PHPUnit_Framework_Assert::logicalNot
1271 * @covers PHPUnit_Framework_TestFailure::exceptionToString
1273 public function testConstraintIsNotInstanceOf2()
1275 $constraint = PHPUnit_Framework_Assert::logicalNot(
1276 PHPUnit_Framework_Assert::isInstanceOf('stdClass')
1280 $constraint->evaluate(new stdClass, 'custom message');
1281 } catch (PHPUnit_Framework_ExpectationFailedException $e) {
1282 $this->assertEquals(<<<EOF
1284 Failed asserting that stdClass Object () is not an instance of class "stdClass".
1288 PHPUnit_Framework_TestFailure::exceptionToString($e)
1298 * @covers PHPUnit_Framework_Constraint_IsType
1299 * @covers PHPUnit_Framework_Assert::isType
1300 * @covers PHPUnit_Framework_Constraint::count
1301 * @covers PHPUnit_Framework_TestFailure::exceptionToString
1303 public function testConstraintIsType()
1305 $constraint = PHPUnit_Framework_Assert::isType('string');
1307 $this->assertFalse($constraint->evaluate(0, '', true));
1308 $this->assertTrue($constraint->evaluate('', '', true));
1309 $this->assertEquals('is of type "string"', $constraint->toString());
1310 $this->assertEquals(1, count($constraint));
1313 $constraint->evaluate(new stdClass);
1314 } catch (PHPUnit_Framework_ExpectationFailedException $e) {
1315 $this->assertStringMatchesFormat(<<<EOF
1316 Failed asserting that stdClass Object &%x () is of type "string".
1320 $this->trimnl(PHPUnit_Framework_TestFailure::exceptionToString($e))
1330 * @covers PHPUnit_Framework_Constraint_IsType
1331 * @covers PHPUnit_Framework_Assert::isType
1332 * @covers PHPUnit_Framework_TestFailure::exceptionToString
1334 public function testConstraintIsType2()
1336 $constraint = PHPUnit_Framework_Assert::isType('string');
1339 $constraint->evaluate(new stdClass, 'custom message');
1340 } catch (PHPUnit_Framework_ExpectationFailedException $e) {
1341 $this->assertStringMatchesFormat(<<<EOF
1343 Failed asserting that stdClass Object &%x () is of type "string".
1347 $this->trimnl(PHPUnit_Framework_TestFailure::exceptionToString($e))
1356 public function resources()
1358 $fh = fopen(__FILE__, 'r');
1362 'open resource' => array(fopen(__FILE__, 'r')),
1363 'closed resource' => array($fh),
1368 * @dataProvider resources
1369 * @covers PHPUnit_Framework_Constraint_IsType
1370 * @covers PHPUnit_Framework_Assert::isType
1372 public function testConstraintIsResourceTypeEvaluatesCorrectlyWithResources($resource)
1374 $constraint = PHPUnit_Framework_Assert::isType('resource');
1376 $this->assertTrue($constraint->evaluate($resource, '', true));
1382 * @covers PHPUnit_Framework_Constraint_IsType
1383 * @covers PHPUnit_Framework_Constraint_Not
1384 * @covers PHPUnit_Framework_Assert::isType
1385 * @covers PHPUnit_Framework_Assert::logicalNot
1386 * @covers PHPUnit_Framework_TestFailure::exceptionToString
1388 public function testConstraintIsNotType()
1390 $constraint = PHPUnit_Framework_Assert::logicalNot(
1391 PHPUnit_Framework_Assert::isType('string')
1394 $this->assertTrue($constraint->evaluate(0, '', true));
1395 $this->assertFalse($constraint->evaluate('', '', true));
1396 $this->assertEquals('is not of type "string"', $constraint->toString());
1397 $this->assertEquals(1, count($constraint));
1400 $constraint->evaluate('');
1401 } catch (PHPUnit_Framework_ExpectationFailedException $e) {
1402 $this->assertEquals(
1404 Failed asserting that '' is not of type "string".
1408 PHPUnit_Framework_TestFailure::exceptionToString($e)
1418 * @covers PHPUnit_Framework_Constraint_IsType
1419 * @covers PHPUnit_Framework_Constraint_Not
1420 * @covers PHPUnit_Framework_Assert::isType
1421 * @covers PHPUnit_Framework_Assert::logicalNot
1422 * @covers PHPUnit_Framework_TestFailure::exceptionToString
1424 public function testConstraintIsNotType2()
1426 $constraint = PHPUnit_Framework_Assert::logicalNot(
1427 PHPUnit_Framework_Assert::isType('string')
1431 $constraint->evaluate('', 'custom message');
1432 } catch (PHPUnit_Framework_ExpectationFailedException $e) {
1433 $this->assertEquals(<<<EOF
1435 Failed asserting that '' is not of type "string".
1439 PHPUnit_Framework_TestFailure::exceptionToString($e)
1449 * @covers PHPUnit_Framework_Constraint_IsNull
1450 * @covers PHPUnit_Framework_Assert::isNull
1451 * @covers PHPUnit_Framework_Constraint::count
1452 * @covers PHPUnit_Framework_TestFailure::exceptionToString
1454 public function testConstraintIsNull()
1456 $constraint = PHPUnit_Framework_Assert::isNull();
1458 $this->assertFalse($constraint->evaluate(0, '', true));
1459 $this->assertTrue($constraint->evaluate(null, '', true));
1460 $this->assertEquals('is null', $constraint->toString());
1461 $this->assertEquals(1, count($constraint));
1464 $constraint->evaluate(0);
1465 } catch (PHPUnit_Framework_ExpectationFailedException $e) {
1466 $this->assertEquals(<<<EOF
1467 Failed asserting that 0 is null.
1471 PHPUnit_Framework_TestFailure::exceptionToString($e)
1481 * @covers PHPUnit_Framework_Constraint_IsNull
1482 * @covers PHPUnit_Framework_Assert::isNull
1483 * @covers PHPUnit_Framework_TestFailure::exceptionToString
1485 public function testConstraintIsNull2()
1487 $constraint = PHPUnit_Framework_Assert::isNull();
1490 $constraint->evaluate(0, 'custom message');
1491 } catch (PHPUnit_Framework_ExpectationFailedException $e) {
1492 $this->assertEquals(<<<EOF
1494 Failed asserting that 0 is null.
1498 PHPUnit_Framework_TestFailure::exceptionToString($e)
1508 * @covers PHPUnit_Framework_Constraint_IsNull
1509 * @covers PHPUnit_Framework_Constraint_Not
1510 * @covers PHPUnit_Framework_Assert::isNull
1511 * @covers PHPUnit_Framework_Assert::logicalNot
1512 * @covers PHPUnit_Framework_Constraint::count
1513 * @covers PHPUnit_Framework_TestFailure::exceptionToString
1515 public function testConstraintIsNotNull()
1517 $constraint = PHPUnit_Framework_Assert::logicalNot(
1518 PHPUnit_Framework_Assert::isNull()
1521 $this->assertFalse($constraint->evaluate(null, '', true));
1522 $this->assertTrue($constraint->evaluate(0, '', true));
1523 $this->assertEquals('is not null', $constraint->toString());
1524 $this->assertEquals(1, count($constraint));
1527 $constraint->evaluate(null);
1528 } catch (PHPUnit_Framework_ExpectationFailedException $e) {
1529 $this->assertEquals(<<<EOF
1530 Failed asserting that null is not null.
1534 PHPUnit_Framework_TestFailure::exceptionToString($e)
1544 * @covers PHPUnit_Framework_Constraint_IsNull
1545 * @covers PHPUnit_Framework_Constraint_Not
1546 * @covers PHPUnit_Framework_Assert::isNull
1547 * @covers PHPUnit_Framework_Assert::logicalNot
1548 * @covers PHPUnit_Framework_TestFailure::exceptionToString
1550 public function testConstraintIsNotNull2()
1552 $constraint = PHPUnit_Framework_Assert::logicalNot(
1553 PHPUnit_Framework_Assert::isNull()
1557 $constraint->evaluate(null, 'custom message');
1558 } catch (PHPUnit_Framework_ExpectationFailedException $e) {
1559 $this->assertEquals(<<<EOF
1561 Failed asserting that null is not null.
1565 PHPUnit_Framework_TestFailure::exceptionToString($e)
1575 * @covers PHPUnit_Framework_Constraint_LessThan
1576 * @covers PHPUnit_Framework_Assert::lessThan
1577 * @covers PHPUnit_Framework_Constraint::count
1578 * @covers PHPUnit_Framework_TestFailure::exceptionToString
1580 public function testConstraintLessThan()
1582 $constraint = PHPUnit_Framework_Assert::lessThan(1);
1584 $this->assertTrue($constraint->evaluate(0, '', true));
1585 $this->assertFalse($constraint->evaluate(1, '', true));
1586 $this->assertEquals('is less than 1', $constraint->toString());
1587 $this->assertEquals(1, count($constraint));
1590 $constraint->evaluate(1);
1591 } catch (PHPUnit_Framework_ExpectationFailedException $e) {
1592 $this->assertEquals(
1594 Failed asserting that 1 is less than 1.
1598 PHPUnit_Framework_TestFailure::exceptionToString($e)
1608 * @covers PHPUnit_Framework_Constraint_LessThan
1609 * @covers PHPUnit_Framework_Assert::lessThan
1610 * @covers PHPUnit_Framework_TestFailure::exceptionToString
1612 public function testConstraintLessThan2()
1614 $constraint = PHPUnit_Framework_Assert::lessThan(1);
1617 $constraint->evaluate(1, 'custom message');
1618 } catch (PHPUnit_Framework_ExpectationFailedException $e) {
1619 $this->assertEquals(
1622 Failed asserting that 1 is less than 1.
1626 PHPUnit_Framework_TestFailure::exceptionToString($e)
1636 * @covers PHPUnit_Framework_Constraint_LessThan
1637 * @covers PHPUnit_Framework_Constraint_Not
1638 * @covers PHPUnit_Framework_Assert::lessThan
1639 * @covers PHPUnit_Framework_Assert::logicalNot
1640 * @covers PHPUnit_Framework_TestFailure::exceptionToString
1642 public function testConstraintNotLessThan()
1644 $constraint = PHPUnit_Framework_Assert::logicalNot(
1645 PHPUnit_Framework_Assert::lessThan(1)
1648 $this->assertTrue($constraint->evaluate(1, '', true));
1649 $this->assertFalse($constraint->evaluate(0, '', true));
1650 $this->assertEquals('is not less than 1', $constraint->toString());
1651 $this->assertEquals(1, count($constraint));
1654 $constraint->evaluate(0);
1655 } catch (PHPUnit_Framework_ExpectationFailedException $e) {
1656 $this->assertEquals(
1658 Failed asserting that 0 is not less than 1.
1662 PHPUnit_Framework_TestFailure::exceptionToString($e)
1672 * @covers PHPUnit_Framework_Constraint_LessThan
1673 * @covers PHPUnit_Framework_Constraint_Not
1674 * @covers PHPUnit_Framework_Assert::lessThan
1675 * @covers PHPUnit_Framework_Assert::logicalNot
1676 * @covers PHPUnit_Framework_TestFailure::exceptionToString
1678 public function testConstraintNotLessThan2()
1680 $constraint = PHPUnit_Framework_Assert::logicalNot(
1681 PHPUnit_Framework_Assert::lessThan(1)
1685 $constraint->evaluate(0, 'custom message');
1686 } catch (PHPUnit_Framework_ExpectationFailedException $e) {
1687 $this->assertEquals(
1690 Failed asserting that 0 is not less than 1.
1694 PHPUnit_Framework_TestFailure::exceptionToString($e)
1704 * @covers PHPUnit_Framework_Constraint_IsEqual
1705 * @covers PHPUnit_Framework_Constraint_LessThan
1706 * @covers PHPUnit_Framework_Constraint_Or
1707 * @covers PHPUnit_Framework_Assert::lessThanOrEqual
1708 * @covers PHPUnit_Framework_TestFailure::exceptionToString
1710 public function testConstraintLessThanOrEqual()
1712 $constraint = PHPUnit_Framework_Assert::lessThanOrEqual(1);
1714 $this->assertTrue($constraint->evaluate(1, '', true));
1715 $this->assertFalse($constraint->evaluate(2, '', true));
1716 $this->assertEquals('is equal to 1 or is less than 1', $constraint->toString());
1717 $this->assertEquals(2, count($constraint));
1720 $constraint->evaluate(2);
1721 } catch (PHPUnit_Framework_ExpectationFailedException $e) {
1722 $this->assertEquals(
1724 Failed asserting that 2 is equal to 1 or is less than 1.
1728 PHPUnit_Framework_TestFailure::exceptionToString($e)
1738 * @covers PHPUnit_Framework_Constraint_Callback
1740 public function testConstraintCallback()
1742 $closureReflect = function ($parameter) {
1746 $closureWithoutParameter = function () {
1750 $constraint = PHPUnit_Framework_Assert::callback($closureWithoutParameter);
1751 $this->assertTrue($constraint->evaluate('', '', true));
1753 $constraint = PHPUnit_Framework_Assert::callback($closureReflect);
1754 $this->assertTrue($constraint->evaluate(true, '', true));
1755 $this->assertFalse($constraint->evaluate(false, '', true));
1757 $callback = array($this, 'callbackReturningTrue');
1758 $constraint = PHPUnit_Framework_Assert::callback($callback);
1759 $this->assertTrue($constraint->evaluate(false, '', true));
1761 $callback = array('Framework_ConstraintTest', 'staticCallbackReturningTrue');
1762 $constraint = PHPUnit_Framework_Assert::callback($callback);
1763 $this->assertTrue($constraint->evaluate(null, '', true));
1765 $this->assertEquals('is accepted by specified callback', $constraint->toString());
1769 * @covers PHPUnit_Framework_Constraint_Callback
1770 * @expectedException PHPUnit_Framework_ExpectationFailedException
1771 * @expectedExceptionMessage Failed asserting that 'This fails' is accepted by specified callback.
1773 public function testConstraintCallbackFailure()
1775 $constraint = PHPUnit_Framework_Assert::callback(function () {
1778 $constraint->evaluate('This fails');
1781 public function callbackReturningTrue()
1786 public static function staticCallbackReturningTrue()
1792 * @covers PHPUnit_Framework_Constraint_IsEqual
1793 * @covers PHPUnit_Framework_Constraint_LessThan
1794 * @covers PHPUnit_Framework_Constraint_Or
1795 * @covers PHPUnit_Framework_Assert::lessThanOrEqual
1796 * @covers PHPUnit_Framework_TestFailure::exceptionToString
1798 public function testConstraintLessThanOrEqual2()
1800 $constraint = PHPUnit_Framework_Assert::lessThanOrEqual(1);
1803 $constraint->evaluate(2, 'custom message');
1804 } catch (PHPUnit_Framework_ExpectationFailedException $e) {
1805 $this->assertEquals(
1808 Failed asserting that 2 is equal to 1 or is less than 1.
1812 PHPUnit_Framework_TestFailure::exceptionToString($e)
1822 * @covers PHPUnit_Framework_Constraint_IsEqual
1823 * @covers PHPUnit_Framework_Constraint_LessThan
1824 * @covers PHPUnit_Framework_Constraint_Or
1825 * @covers PHPUnit_Framework_Constraint_Not
1826 * @covers PHPUnit_Framework_Assert::lessThanOrEqual
1827 * @covers PHPUnit_Framework_Assert::logicalNot
1828 * @covers PHPUnit_Framework_TestFailure::exceptionToString
1830 public function testConstraintNotLessThanOrEqual()
1832 $constraint = PHPUnit_Framework_Assert::logicalNot(
1833 PHPUnit_Framework_Assert::lessThanOrEqual(1)
1836 $this->assertTrue($constraint->evaluate(2, '', true));
1837 $this->assertFalse($constraint->evaluate(1, '', true));
1838 $this->assertEquals('not( is equal to 1 or is less than 1 )', $constraint->toString());
1839 $this->assertEquals(2, count($constraint));
1842 $constraint->evaluate(1);
1843 } catch (PHPUnit_Framework_ExpectationFailedException $e) {
1844 $this->assertEquals(
1846 Failed asserting that not( 1 is equal to 1 or is less than 1 ).
1850 PHPUnit_Framework_TestFailure::exceptionToString($e)
1860 * @covers PHPUnit_Framework_Constraint_IsEqual
1861 * @covers PHPUnit_Framework_Constraint_LessThan
1862 * @covers PHPUnit_Framework_Constraint_Or
1863 * @covers PHPUnit_Framework_Constraint_Not
1864 * @covers PHPUnit_Framework_Assert::lessThanOrEqual
1865 * @covers PHPUnit_Framework_Assert::logicalNot
1866 * @covers PHPUnit_Framework_TestFailure::exceptionToString
1868 public function testConstraintNotLessThanOrEqual2()
1870 $constraint = PHPUnit_Framework_Assert::logicalNot(
1871 PHPUnit_Framework_Assert::lessThanOrEqual(1)
1875 $constraint->evaluate(1, 'custom message');
1876 } catch (PHPUnit_Framework_ExpectationFailedException $e) {
1877 $this->assertEquals(
1880 Failed asserting that not( 1 is equal to 1 or is less than 1 ).
1884 PHPUnit_Framework_TestFailure::exceptionToString($e)
1894 * @covers PHPUnit_Framework_Constraint_ClassHasAttribute
1895 * @covers PHPUnit_Framework_Assert::classHasAttribute
1896 * @covers PHPUnit_Framework_Constraint::count
1897 * @covers PHPUnit_Framework_TestFailure::exceptionToString
1899 public function testConstraintClassHasAttribute()
1901 $constraint = PHPUnit_Framework_Assert::classHasAttribute('privateAttribute');
1903 $this->assertTrue($constraint->evaluate('ClassWithNonPublicAttributes', '', true));
1904 $this->assertFalse($constraint->evaluate('stdClass', '', true));
1905 $this->assertEquals('has attribute "privateAttribute"', $constraint->toString());
1906 $this->assertEquals(1, count($constraint));
1909 $constraint->evaluate('stdClass');
1910 } catch (PHPUnit_Framework_ExpectationFailedException $e) {
1911 $this->assertEquals(
1913 Failed asserting that class "stdClass" has attribute "privateAttribute".
1917 PHPUnit_Framework_TestFailure::exceptionToString($e)
1927 * @covers PHPUnit_Framework_Constraint_ClassHasAttribute
1928 * @covers PHPUnit_Framework_Assert::classHasAttribute
1929 * @covers PHPUnit_Framework_TestFailure::exceptionToString
1931 public function testConstraintClassHasAttribute2()
1933 $constraint = PHPUnit_Framework_Assert::classHasAttribute('privateAttribute');
1936 $constraint->evaluate('stdClass', 'custom message');
1937 } catch (PHPUnit_Framework_ExpectationFailedException $e) {
1938 $this->assertEquals(<<<EOF
1940 Failed asserting that class "stdClass" has attribute "privateAttribute".
1944 PHPUnit_Framework_TestFailure::exceptionToString($e)
1954 * @covers PHPUnit_Framework_Constraint_ClassHasAttribute
1955 * @covers PHPUnit_Framework_Constraint_Not
1956 * @covers PHPUnit_Framework_Assert::classHasAttribute
1957 * @covers PHPUnit_Framework_Assert::logicalNot
1958 * @covers PHPUnit_Framework_TestFailure::exceptionToString
1960 public function testConstraintClassNotHasAttribute()
1962 $constraint = PHPUnit_Framework_Assert::logicalNot(
1963 PHPUnit_Framework_Assert::classHasAttribute('privateAttribute')
1966 $this->assertTrue($constraint->evaluate('stdClass', '', true));
1967 $this->assertFalse($constraint->evaluate('ClassWithNonPublicAttributes', '', true));
1968 $this->assertEquals('does not have attribute "privateAttribute"', $constraint->toString());
1969 $this->assertEquals(1, count($constraint));
1972 $constraint->evaluate('ClassWithNonPublicAttributes');
1973 } catch (PHPUnit_Framework_ExpectationFailedException $e) {
1974 $this->assertEquals(
1976 Failed asserting that class "ClassWithNonPublicAttributes" does not have attribute "privateAttribute".
1980 PHPUnit_Framework_TestFailure::exceptionToString($e)
1990 * @covers PHPUnit_Framework_Constraint_ClassHasAttribute
1991 * @covers PHPUnit_Framework_Constraint_Not
1992 * @covers PHPUnit_Framework_Assert::classHasAttribute
1993 * @covers PHPUnit_Framework_Assert::logicalNot
1994 * @covers PHPUnit_Framework_TestFailure::exceptionToString
1996 public function testConstraintClassNotHasAttribute2()
1998 $constraint = PHPUnit_Framework_Assert::logicalNot(
1999 PHPUnit_Framework_Assert::classHasAttribute('privateAttribute')
2003 $constraint->evaluate('ClassWithNonPublicAttributes', 'custom message');
2004 } catch (PHPUnit_Framework_ExpectationFailedException $e) {
2005 $this->assertEquals(<<<EOF
2007 Failed asserting that class "ClassWithNonPublicAttributes" does not have attribute "privateAttribute".
2011 PHPUnit_Framework_TestFailure::exceptionToString($e)
2021 * @covers PHPUnit_Framework_Constraint_ClassHasStaticAttribute
2022 * @covers PHPUnit_Framework_Assert::classHasStaticAttribute
2023 * @covers PHPUnit_Framework_Constraint::count
2024 * @covers PHPUnit_Framework_TestFailure::exceptionToString
2026 public function testConstraintClassHasStaticAttribute()
2028 $constraint = PHPUnit_Framework_Assert::classHasStaticAttribute('privateStaticAttribute');
2030 $this->assertTrue($constraint->evaluate('ClassWithNonPublicAttributes', '', true));
2031 $this->assertFalse($constraint->evaluate('stdClass', '', true));
2032 $this->assertEquals('has static attribute "privateStaticAttribute"', $constraint->toString());
2033 $this->assertEquals(1, count($constraint));
2036 $constraint->evaluate('stdClass');
2037 } catch (PHPUnit_Framework_ExpectationFailedException $e) {
2038 $this->assertEquals(
2040 Failed asserting that class "stdClass" has static attribute "privateStaticAttribute".
2044 PHPUnit_Framework_TestFailure::exceptionToString($e)
2054 * @covers PHPUnit_Framework_Constraint_ClassHasStaticAttribute
2055 * @covers PHPUnit_Framework_Assert::classHasStaticAttribute
2056 * @covers PHPUnit_Framework_TestFailure::exceptionToString
2058 public function testConstraintClassHasStaticAttribute2()
2060 $constraint = PHPUnit_Framework_Assert::classHasStaticAttribute('foo');
2063 $constraint->evaluate('stdClass', 'custom message');
2064 } catch (PHPUnit_Framework_ExpectationFailedException $e) {
2065 $this->assertEquals(<<<EOF
2067 Failed asserting that class "stdClass" has static attribute "foo".
2071 PHPUnit_Framework_TestFailure::exceptionToString($e)
2081 * @covers PHPUnit_Framework_Constraint_ClassHasStaticAttribute
2082 * @covers PHPUnit_Framework_Constraint_Not
2083 * @covers PHPUnit_Framework_Assert::classHasStaticAttribute
2084 * @covers PHPUnit_Framework_Assert::logicalNot
2085 * @covers PHPUnit_Framework_TestFailure::exceptionToString
2087 public function testConstraintClassNotHasStaticAttribute()
2089 $constraint = PHPUnit_Framework_Assert::logicalNot(
2090 PHPUnit_Framework_Assert::classHasStaticAttribute('privateStaticAttribute')
2093 $this->assertTrue($constraint->evaluate('stdClass', '', true));
2094 $this->assertFalse($constraint->evaluate('ClassWithNonPublicAttributes', '', true));
2095 $this->assertEquals('does not have static attribute "privateStaticAttribute"', $constraint->toString());
2096 $this->assertEquals(1, count($constraint));
2099 $constraint->evaluate('ClassWithNonPublicAttributes');
2100 } catch (PHPUnit_Framework_ExpectationFailedException $e) {
2101 $this->assertEquals(
2103 Failed asserting that class "ClassWithNonPublicAttributes" does not have static attribute "privateStaticAttribute".
2107 PHPUnit_Framework_TestFailure::exceptionToString($e)
2117 * @covers PHPUnit_Framework_Constraint_ClassHasStaticAttribute
2118 * @covers PHPUnit_Framework_Constraint_Not
2119 * @covers PHPUnit_Framework_Assert::classHasStaticAttribute
2120 * @covers PHPUnit_Framework_Assert::logicalNot
2121 * @covers PHPUnit_Framework_TestFailure::exceptionToString
2123 public function testConstraintClassNotHasStaticAttribute2()
2125 $constraint = PHPUnit_Framework_Assert::logicalNot(
2126 PHPUnit_Framework_Assert::classHasStaticAttribute('privateStaticAttribute')
2130 $constraint->evaluate('ClassWithNonPublicAttributes', 'custom message');
2131 } catch (PHPUnit_Framework_ExpectationFailedException $e) {
2132 $this->assertEquals(<<<EOF
2134 Failed asserting that class "ClassWithNonPublicAttributes" does not have static attribute "privateStaticAttribute".
2138 PHPUnit_Framework_TestFailure::exceptionToString($e)
2148 * @covers PHPUnit_Framework_Constraint_ObjectHasAttribute
2149 * @covers PHPUnit_Framework_Assert::objectHasAttribute
2150 * @covers PHPUnit_Framework_Constraint::count
2151 * @covers PHPUnit_Framework_TestFailure::exceptionToString
2153 public function testConstraintObjectHasAttribute()
2155 $constraint = PHPUnit_Framework_Assert::objectHasAttribute('privateAttribute');
2157 $this->assertTrue($constraint->evaluate(new ClassWithNonPublicAttributes, '', true));
2158 $this->assertFalse($constraint->evaluate(new stdClass, '', true));
2159 $this->assertEquals('has attribute "privateAttribute"', $constraint->toString());
2160 $this->assertEquals(1, count($constraint));
2163 $constraint->evaluate(new stdClass);
2164 } catch (PHPUnit_Framework_ExpectationFailedException $e) {
2165 $this->assertEquals(
2167 Failed asserting that object of class "stdClass" has attribute "privateAttribute".
2171 PHPUnit_Framework_TestFailure::exceptionToString($e)
2181 * @covers PHPUnit_Framework_Constraint_ObjectHasAttribute
2182 * @covers PHPUnit_Framework_Assert::objectHasAttribute
2183 * @covers PHPUnit_Framework_TestFailure::exceptionToString
2185 public function testConstraintObjectHasAttribute2()
2187 $constraint = PHPUnit_Framework_Assert::objectHasAttribute('privateAttribute');
2190 $constraint->evaluate(new stdClass, 'custom message');
2191 } catch (PHPUnit_Framework_ExpectationFailedException $e) {
2192 $this->assertEquals(<<<EOF
2194 Failed asserting that object of class "stdClass" has attribute "privateAttribute".
2198 PHPUnit_Framework_TestFailure::exceptionToString($e)
2208 * @covers PHPUnit_Framework_Constraint_ObjectHasAttribute
2209 * @covers PHPUnit_Framework_Constraint_Not
2210 * @covers PHPUnit_Framework_Assert::objectHasAttribute
2211 * @covers PHPUnit_Framework_Assert::logicalNot
2212 * @covers PHPUnit_Framework_TestFailure::exceptionToString
2214 public function testConstraintObjectNotHasAttribute()
2216 $constraint = PHPUnit_Framework_Assert::logicalNot(
2217 PHPUnit_Framework_Assert::objectHasAttribute('privateAttribute')
2220 $this->assertTrue($constraint->evaluate(new stdClass, '', true));
2221 $this->assertFalse($constraint->evaluate(new ClassWithNonPublicAttributes, '', true));
2222 $this->assertEquals('does not have attribute "privateAttribute"', $constraint->toString());
2223 $this->assertEquals(1, count($constraint));
2226 $constraint->evaluate(new ClassWithNonPublicAttributes);
2227 } catch (PHPUnit_Framework_ExpectationFailedException $e) {
2228 $this->assertEquals(
2230 Failed asserting that object of class "ClassWithNonPublicAttributes" does not have attribute "privateAttribute".
2234 PHPUnit_Framework_TestFailure::exceptionToString($e)
2244 * @covers PHPUnit_Framework_Constraint_ObjectHasAttribute
2245 * @covers PHPUnit_Framework_Constraint_Not
2246 * @covers PHPUnit_Framework_Assert::objectHasAttribute
2247 * @covers PHPUnit_Framework_Assert::logicalNot
2248 * @covers PHPUnit_Framework_TestFailure::exceptionToString
2250 public function testConstraintObjectNotHasAttribute2()
2252 $constraint = PHPUnit_Framework_Assert::logicalNot(
2253 PHPUnit_Framework_Assert::objectHasAttribute('privateAttribute')
2257 $constraint->evaluate(new ClassWithNonPublicAttributes, 'custom message');
2258 } catch (PHPUnit_Framework_ExpectationFailedException $e) {
2259 $this->assertEquals(<<<EOF
2261 Failed asserting that object of class "ClassWithNonPublicAttributes" does not have attribute "privateAttribute".
2265 PHPUnit_Framework_TestFailure::exceptionToString($e)
2275 * @covers PHPUnit_Framework_Constraint_PCREMatch
2276 * @covers PHPUnit_Framework_Assert::matchesRegularExpression
2277 * @covers PHPUnit_Framework_Constraint::count
2278 * @covers PHPUnit_Framework_TestFailure::exceptionToString
2280 public function testConstraintPCREMatch()
2282 $constraint = PHPUnit_Framework_Assert::matchesRegularExpression('/foo/');
2284 $this->assertFalse($constraint->evaluate('barbazbar', '', true));
2285 $this->assertTrue($constraint->evaluate('barfoobar', '', true));
2286 $this->assertEquals('matches PCRE pattern "/foo/"', $constraint->toString());
2287 $this->assertEquals(1, count($constraint));
2290 $constraint->evaluate('barbazbar');
2291 } catch (PHPUnit_Framework_ExpectationFailedException $e) {
2292 $this->assertEquals(
2294 Failed asserting that 'barbazbar' matches PCRE pattern "/foo/".
2298 PHPUnit_Framework_TestFailure::exceptionToString($e)
2308 * @covers PHPUnit_Framework_Constraint_PCREMatch
2309 * @covers PHPUnit_Framework_Assert::matchesRegularExpression
2310 * @covers PHPUnit_Framework_TestFailure::exceptionToString
2312 public function testConstraintPCREMatch2()
2314 $constraint = PHPUnit_Framework_Assert::matchesRegularExpression('/foo/');
2317 $constraint->evaluate('barbazbar', 'custom message');
2318 } catch (PHPUnit_Framework_ExpectationFailedException $e) {
2319 $this->assertEquals(<<<EOF
2321 Failed asserting that 'barbazbar' matches PCRE pattern "/foo/".
2325 PHPUnit_Framework_TestFailure::exceptionToString($e)
2335 * @covers PHPUnit_Framework_Constraint_PCREMatch
2336 * @covers PHPUnit_Framework_Constraint_Not
2337 * @covers PHPUnit_Framework_Assert::matchesRegularExpression
2338 * @covers PHPUnit_Framework_Assert::logicalNot
2339 * @covers PHPUnit_Framework_TestFailure::exceptionToString
2341 public function testConstraintPCRENotMatch()
2343 $constraint = PHPUnit_Framework_Assert::logicalNot(
2344 PHPUnit_Framework_Assert::matchesRegularExpression('/foo/')
2347 $this->assertTrue($constraint->evaluate('barbazbar', '', true));
2348 $this->assertFalse($constraint->evaluate('barfoobar', '', true));
2349 $this->assertEquals('does not match PCRE pattern "/foo/"', $constraint->toString());
2350 $this->assertEquals(1, count($constraint));
2353 $constraint->evaluate('barfoobar');
2354 } catch (PHPUnit_Framework_ExpectationFailedException $e) {
2355 $this->assertEquals(
2357 Failed asserting that 'barfoobar' does not match PCRE pattern "/foo/".
2361 PHPUnit_Framework_TestFailure::exceptionToString($e)
2371 * @covers PHPUnit_Framework_Constraint_PCREMatch
2372 * @covers PHPUnit_Framework_Constraint_Not
2373 * @covers PHPUnit_Framework_Assert::matchesRegularExpression
2374 * @covers PHPUnit_Framework_Assert::logicalNot
2375 * @covers PHPUnit_Framework_TestFailure::exceptionToString
2377 public function testConstraintPCRENotMatch2()
2379 $constraint = PHPUnit_Framework_Assert::logicalNot(
2380 PHPUnit_Framework_Assert::matchesRegularExpression('/foo/')
2384 $constraint->evaluate('barfoobar', 'custom message');
2385 } catch (PHPUnit_Framework_ExpectationFailedException $e) {
2386 $this->assertEquals(<<<EOF
2388 Failed asserting that 'barfoobar' does not match PCRE pattern "/foo/".
2392 PHPUnit_Framework_TestFailure::exceptionToString($e)
2402 * @covers PHPUnit_Framework_Constraint_StringMatches
2403 * @covers PHPUnit_Framework_Assert::matches
2404 * @covers PHPUnit_Framework_Constraint::count
2406 public function testConstraintStringMatches()
2408 $constraint = PHPUnit_Framework_Assert::matches('*%c*');
2409 $this->assertFalse($constraint->evaluate('**', '', true));
2410 $this->assertTrue($constraint->evaluate('***', '', true));
2411 $this->assertEquals('matches PCRE pattern "/^\*.\*$/s"', $constraint->toString());
2412 $this->assertEquals(1, count($constraint));
2416 * @covers PHPUnit_Framework_Constraint_StringMatches
2417 * @covers PHPUnit_Framework_Assert::matches
2418 * @covers PHPUnit_Framework_Constraint::count
2420 public function testConstraintStringMatches2()
2422 $constraint = PHPUnit_Framework_Assert::matches('*%s*');
2423 $this->assertFalse($constraint->evaluate('**', '', true));
2424 $this->assertTrue($constraint->evaluate('***', '', true));
2425 $this->assertEquals('matches PCRE pattern "/^\*[^\r\n]+\*$/s"', $constraint->toString());
2426 $this->assertEquals(1, count($constraint));
2430 * @covers PHPUnit_Framework_Constraint_StringMatches
2431 * @covers PHPUnit_Framework_Assert::matches
2432 * @covers PHPUnit_Framework_Constraint::count
2434 public function testConstraintStringMatches3()
2436 $constraint = PHPUnit_Framework_Assert::matches('*%i*');
2437 $this->assertFalse($constraint->evaluate('**', '', true));
2438 $this->assertTrue($constraint->evaluate('*0*', '', true));
2439 $this->assertEquals('matches PCRE pattern "/^\*[+-]?\d+\*$/s"', $constraint->toString());
2440 $this->assertEquals(1, count($constraint));
2444 * @covers PHPUnit_Framework_Constraint_StringMatches
2445 * @covers PHPUnit_Framework_Assert::matches
2446 * @covers PHPUnit_Framework_Constraint::count
2448 public function testConstraintStringMatches4()
2450 $constraint = PHPUnit_Framework_Assert::matches('*%d*');
2451 $this->assertFalse($constraint->evaluate('**', '', true));
2452 $this->assertTrue($constraint->evaluate('*0*', '', true));
2453 $this->assertEquals('matches PCRE pattern "/^\*\d+\*$/s"', $constraint->toString());
2454 $this->assertEquals(1, count($constraint));
2458 * @covers PHPUnit_Framework_Constraint_StringMatches
2459 * @covers PHPUnit_Framework_Assert::matches
2460 * @covers PHPUnit_Framework_Constraint::count
2462 public function testConstraintStringMatches5()
2464 $constraint = PHPUnit_Framework_Assert::matches('*%x*');
2465 $this->assertFalse($constraint->evaluate('**', '', true));
2466 $this->assertTrue($constraint->evaluate('*0f0f0f*', '', true));
2467 $this->assertEquals('matches PCRE pattern "/^\*[0-9a-fA-F]+\*$/s"', $constraint->toString());
2468 $this->assertEquals(1, count($constraint));
2472 * @covers PHPUnit_Framework_Constraint_StringMatches
2473 * @covers PHPUnit_Framework_Assert::matches
2474 * @covers PHPUnit_Framework_Constraint::count
2476 public function testConstraintStringMatches6()
2478 $constraint = PHPUnit_Framework_Assert::matches('*%f*');
2479 $this->assertFalse($constraint->evaluate('**', '', true));
2480 $this->assertTrue($constraint->evaluate('*1.0*', '', true));
2481 $this->assertEquals('matches PCRE pattern "/^\*[+-]?\.?\d+\.?\d*(?:[Ee][+-]?\d+)?\*$/s"', $constraint->toString());
2482 $this->assertEquals(1, count($constraint));
2486 * @covers PHPUnit_Framework_Constraint_StringStartsWith
2487 * @covers PHPUnit_Framework_Assert::stringStartsWith
2488 * @covers PHPUnit_Framework_Constraint::count
2489 * @covers PHPUnit_Framework_TestFailure::exceptionToString
2491 public function testConstraintStringStartsWith()
2493 $constraint = PHPUnit_Framework_Assert::stringStartsWith('prefix');
2495 $this->assertFalse($constraint->evaluate('foo', '', true));
2496 $this->assertTrue($constraint->evaluate('prefixfoo', '', true));
2497 $this->assertEquals('starts with "prefix"', $constraint->toString());
2498 $this->assertEquals(1, count($constraint));
2501 $constraint->evaluate('foo');
2502 } catch (PHPUnit_Framework_ExpectationFailedException $e) {
2503 $this->assertEquals(
2505 Failed asserting that 'foo' starts with "prefix".
2509 PHPUnit_Framework_TestFailure::exceptionToString($e)
2519 * @covers PHPUnit_Framework_Constraint_StringStartsWith
2520 * @covers PHPUnit_Framework_Assert::stringStartsWith
2521 * @covers PHPUnit_Framework_TestFailure::exceptionToString
2523 public function testConstraintStringStartsWith2()
2525 $constraint = PHPUnit_Framework_Assert::stringStartsWith('prefix');
2528 $constraint->evaluate('foo', 'custom message');
2529 } catch (PHPUnit_Framework_ExpectationFailedException $e) {
2530 $this->assertEquals(
2532 custom message\nFailed asserting that 'foo' starts with "prefix".
2536 PHPUnit_Framework_TestFailure::exceptionToString($e)
2546 * @covers PHPUnit_Framework_Constraint_StringStartsWith
2547 * @covers PHPUnit_Framework_Constraint_Not
2548 * @covers PHPUnit_Framework_Assert::stringStartsWith
2549 * @covers PHPUnit_Framework_Assert::logicalNot
2550 * @covers PHPUnit_Framework_TestFailure::exceptionToString
2552 public function testConstraintStringStartsNotWith()
2554 $constraint = PHPUnit_Framework_Assert::logicalNot(
2555 PHPUnit_Framework_Assert::stringStartsWith('prefix')
2558 $this->assertTrue($constraint->evaluate('foo', '', true));
2559 $this->assertFalse($constraint->evaluate('prefixfoo', '', true));
2560 $this->assertEquals('starts not with "prefix"', $constraint->toString());
2561 $this->assertEquals(1, count($constraint));
2564 $constraint->evaluate('prefixfoo');
2565 } catch (PHPUnit_Framework_ExpectationFailedException $e) {
2566 $this->assertEquals(
2568 Failed asserting that 'prefixfoo' starts not with "prefix".
2572 PHPUnit_Framework_TestFailure::exceptionToString($e)
2582 * @covers PHPUnit_Framework_Constraint_StringStartsWith
2583 * @covers PHPUnit_Framework_Assert::stringStartsWith
2584 * @covers PHPUnit_Framework_TestFailure::exceptionToString
2586 public function testConstraintStringStartsNotWith2()
2588 $constraint = PHPUnit_Framework_Assert::logicalNot(
2589 PHPUnit_Framework_Assert::stringStartsWith('prefix')
2593 $constraint->evaluate('prefixfoo', 'custom message');
2594 } catch (PHPUnit_Framework_ExpectationFailedException $e) {
2595 $this->assertEquals(
2598 Failed asserting that 'prefixfoo' starts not with "prefix".
2602 PHPUnit_Framework_TestFailure::exceptionToString($e)
2612 * @covers PHPUnit_Framework_Constraint_StringContains
2613 * @covers PHPUnit_Framework_Assert::stringContains
2614 * @covers PHPUnit_Framework_Constraint::count
2615 * @covers PHPUnit_Framework_TestFailure::exceptionToString
2617 public function testConstraintStringContains()
2619 $constraint = PHPUnit_Framework_Assert::stringContains('foo');
2621 $this->assertFalse($constraint->evaluate('barbazbar', '', true));
2622 $this->assertTrue($constraint->evaluate('barfoobar', '', true));
2623 $this->assertEquals('contains "foo"', $constraint->toString());
2624 $this->assertEquals(1, count($constraint));
2627 $constraint->evaluate('barbazbar');
2628 } catch (PHPUnit_Framework_ExpectationFailedException $e) {
2629 $this->assertEquals(
2631 Failed asserting that 'barbazbar' contains "foo".
2635 PHPUnit_Framework_TestFailure::exceptionToString($e)
2645 * @covers PHPUnit_Framework_Constraint_StringContains
2646 * @covers PHPUnit_Framework_Assert::stringContains
2647 * @covers PHPUnit_Framework_TestFailure::exceptionToString
2649 public function testConstraintStringContains2()
2651 $constraint = PHPUnit_Framework_Assert::stringContains('foo');
2654 $constraint->evaluate('barbazbar', 'custom message');
2655 } catch (PHPUnit_Framework_ExpectationFailedException $e) {
2656 $this->assertEquals(
2659 Failed asserting that 'barbazbar' contains "foo".
2663 PHPUnit_Framework_TestFailure::exceptionToString($e)
2673 * @covers PHPUnit_Framework_Constraint_StringContains
2674 * @covers PHPUnit_Framework_Constraint_Not
2675 * @covers PHPUnit_Framework_Assert::stringContains
2676 * @covers PHPUnit_Framework_Assert::logicalNot
2677 * @covers PHPUnit_Framework_TestFailure::exceptionToString
2679 public function testConstraintStringNotContains()
2681 $constraint = PHPUnit_Framework_Assert::logicalNot(
2682 PHPUnit_Framework_Assert::stringContains('foo')
2685 $this->assertTrue($constraint->evaluate('barbazbar', '', true));
2686 $this->assertFalse($constraint->evaluate('barfoobar', '', true));
2687 $this->assertEquals('does not contain "foo"', $constraint->toString());
2688 $this->assertEquals(1, count($constraint));
2691 $constraint->evaluate('barfoobar');
2692 } catch (PHPUnit_Framework_ExpectationFailedException $e) {
2693 $this->assertEquals(
2695 Failed asserting that 'barfoobar' does not contain "foo".
2699 PHPUnit_Framework_TestFailure::exceptionToString($e)
2709 * @covers PHPUnit_Framework_Constraint_StringContains
2710 * @covers PHPUnit_Framework_Constraint_Not
2711 * @covers PHPUnit_Framework_Assert::stringContains
2712 * @covers PHPUnit_Framework_Assert::logicalNot
2713 * @covers PHPUnit_Framework_TestFailure::exceptionToString
2715 public function testConstraintStringNotContains2()
2717 $constraint = PHPUnit_Framework_Assert::logicalNot(
2718 PHPUnit_Framework_Assert::stringContains('foo')
2722 $constraint->evaluate('barfoobar', 'custom message');
2723 } catch (PHPUnit_Framework_ExpectationFailedException $e) {
2724 $this->assertEquals(
2727 Failed asserting that 'barfoobar' does not contain "foo".
2731 PHPUnit_Framework_TestFailure::exceptionToString($e)
2741 * @covers PHPUnit_Framework_Constraint_StringEndsWith
2742 * @covers PHPUnit_Framework_Assert::stringEndsWith
2743 * @covers PHPUnit_Framework_Constraint::count
2744 * @covers PHPUnit_Framework_TestFailure::exceptionToString
2746 public function testConstraintStringEndsWith()
2748 $constraint = PHPUnit_Framework_Assert::stringEndsWith('suffix');
2750 $this->assertFalse($constraint->evaluate('foo', '', true));
2751 $this->assertTrue($constraint->evaluate('foosuffix', '', true));
2752 $this->assertEquals('ends with "suffix"', $constraint->toString());
2753 $this->assertEquals(1, count($constraint));
2756 $constraint->evaluate('foo');
2757 } catch (PHPUnit_Framework_ExpectationFailedException $e) {
2758 $this->assertEquals(
2760 Failed asserting that 'foo' ends with "suffix".
2764 PHPUnit_Framework_TestFailure::exceptionToString($e)
2774 * @covers PHPUnit_Framework_Constraint_StringEndsWith
2775 * @covers PHPUnit_Framework_Assert::stringEndsWith
2776 * @covers PHPUnit_Framework_TestFailure::exceptionToString
2778 public function testConstraintStringEndsWith2()
2780 $constraint = PHPUnit_Framework_Assert::stringEndsWith('suffix');
2783 $constraint->evaluate('foo', 'custom message');
2784 } catch (PHPUnit_Framework_ExpectationFailedException $e) {
2785 $this->assertEquals(
2788 Failed asserting that 'foo' ends with "suffix".
2792 PHPUnit_Framework_TestFailure::exceptionToString($e)
2802 * @covers PHPUnit_Framework_Constraint_StringEndsWith
2803 * @covers PHPUnit_Framework_Constraint_Not
2804 * @covers PHPUnit_Framework_Assert::stringEndsWith
2805 * @covers PHPUnit_Framework_Assert::logicalNot
2806 * @covers PHPUnit_Framework_TestFailure::exceptionToString
2808 public function testConstraintStringEndsNotWith()
2810 $constraint = PHPUnit_Framework_Assert::logicalNot(
2811 PHPUnit_Framework_Assert::stringEndsWith('suffix')
2814 $this->assertTrue($constraint->evaluate('foo', '', true));
2815 $this->assertFalse($constraint->evaluate('foosuffix', '', true));
2816 $this->assertEquals('ends not with "suffix"', $constraint->toString());
2817 $this->assertEquals(1, count($constraint));
2820 $constraint->evaluate('foosuffix');
2821 } catch (PHPUnit_Framework_ExpectationFailedException $e) {
2822 $this->assertEquals(
2824 Failed asserting that 'foosuffix' ends not with "suffix".
2828 PHPUnit_Framework_TestFailure::exceptionToString($e)
2838 * @covers PHPUnit_Framework_Constraint_StringEndsWith
2839 * @covers PHPUnit_Framework_Assert::stringEndsWith
2840 * @covers PHPUnit_Framework_TestFailure::exceptionToString
2842 public function testConstraintStringEndsNotWith2()
2844 $constraint = PHPUnit_Framework_Assert::logicalNot(
2845 PHPUnit_Framework_Assert::stringEndsWith('suffix')
2849 $constraint->evaluate('foosuffix', 'custom message');
2850 } catch (PHPUnit_Framework_ExpectationFailedException $e) {
2851 $this->assertEquals(
2854 Failed asserting that 'foosuffix' ends not with "suffix".
2858 PHPUnit_Framework_TestFailure::exceptionToString($e)
2868 * @covers PHPUnit_Framework_Constraint_TraversableContains
2870 public function testConstraintArrayContainsCheckForObjectIdentity()
2872 // Check for primitive type.
2873 $constraint = new PHPUnit_Framework_Constraint_TraversableContains('foo', true, true);
2875 $this->assertFalse($constraint->evaluate(array(0), '', true));
2876 $this->assertFalse($constraint->evaluate(array(true), '', true));
2879 $constraint = new PHPUnit_Framework_Constraint_TraversableContains('foo');
2881 $this->assertTrue($constraint->evaluate(array(0), '', true));
2882 $this->assertTrue($constraint->evaluate(array(true), '', true));
2886 * @covers PHPUnit_Framework_Constraint_TraversableContains
2887 * @covers PHPUnit_Framework_Constraint::count
2888 * @covers PHPUnit_Framework_TestFailure::exceptionToString
2890 public function testConstraintArrayContains()
2892 $constraint = new PHPUnit_Framework_Constraint_TraversableContains('foo');
2894 $this->assertFalse($constraint->evaluate(array('bar'), '', true));
2895 $this->assertTrue($constraint->evaluate(array('foo'), '', true));
2896 $this->assertEquals("contains 'foo'", $constraint->toString());
2897 $this->assertEquals(1, count($constraint));
2900 $constraint->evaluate(array('bar'));
2901 } catch (PHPUnit_Framework_ExpectationFailedException $e) {
2902 $this->assertEquals(
2904 Failed asserting that an array contains 'foo'.
2908 PHPUnit_Framework_TestFailure::exceptionToString($e)
2918 * @covers PHPUnit_Framework_Constraint_TraversableContains
2919 * @covers PHPUnit_Framework_TestFailure::exceptionToString
2921 public function testConstraintArrayContains2()
2923 $constraint = new PHPUnit_Framework_Constraint_TraversableContains('foo');
2926 $constraint->evaluate(array('bar'), 'custom message');
2927 } catch (PHPUnit_Framework_ExpectationFailedException $e) {
2928 $this->assertEquals(
2931 Failed asserting that an array contains 'foo'.
2935 PHPUnit_Framework_TestFailure::exceptionToString($e)
2945 * @covers PHPUnit_Framework_Constraint_TraversableContains
2946 * @covers PHPUnit_Framework_Constraint_Not
2947 * @covers PHPUnit_Framework_Assert::logicalNot
2948 * @covers PHPUnit_Framework_TestFailure::exceptionToString
2950 public function testConstraintArrayNotContains()
2952 $constraint = PHPUnit_Framework_Assert::logicalNot(
2953 new PHPUnit_Framework_Constraint_TraversableContains('foo')
2956 $this->assertTrue($constraint->evaluate(array('bar'), '', true));
2957 $this->assertFalse($constraint->evaluate(array('foo'), '', true));
2958 $this->assertEquals("does not contain 'foo'", $constraint->toString());
2959 $this->assertEquals(1, count($constraint));
2962 $constraint->evaluate(array('foo'));
2963 } catch (PHPUnit_Framework_ExpectationFailedException $e) {
2964 $this->assertEquals(
2966 Failed asserting that an array does not contain 'foo'.
2970 PHPUnit_Framework_TestFailure::exceptionToString($e)
2980 * @covers PHPUnit_Framework_Constraint_TraversableContains
2981 * @covers PHPUnit_Framework_Constraint_Not
2982 * @covers PHPUnit_Framework_Assert::logicalNot
2983 * @covers PHPUnit_Framework_TestFailure::exceptionToString
2985 public function testConstraintArrayNotContains2()
2987 $constraint = PHPUnit_Framework_Assert::logicalNot(
2988 new PHPUnit_Framework_Constraint_TraversableContains('foo')
2992 $constraint->evaluate(array('foo'), 'custom message');
2993 } catch (PHPUnit_Framework_ExpectationFailedException $e) {
2994 $this->assertEquals(
2997 Failed asserting that an array does not contain 'foo'.
3001 PHPUnit_Framework_TestFailure::exceptionToString($e)
3011 * @covers PHPUnit_Framework_Constraint_TraversableContains
3012 * @covers PHPUnit_Framework_Constraint::count
3013 * @covers PHPUnit_Framework_TestFailure::exceptionToString
3015 public function testConstraintSplObjectStorageContains()
3017 $object = new StdClass;
3018 $constraint = new PHPUnit_Framework_Constraint_TraversableContains($object);
3019 $this->assertStringMatchesFormat('contains stdClass Object &%s ()', $constraint->toString());
3021 $storage = new SplObjectStorage;
3022 $this->assertFalse($constraint->evaluate($storage, '', true));
3024 $storage->attach($object);
3025 $this->assertTrue($constraint->evaluate($storage, '', true));
3028 $constraint->evaluate(new SplObjectStorage);
3029 } catch (PHPUnit_Framework_ExpectationFailedException $e) {
3030 $this->assertStringMatchesFormat(
3032 Failed asserting that a traversable contains stdClass Object &%x ().
3036 PHPUnit_Framework_TestFailure::exceptionToString($e)
3046 * @covers PHPUnit_Framework_Constraint_TraversableContains
3047 * @covers PHPUnit_Framework_TestFailure::exceptionToString
3049 public function testConstraintSplObjectStorageContains2()
3051 $object = new StdClass;
3052 $constraint = new PHPUnit_Framework_Constraint_TraversableContains($object);
3055 $constraint->evaluate(new SplObjectStorage, 'custom message');
3056 } catch (PHPUnit_Framework_ExpectationFailedException $e) {
3057 $this->assertStringMatchesFormat(
3060 Failed asserting that a traversable contains stdClass Object &%x ().
3064 PHPUnit_Framework_TestFailure::exceptionToString($e)
3074 * @covers PHPUnit_Framework_Assert::attributeEqualTo
3075 * @covers PHPUnit_Framework_Constraint_Attribute
3076 * @covers PHPUnit_Framework_TestFailure::exceptionToString
3078 public function testAttributeEqualTo()
3080 $object = new ClassWithNonPublicAttributes;
3081 $constraint = PHPUnit_Framework_Assert::attributeEqualTo('foo', 1);
3083 $this->assertTrue($constraint->evaluate($object, '', true));
3084 $this->assertEquals('attribute "foo" is equal to 1', $constraint->toString());
3085 $this->assertEquals(1, count($constraint));
3087 $constraint = PHPUnit_Framework_Assert::attributeEqualTo('foo', 2);
3089 $this->assertFalse($constraint->evaluate($object, '', true));
3092 $constraint->evaluate($object);
3093 } catch (PHPUnit_Framework_ExpectationFailedException $e) {
3094 $this->assertEquals(
3096 Failed asserting that attribute "foo" is equal to 2.
3100 PHPUnit_Framework_TestFailure::exceptionToString($e)
3110 * @covers PHPUnit_Framework_Assert::attributeEqualTo
3111 * @covers PHPUnit_Framework_Constraint_Attribute
3112 * @covers PHPUnit_Framework_TestFailure::exceptionToString
3114 public function testAttributeEqualTo2()
3116 $object = new ClassWithNonPublicAttributes;
3117 $constraint = PHPUnit_Framework_Assert::attributeEqualTo('foo', 2);
3120 $constraint->evaluate($object, 'custom message');
3121 } catch (PHPUnit_Framework_ExpectationFailedException $e) {
3122 $this->assertEquals(
3124 custom message\nFailed asserting that attribute "foo" is equal to 2.
3128 PHPUnit_Framework_TestFailure::exceptionToString($e)
3138 * @covers PHPUnit_Framework_Assert::attributeEqualTo
3139 * @covers PHPUnit_Framework_Assert::logicalNot
3140 * @covers PHPUnit_Framework_Constraint_Attribute
3141 * @covers PHPUnit_Framework_Constraint_Not
3142 * @covers PHPUnit_Framework_TestFailure::exceptionToString
3144 public function testAttributeNotEqualTo()
3146 $object = new ClassWithNonPublicAttributes;
3147 $constraint = PHPUnit_Framework_Assert::logicalNot(
3148 PHPUnit_Framework_Assert::attributeEqualTo('foo', 2)
3151 $this->assertTrue($constraint->evaluate($object, '', true));
3152 $this->assertEquals('attribute "foo" is not equal to 2', $constraint->toString());
3153 $this->assertEquals(1, count($constraint));
3155 $constraint = PHPUnit_Framework_Assert::logicalNot(
3156 PHPUnit_Framework_Assert::attributeEqualTo('foo', 1)
3159 $this->assertFalse($constraint->evaluate($object, '', true));
3162 $constraint->evaluate($object);
3163 } catch (PHPUnit_Framework_ExpectationFailedException $e) {
3164 $this->assertEquals(
3166 Failed asserting that attribute "foo" is not equal to 1.
3170 PHPUnit_Framework_TestFailure::exceptionToString($e)
3180 * @covers PHPUnit_Framework_Assert::attributeEqualTo
3181 * @covers PHPUnit_Framework_Assert::logicalNot
3182 * @covers PHPUnit_Framework_Constraint_Attribute
3183 * @covers PHPUnit_Framework_Constraint_Not
3184 * @covers PHPUnit_Framework_TestFailure::exceptionToString
3186 public function testAttributeNotEqualTo2()
3188 $object = new ClassWithNonPublicAttributes;
3189 $constraint = PHPUnit_Framework_Assert::logicalNot(
3190 PHPUnit_Framework_Assert::attributeEqualTo('foo', 1)
3194 $constraint->evaluate($object, 'custom message');
3195 } catch (PHPUnit_Framework_ExpectationFailedException $e) {
3196 $this->assertEquals(
3198 custom message\nFailed asserting that attribute "foo" is not equal to 1.
3202 PHPUnit_Framework_TestFailure::exceptionToString($e)
3212 * @covers PHPUnit_Framework_Constraint_IsEmpty
3213 * @covers PHPUnit_Framework_Constraint::count
3214 * @covers PHPUnit_Framework_TestFailure::exceptionToString
3216 public function testConstraintIsEmpty()
3218 $constraint = new PHPUnit_Framework_Constraint_IsEmpty;
3220 $this->assertFalse($constraint->evaluate(array('foo'), '', true));
3221 $this->assertTrue($constraint->evaluate(array(), '', true));
3222 $this->assertFalse($constraint->evaluate(new ArrayObject(array('foo')), '', true));
3223 $this->assertTrue($constraint->evaluate(new ArrayObject(array()), '', true));
3224 $this->assertEquals('is empty', $constraint->toString());
3225 $this->assertEquals(1, count($constraint));
3228 $constraint->evaluate(array('foo'));
3229 } catch (PHPUnit_Framework_ExpectationFailedException $e) {
3230 $this->assertEquals(
3232 Failed asserting that an array is empty.
3236 PHPUnit_Framework_TestFailure::exceptionToString($e)
3246 * @covers PHPUnit_Framework_Constraint_IsEmpty
3247 * @covers PHPUnit_Framework_TestFailure::exceptionToString
3249 public function testConstraintIsEmpty2()
3251 $constraint = new PHPUnit_Framework_Constraint_IsEmpty;
3254 $constraint->evaluate(array('foo'), 'custom message');
3255 } catch (PHPUnit_Framework_ExpectationFailedException $e) {
3256 $this->assertEquals(
3258 custom message\nFailed asserting that an array is empty.
3262 PHPUnit_Framework_TestFailure::exceptionToString($e)
3272 * @covers PHPUnit_Framework_Constraint_Count
3274 public function testConstraintCountWithAnArray()
3276 $constraint = new PHPUnit_Framework_Constraint_Count(5);
3278 $this->assertTrue($constraint->evaluate(array(1, 2, 3, 4, 5), '', true));
3279 $this->assertFalse($constraint->evaluate(array(1, 2, 3, 4), '', true));
3283 * @covers PHPUnit_Framework_Constraint_Count
3285 public function testConstraintCountWithAnIteratorWhichDoesNotImplementCountable()
3287 $constraint = new PHPUnit_Framework_Constraint_Count(5);
3289 $this->assertTrue($constraint->evaluate(new TestIterator(array(1, 2, 3, 4, 5)), '', true));
3290 $this->assertFalse($constraint->evaluate(new TestIterator(array(1, 2, 3, 4)), '', true));
3294 * @covers PHPUnit_Framework_Constraint_Count
3296 public function testConstraintCountWithAnObjectImplementingCountable()
3298 $constraint = new PHPUnit_Framework_Constraint_Count(5);
3300 $this->assertTrue($constraint->evaluate(new ArrayObject(array(1, 2, 3, 4, 5)), '', true));
3301 $this->assertFalse($constraint->evaluate(new ArrayObject(array(1, 2, 3, 4)), '', true));
3305 * @covers PHPUnit_Framework_Constraint_Count
3306 * @covers PHPUnit_Framework_TestFailure::exceptionToString
3308 public function testConstraintCountFailing()
3310 $constraint = new PHPUnit_Framework_Constraint_Count(5);
3313 $constraint->evaluate(array(1, 2));
3314 } catch (PHPUnit_Framework_ExpectationFailedException $e) {
3315 $this->assertEquals(
3317 Failed asserting that actual size 2 matches expected size 5.
3321 PHPUnit_Framework_TestFailure::exceptionToString($e)
3331 * @covers PHPUnit_Framework_Constraint_Count
3332 * @covers PHPUnit_Framework_Constraint_Not
3333 * @covers PHPUnit_Framework_Assert::logicalNot
3334 * @covers PHPUnit_Framework_TestFailure::exceptionToString
3336 public function testConstraintNotCountFailing()
3338 $constraint = PHPUnit_Framework_Assert::logicalNot(
3339 new PHPUnit_Framework_Constraint_Count(2)
3343 $constraint->evaluate(array(1, 2));
3344 } catch (PHPUnit_Framework_ExpectationFailedException $e) {
3345 $this->assertEquals(
3347 Failed asserting that actual size 2 does not match expected size 2.
3351 PHPUnit_Framework_TestFailure::exceptionToString($e)
3361 * @covers PHPUnit_Framework_Constraint_SameSize
3363 public function testConstraintSameSizeWithAnArray()
3365 $constraint = new PHPUnit_Framework_Constraint_SameSize(array(1, 2, 3, 4, 5));
3367 $this->assertTrue($constraint->evaluate(array(6, 7, 8, 9, 10), '', true));
3368 $this->assertFalse($constraint->evaluate(array(1, 2, 3, 4), '', true));
3372 * @covers PHPUnit_Framework_Constraint_SameSize
3374 public function testConstraintSameSizeWithAnIteratorWhichDoesNotImplementCountable()
3376 $constraint = new PHPUnit_Framework_Constraint_SameSize(new TestIterator(array(1, 2, 3, 4, 5)));
3378 $this->assertTrue($constraint->evaluate(new TestIterator(array(6, 7, 8, 9, 10)), '', true));
3379 $this->assertFalse($constraint->evaluate(new TestIterator(array(1, 2, 3, 4)), '', true));
3383 * @covers PHPUnit_Framework_Constraint_SameSize
3385 public function testConstraintSameSizeWithAnObjectImplementingCountable()
3387 $constraint = new PHPUnit_Framework_Constraint_SameSize(new ArrayObject(array(1, 2, 3, 4, 5)));
3389 $this->assertTrue($constraint->evaluate(new ArrayObject(array(6, 7, 8, 9, 10)), '', true));
3390 $this->assertFalse($constraint->evaluate(new ArrayObject(array(1, 2, 3, 4)), '', true));
3394 * @covers PHPUnit_Framework_Constraint_SameSize
3395 * @covers PHPUnit_Framework_TestFailure::exceptionToString
3397 public function testConstraintSameSizeFailing()
3399 $constraint = new PHPUnit_Framework_Constraint_SameSize(array(1, 2, 3, 4, 5));
3402 $constraint->evaluate(array(1, 2));
3403 } catch (PHPUnit_Framework_ExpectationFailedException $e) {
3404 $this->assertEquals(
3406 Failed asserting that actual size 2 matches expected size 5.
3410 PHPUnit_Framework_TestFailure::exceptionToString($e)
3420 * @covers PHPUnit_Framework_Constraint_SameSize
3421 * @covers PHPUnit_Framework_Constraint_Not
3422 * @covers PHPUnit_Framework_Assert::logicalNot
3423 * @covers PHPUnit_Framework_TestFailure::exceptionToString
3425 public function testConstraintNotSameSizeFailing()
3427 $constraint = PHPUnit_Framework_Assert::logicalNot(
3428 new PHPUnit_Framework_Constraint_SameSize(array(1, 2))
3432 $constraint->evaluate(array(3, 4));
3433 } catch (PHPUnit_Framework_ExpectationFailedException $e) {
3434 $this->assertEquals(
3436 Failed asserting that actual size 2 does not match expected size 2.
3440 PHPUnit_Framework_TestFailure::exceptionToString($e)
3450 * @covers PHPUnit_Framework_Constraint_Exception
3451 * @covers PHPUnit_Framework_TestFailure::exceptionToString
3453 public function testConstraintException()
3455 $constraint = new PHPUnit_Framework_Constraint_Exception('FoobarException');
3456 $exception = new DummyException('Test');
3457 $stackTrace = $exception->getTraceAsString();
3460 $constraint->evaluate($exception);
3461 } catch (PHPUnit_Framework_ExpectationFailedException $e) {
3462 $this->assertEquals(
3464 Failed asserting that exception of type "DummyException" matches expected exception "FoobarException". Message was: "Test" at
3469 PHPUnit_Framework_TestFailure::exceptionToString($e)
3479 * Removes spaces in front of newlines
3481 * @param string $string
3485 private function trimnl($string)
3487 return preg_replace('/[ ]*\n/', "\n", $string);