5 * Copyright (c) 2002-2009, Sebastian Bergmann <sb@sebastian-bergmann.de>.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
12 * * Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
15 * * Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
20 * * Neither the name of Sebastian Bergmann nor the names of his
21 * contributors may be used to endorse or promote products derived
22 * from this software without specific prior written permission.
24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
27 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
28 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
29 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
30 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
31 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
32 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
34 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 * POSSIBILITY OF SUCH DAMAGE.
39 * @author Sebastian Bergmann <sb@sebastian-bergmann.de>
40 * @copyright 2002-2009 Sebastian Bergmann <sb@sebastian-bergmann.de>
41 * @license http://www.opensource.org/licenses/bsd-license.php BSD License
43 * @link http://www.phpunit.de/
44 * @since File available since Release 3.3.0
47 require_once 'PHPUnit/Framework/TestCase.php';
49 require_once dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . '_files' . DIRECTORY_SEPARATOR . 'ClassWithNonPublicAttributes.php';
56 * @author Sebastian Bergmann <sb@sebastian-bergmann.de>
57 * @copyright 2002-2009 Sebastian Bergmann <sb@sebastian-bergmann.de>
58 * @license http://www.opensource.org/licenses/bsd-license.php BSD License
59 * @version Release: 3.3.17
60 * @link http://www.phpunit.de/
61 * @since Class available since Release 3.3.0
63 class Framework_TestFailureTest extends PHPUnit_Framework_TestCase
65 public function testFailureArrayHasKey()
67 $constraint = new PHPUnit_Framework_Constraint_ArrayHasKey(0);
70 $constraint->fail(array(), '');
73 catch (PHPUnit_Framework_ExpectationFailedException $e) {
75 "Failed asserting that an array has the key <integer:0>.\n",
76 PHPUnit_Framework_TestFailure::exceptionToString($e)
85 public function testFailureArrayHasKey2()
87 $constraint = new PHPUnit_Framework_Constraint_ArrayHasKey(0);
90 $constraint->fail(array(), 'custom message');
93 catch (PHPUnit_Framework_ExpectationFailedException $e) {
95 "custom message\nFailed asserting that an array has the key <integer:0>.\n",
96 PHPUnit_Framework_TestFailure::exceptionToString($e)
105 public function testFailureArrayNotHasKey()
107 $constraint = new PHPUnit_Framework_Constraint_Not(
108 new PHPUnit_Framework_Constraint_ArrayHasKey(0)
112 $constraint->fail(array(0), '', TRUE);
115 catch (PHPUnit_Framework_ExpectationFailedException $e) {
117 "Failed asserting that an array does not have the key <integer:0>.\n",
118 PHPUnit_Framework_TestFailure::exceptionToString($e)
127 public function testFailureArrayNotHasKey2()
129 $constraint = new PHPUnit_Framework_Constraint_Not(
130 new PHPUnit_Framework_Constraint_ArrayHasKey(0)
134 $constraint->fail(array(0), 'custom message', TRUE);
137 catch (PHPUnit_Framework_ExpectationFailedException $e) {
139 "custom message\nFailed asserting that an array does not have the key <integer:0>.\n",
140 PHPUnit_Framework_TestFailure::exceptionToString($e)
149 public function testFailureFileExists()
151 $constraint = new PHPUnit_Framework_Constraint_FileExists;
154 $constraint->fail('foo', '');
157 catch (PHPUnit_Framework_ExpectationFailedException $e) {
159 "Failed asserting that file \"foo\" exists.\n",
160 PHPUnit_Framework_TestFailure::exceptionToString($e)
169 public function testFailureFileExists2()
171 $constraint = new PHPUnit_Framework_Constraint_FileExists;
174 $constraint->fail('foo', 'custom message');
177 catch (PHPUnit_Framework_ExpectationFailedException $e) {
179 "custom message\nFailed asserting that file \"foo\" exists.\n",
180 PHPUnit_Framework_TestFailure::exceptionToString($e)
189 public function testFailureFileNotExists()
191 $constraint = new PHPUnit_Framework_Constraint_Not(
192 new PHPUnit_Framework_Constraint_FileExists
196 $constraint->fail('foo', '', TRUE);
199 catch (PHPUnit_Framework_ExpectationFailedException $e) {
201 "Failed asserting that file \"foo\" does not exist.\n",
202 PHPUnit_Framework_TestFailure::exceptionToString($e)
211 public function testFailureFileNotExists2()
213 $constraint = new PHPUnit_Framework_Constraint_Not(
214 new PHPUnit_Framework_Constraint_FileExists
218 $constraint->fail('foo', 'custom message', TRUE);
221 catch (PHPUnit_Framework_ExpectationFailedException $e) {
223 "custom message\nFailed asserting that file \"foo\" does not exist.\n",
224 PHPUnit_Framework_TestFailure::exceptionToString($e)
233 public function testFailureGreaterThan()
235 $constraint = new PHPUnit_Framework_Constraint_GreaterThan(1);
238 $constraint->fail(0, '');
241 catch (PHPUnit_Framework_ExpectationFailedException $e) {
243 "Failed asserting that <integer:0> is greater than <integer:1>.\n",
244 PHPUnit_Framework_TestFailure::exceptionToString($e)
253 public function testFailureGreaterThan2()
255 $constraint = new PHPUnit_Framework_Constraint_GreaterThan(1);
258 $constraint->fail(0, 'custom message');
261 catch (PHPUnit_Framework_ExpectationFailedException $e) {
263 "custom message\nFailed asserting that <integer:0> is greater than <integer:1>.\n",
264 PHPUnit_Framework_TestFailure::exceptionToString($e)
273 public function testFailureNotGreaterThan()
275 $constraint = new PHPUnit_Framework_Constraint_Not(
276 new PHPUnit_Framework_Constraint_GreaterThan(1)
280 $constraint->fail(1, '', TRUE);
283 catch (PHPUnit_Framework_ExpectationFailedException $e) {
285 "Failed asserting that <integer:1> is not greater than <integer:1>.\n",
286 PHPUnit_Framework_TestFailure::exceptionToString($e)
295 public function testFailureNotGreaterThan2()
297 $constraint = new PHPUnit_Framework_Constraint_Not(
298 new PHPUnit_Framework_Constraint_GreaterThan(1)
302 $constraint->fail(1, 'custom message', TRUE);
305 catch (PHPUnit_Framework_ExpectationFailedException $e) {
307 "custom message\nFailed asserting that <integer:1> is not greater than <integer:1>.\n",
308 PHPUnit_Framework_TestFailure::exceptionToString($e)
317 public function testFailureIsEqual()
319 $constraint = new PHPUnit_Framework_Constraint_IsEqual(1);
322 $constraint->fail(0, '');
325 catch (PHPUnit_Framework_ExpectationFailedException $e) {
327 "Failed asserting that <integer:0> matches expected value <integer:1>.\n",
328 PHPUnit_Framework_TestFailure::exceptionToString($e)
337 public function testFailureIsEqual2()
339 $constraint = new PHPUnit_Framework_Constraint_IsEqual(1);
342 $constraint->fail(0, 'custom message');
345 catch (PHPUnit_Framework_ExpectationFailedException $e) {
347 "custom message\nFailed asserting that <integer:0> matches expected value <integer:1>.\n",
348 PHPUnit_Framework_TestFailure::exceptionToString($e)
357 public function testFailureIsNotEqual()
359 $constraint = new PHPUnit_Framework_Constraint_Not(
360 new PHPUnit_Framework_Constraint_IsEqual(1)
364 $constraint->fail(1, '', TRUE);
367 catch (PHPUnit_Framework_ExpectationFailedException $e) {
369 "Failed asserting that <integer:1> is not equal to <integer:1>.\n",
370 PHPUnit_Framework_TestFailure::exceptionToString($e)
379 public function testFailureIsNotEqual2()
381 $constraint = new PHPUnit_Framework_Constraint_Not(
382 new PHPUnit_Framework_Constraint_IsEqual(1)
386 $constraint->fail(1, 'custom message', TRUE);
389 catch (PHPUnit_Framework_ExpectationFailedException $e) {
391 "custom message\nFailed asserting that <integer:1> is not equal to <integer:1>.\n",
392 PHPUnit_Framework_TestFailure::exceptionToString($e)
401 public function testFailureIsIdentical()
406 $constraint = new PHPUnit_Framework_Constraint_IsIdentical($a);
409 $constraint->fail($b, '');
412 catch (PHPUnit_Framework_ExpectationFailedException $e) {
414 "Failed asserting that two variables reference the same object.\n",
415 PHPUnit_Framework_TestFailure::exceptionToString($e)
424 public function testFailureIsIdentical2()
429 $constraint = new PHPUnit_Framework_Constraint_IsIdentical($a);
432 $constraint->fail($b, 'custom message');
435 catch (PHPUnit_Framework_ExpectationFailedException $e) {
437 "custom message\nFailed asserting that two variables reference the same object.\n",
438 PHPUnit_Framework_TestFailure::exceptionToString($e)
447 public function testFailureIsNotIdentical()
452 $constraint = new PHPUnit_Framework_Constraint_Not(
453 new PHPUnit_Framework_Constraint_IsIdentical($a)
457 $constraint->fail($a, '', TRUE);
460 catch (PHPUnit_Framework_ExpectationFailedException $e) {
462 "Failed asserting that \nstdClass Object\n(\n)\n is not identical to an object of class \"stdClass\".\n",
463 PHPUnit_Framework_TestFailure::exceptionToString($e)
472 public function testFailureIsNotIdentical2()
476 $constraint = new PHPUnit_Framework_Constraint_Not(
477 new PHPUnit_Framework_Constraint_IsIdentical($a)
481 $constraint->fail($a, 'custom message', TRUE);
484 catch (PHPUnit_Framework_ExpectationFailedException $e) {
486 "custom message\nFailed asserting that \nstdClass Object\n(\n)\n is not identical to an object of class \"stdClass\".\n",
487 PHPUnit_Framework_TestFailure::exceptionToString($e)
496 public function testFailureIsInstanceOf()
498 $constraint = new PHPUnit_Framework_Constraint_IsInstanceOf('Exception');
501 $constraint->fail(new stdClass, '');
504 catch (PHPUnit_Framework_ExpectationFailedException $e) {
506 "Failed asserting that <stdClass> is an instance of class \"Exception\".\n",
507 PHPUnit_Framework_TestFailure::exceptionToString($e)
516 public function testFailureIsInstanceOf2()
518 $constraint = new PHPUnit_Framework_Constraint_IsInstanceOf('Exception');
521 $constraint->fail(new stdClass, 'custom message');
524 catch (PHPUnit_Framework_ExpectationFailedException $e) {
526 "custom message\nFailed asserting that <stdClass> is an instance of class \"Exception\".\n",
527 PHPUnit_Framework_TestFailure::exceptionToString($e)
536 public function testFailureIsNotInstanceOf()
538 $constraint = new PHPUnit_Framework_Constraint_Not(
539 new PHPUnit_Framework_Constraint_IsInstanceOf('stdClass')
543 $constraint->fail(new stdClass, '', TRUE);
546 catch (PHPUnit_Framework_ExpectationFailedException $e) {
548 "Failed asserting that <stdClass> is not an instance of class \"stdClass\".\n",
549 PHPUnit_Framework_TestFailure::exceptionToString($e)
558 public function testFailureIsNotInstanceOf2()
560 $constraint = new PHPUnit_Framework_Constraint_Not(
561 new PHPUnit_Framework_Constraint_IsInstanceOf('stdClass')
565 $constraint->fail(new stdClass, 'custom message', TRUE);
568 catch (PHPUnit_Framework_ExpectationFailedException $e) {
570 "custom message\nFailed asserting that <stdClass> is not an instance of class \"stdClass\".\n",
571 PHPUnit_Framework_TestFailure::exceptionToString($e)
580 public function testFailureIsType()
582 $constraint = new PHPUnit_Framework_Constraint_IsType('string');
585 $constraint->fail(new stdClass, '');
588 catch (PHPUnit_Framework_ExpectationFailedException $e) {
590 "Failed asserting that \nstdClass Object\n(\n)\n is of type \"string\".\n",
591 PHPUnit_Framework_TestFailure::exceptionToString($e)
600 public function testFailureIsType2()
602 $constraint = new PHPUnit_Framework_Constraint_IsType('string');
605 $constraint->fail(new stdClass, 'custom message');
608 catch (PHPUnit_Framework_ExpectationFailedException $e) {
610 "custom message\nFailed asserting that \nstdClass Object\n(\n)\n is of type \"string\".\n",
611 PHPUnit_Framework_TestFailure::exceptionToString($e)
620 public function testFailureIsNotType()
622 $constraint = new PHPUnit_Framework_Constraint_Not(
623 new PHPUnit_Framework_Constraint_IsType('string')
627 $constraint->fail('', '', TRUE);
630 catch (PHPUnit_Framework_ExpectationFailedException $e) {
632 "Failed asserting that <string:> is not of type \"string\".\n",
633 PHPUnit_Framework_TestFailure::exceptionToString($e)
642 public function testFailureIsNotType2()
644 $constraint = new PHPUnit_Framework_Constraint_Not(
645 new PHPUnit_Framework_Constraint_IsType('string')
649 $constraint->fail('', 'custom message', TRUE);
652 catch (PHPUnit_Framework_ExpectationFailedException $e) {
654 "custom message\nFailed asserting that <string:> is not of type \"string\".\n",
655 PHPUnit_Framework_TestFailure::exceptionToString($e)
664 public function testFailureLessThan()
666 $constraint = new PHPUnit_Framework_Constraint_LessThan(1);
669 $constraint->fail(0, '');
672 catch (PHPUnit_Framework_ExpectationFailedException $e) {
674 "Failed asserting that <integer:0> is less than <integer:1>.\n",
675 PHPUnit_Framework_TestFailure::exceptionToString($e)
684 public function testFailureLessThan2()
686 $constraint = new PHPUnit_Framework_Constraint_LessThan(1);
689 $constraint->fail(0, 'custom message');
692 catch (PHPUnit_Framework_ExpectationFailedException $e) {
694 "custom message\nFailed asserting that <integer:0> is less than <integer:1>.\n",
695 PHPUnit_Framework_TestFailure::exceptionToString($e)
704 public function testFailureNotLessThan()
706 $constraint = new PHPUnit_Framework_Constraint_Not(
707 new PHPUnit_Framework_Constraint_LessThan(1)
711 $constraint->fail(1, '', TRUE);
714 catch (PHPUnit_Framework_ExpectationFailedException $e) {
716 "Failed asserting that <integer:1> is not less than <integer:1>.\n",
717 PHPUnit_Framework_TestFailure::exceptionToString($e)
726 public function testFailureNotLessThan2()
728 $constraint = new PHPUnit_Framework_Constraint_Not(
729 new PHPUnit_Framework_Constraint_LessThan(1)
733 $constraint->fail(1, 'custom message', TRUE);
736 catch (PHPUnit_Framework_ExpectationFailedException $e) {
738 "custom message\nFailed asserting that <integer:1> is not less than <integer:1>.\n",
739 PHPUnit_Framework_TestFailure::exceptionToString($e)
748 public function testFailureObjectHasAttribute()
750 $constraint = new PHPUnit_Framework_Constraint_ObjectHasAttribute('foo');
753 $constraint->fail(new stdClass, '');
756 catch (PHPUnit_Framework_ExpectationFailedException $e) {
758 "Failed asserting that object of class \"stdClass\" has attribute \"foo\".\n",
759 PHPUnit_Framework_TestFailure::exceptionToString($e)
768 public function testFailureObjectHasAttribute2()
770 $constraint = new PHPUnit_Framework_Constraint_ObjectHasAttribute('foo');
773 $constraint->fail(new stdClass, 'custom message');
776 catch (PHPUnit_Framework_ExpectationFailedException $e) {
778 "custom message\nFailed asserting that object of class \"stdClass\" has attribute \"foo\".\n",
779 PHPUnit_Framework_TestFailure::exceptionToString($e)
788 public function testFailureObjectNotHasAttribute()
790 $constraint = new PHPUnit_Framework_Constraint_Not(
791 new PHPUnit_Framework_Constraint_ObjectHasAttribute('foo')
798 $constraint->fail($o, '', TRUE);
801 catch (PHPUnit_Framework_ExpectationFailedException $e) {
803 "Failed asserting that object of class \"stdClass\" does not have attribute \"foo\".\n",
804 PHPUnit_Framework_TestFailure::exceptionToString($e)
813 public function testFailureObjectNotHasAttribute2()
815 $constraint = new PHPUnit_Framework_Constraint_Not(
816 new PHPUnit_Framework_Constraint_ObjectHasAttribute('foo')
823 $constraint->fail($o, 'custom message', TRUE);
826 catch (PHPUnit_Framework_ExpectationFailedException $e) {
828 "custom message\nFailed asserting that object of class \"stdClass\" does not have attribute \"foo\".\n",
829 PHPUnit_Framework_TestFailure::exceptionToString($e)
838 public function testFailurePCREMatch()
840 $constraint = new PHPUnit_Framework_Constraint_PCREMatch('/foo/');
843 $constraint->fail('barbazbar', '');
846 catch (PHPUnit_Framework_ExpectationFailedException $e) {
848 "Failed asserting that <string:barbazbar> matches PCRE pattern \"/foo/\".\n",
849 PHPUnit_Framework_TestFailure::exceptionToString($e)
858 public function testFailurePCREMatch2()
860 $constraint = new PHPUnit_Framework_Constraint_PCREMatch('/foo/');
863 $constraint->fail('barbazbar', 'custom message');
866 catch (PHPUnit_Framework_ExpectationFailedException $e) {
868 "custom message\nFailed asserting that <string:barbazbar> matches PCRE pattern \"/foo/\".\n",
869 PHPUnit_Framework_TestFailure::exceptionToString($e)
878 public function testFailurePCRENotMatch()
880 $constraint = new PHPUnit_Framework_Constraint_Not(
881 new PHPUnit_Framework_Constraint_PCREMatch('/foo/')
885 $constraint->fail('barfoobar', '', TRUE);
888 catch (PHPUnit_Framework_ExpectationFailedException $e) {
890 "Failed asserting that <string:barfoobar> does not match PCRE pattern \"/foo/\".\n",
891 PHPUnit_Framework_TestFailure::exceptionToString($e)
900 public function testFailurePCRENotMatch2()
902 $constraint = new PHPUnit_Framework_Constraint_Not(
903 new PHPUnit_Framework_Constraint_PCREMatch('/foo/')
907 $constraint->fail('barfoobar', 'custom message', TRUE);
910 catch (PHPUnit_Framework_ExpectationFailedException $e) {
912 "custom message\nFailed asserting that <string:barfoobar> does not match PCRE pattern \"/foo/\".\n",
913 PHPUnit_Framework_TestFailure::exceptionToString($e)
922 public function testFailureStringContains()
924 $constraint = new PHPUnit_Framework_Constraint_StringContains('foo');
927 $constraint->fail('barbazbar', '');
930 catch (PHPUnit_Framework_ExpectationFailedException $e) {
932 "Failed asserting that <string:barbazbar> contains \"foo\".\n",
933 PHPUnit_Framework_TestFailure::exceptionToString($e)
942 public function testFailureStringContains2()
944 $constraint = new PHPUnit_Framework_Constraint_StringContains('foo');
947 $constraint->fail('barbazbar', 'custom message');
950 catch (PHPUnit_Framework_ExpectationFailedException $e) {
952 "custom message\nFailed asserting that <string:barbazbar> contains \"foo\".\n",
953 PHPUnit_Framework_TestFailure::exceptionToString($e)
962 public function testFailureStringNotContains()
964 $constraint = new PHPUnit_Framework_Constraint_Not(
965 new PHPUnit_Framework_Constraint_StringContains('foo')
969 $constraint->fail('barfoobar', '', TRUE);
972 catch (PHPUnit_Framework_ExpectationFailedException $e) {
974 "Failed asserting that <string:barfoobar> does not contain \"foo\".\n",
975 PHPUnit_Framework_TestFailure::exceptionToString($e)
984 public function testFailureStringNotContains2()
986 $constraint = new PHPUnit_Framework_Constraint_Not(
987 new PHPUnit_Framework_Constraint_StringContains('foo')
991 $constraint->fail('barfoobar', 'custom message', TRUE);
994 catch (PHPUnit_Framework_ExpectationFailedException $e) {
996 "custom message\nFailed asserting that <string:barfoobar> does not contain \"foo\".\n",
997 PHPUnit_Framework_TestFailure::exceptionToString($e)
1006 public function testFailureTraversableContains()
1008 $constraint = new PHPUnit_Framework_Constraint_TraversableContains('foo');
1011 $constraint->fail(array('bar'), '');
1014 catch (PHPUnit_Framework_ExpectationFailedException $e) {
1015 $this->assertEquals(
1016 "Failed asserting that an array contains <string:foo>.\n",
1017 PHPUnit_Framework_TestFailure::exceptionToString($e)
1026 public function testFailureTraversableContains2()
1028 $constraint = new PHPUnit_Framework_Constraint_TraversableContains('foo');
1031 $constraint->fail(array('bar'), 'custom message');
1034 catch (PHPUnit_Framework_ExpectationFailedException $e) {
1035 $this->assertEquals(
1036 "custom message\nFailed asserting that an array contains <string:foo>.\n",
1037 PHPUnit_Framework_TestFailure::exceptionToString($e)
1046 public function testFailureTraversableNotContains()
1048 $constraint = new PHPUnit_Framework_Constraint_Not(
1049 new PHPUnit_Framework_Constraint_TraversableContains('foo')
1053 $constraint->fail(array('foo'), '', TRUE);
1056 catch (PHPUnit_Framework_ExpectationFailedException $e) {
1057 $this->assertEquals(
1058 "Failed asserting that an array does not contain <string:foo>.\n",
1059 PHPUnit_Framework_TestFailure::exceptionToString($e)
1068 public function testFailureTraversableNotContains2()
1070 $constraint = new PHPUnit_Framework_Constraint_Not(
1071 new PHPUnit_Framework_Constraint_TraversableContains('foo')
1075 $constraint->fail(array('foo'), 'custom message', TRUE);
1078 catch (PHPUnit_Framework_ExpectationFailedException $e) {
1079 $this->assertEquals(
1080 "custom message\nFailed asserting that an array does not contain <string:foo>.\n",
1081 PHPUnit_Framework_TestFailure::exceptionToString($e)