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.0.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.0.0
63 class Framework_ConstraintTest extends PHPUnit_Framework_TestCase
65 public function testConstraintArrayHasKey()
67 $constraint = new PHPUnit_Framework_Constraint_ArrayHasKey(0);
69 $this->assertFalse($constraint->evaluate(array()));
70 $this->assertEquals('has the key <integer:0>', $constraint->toString());
73 $constraint->fail(array(), '');
76 catch (PHPUnit_Framework_ExpectationFailedException $e) {
78 "Failed asserting that an array has the key <integer:0>.",
88 public function testConstraintArrayHasKey2()
90 $constraint = new PHPUnit_Framework_Constraint_ArrayHasKey(0);
93 $constraint->fail(array(), 'custom message');
96 catch (PHPUnit_Framework_ExpectationFailedException $e) {
98 "custom message\nFailed asserting that an array has the key <integer:0>.",
108 public function testConstraintArrayNotHasKey()
110 $constraint = new PHPUnit_Framework_Constraint_Not(
111 new PHPUnit_Framework_Constraint_ArrayHasKey(0)
114 $this->assertTrue($constraint->evaluate(array()));
115 $this->assertEquals('does not have the key <integer:0>', $constraint->toString());
118 $constraint->fail(array(0), '', TRUE);
121 catch (PHPUnit_Framework_ExpectationFailedException $e) {
123 "Failed asserting that an array does not have the key <integer:0>.",
133 public function testConstraintArrayNotHasKey2()
135 $constraint = new PHPUnit_Framework_Constraint_Not(
136 new PHPUnit_Framework_Constraint_ArrayHasKey(0)
140 $constraint->fail(array(0), 'custom message', TRUE);
143 catch (PHPUnit_Framework_ExpectationFailedException $e) {
145 "custom message\nFailed asserting that an array does not have the key <integer:0>.",
155 public function testConstraintFileExists()
157 $constraint = new PHPUnit_Framework_Constraint_FileExists;
159 $this->assertFalse($constraint->evaluate('foo'));
160 $this->assertEquals('file exists', $constraint->toString());
163 $constraint->fail('foo', '');
166 catch (PHPUnit_Framework_ExpectationFailedException $e) {
168 'Failed asserting that file "foo" exists.',
178 public function testConstraintFileExists2()
180 $constraint = new PHPUnit_Framework_Constraint_FileExists;
183 $constraint->fail('foo', 'custom message');
186 catch (PHPUnit_Framework_ExpectationFailedException $e) {
188 "custom message\nFailed asserting that file \"foo\" exists.",
198 public function testConstraintFileNotExists()
200 $constraint = new PHPUnit_Framework_Constraint_Not(
201 new PHPUnit_Framework_Constraint_FileExists
204 $this->assertTrue($constraint->evaluate('foo'));
205 $this->assertEquals('file does not exist', $constraint->toString());
208 $constraint->fail('foo', '', TRUE);
211 catch (PHPUnit_Framework_ExpectationFailedException $e) {
213 'Failed asserting that file "foo" does not exist.',
223 public function testConstraintFileNotExists2()
225 $constraint = new PHPUnit_Framework_Constraint_Not(
226 new PHPUnit_Framework_Constraint_FileExists
230 $constraint->fail('foo', 'custom message', TRUE);
233 catch (PHPUnit_Framework_ExpectationFailedException $e) {
235 "custom message\nFailed asserting that file \"foo\" does not exist.",
245 public function testConstraintGreaterThan()
247 $constraint = new PHPUnit_Framework_Constraint_GreaterThan(1);
249 $this->assertFalse($constraint->evaluate(0));
250 $this->assertTrue($constraint->evaluate(2));
251 $this->assertEquals('is greater than <integer:1>', $constraint->toString());
254 $constraint->fail(0, '');
257 catch (PHPUnit_Framework_ExpectationFailedException $e) {
259 "Failed asserting that <integer:0> is greater than <integer:1>.",
269 public function testConstraintGreaterThan2()
271 $constraint = new PHPUnit_Framework_Constraint_GreaterThan(1);
274 $constraint->fail(0, 'custom message');
277 catch (PHPUnit_Framework_ExpectationFailedException $e) {
279 "custom message\nFailed asserting that <integer:0> is greater than <integer:1>.",
289 public function testConstraintNotGreaterThan()
291 $constraint = new PHPUnit_Framework_Constraint_Not(
292 new PHPUnit_Framework_Constraint_GreaterThan(1)
295 $this->assertTrue($constraint->evaluate(1));
296 $this->assertEquals('is not greater than <integer:1>', $constraint->toString());
299 $constraint->fail(1, '', TRUE);
302 catch (PHPUnit_Framework_ExpectationFailedException $e) {
304 "Failed asserting that <integer:1> is not greater than <integer:1>.",
314 public function testConstraintNotGreaterThan2()
316 $constraint = new PHPUnit_Framework_Constraint_Not(
317 new PHPUnit_Framework_Constraint_GreaterThan(1)
321 $constraint->fail(1, 'custom message', TRUE);
324 catch (PHPUnit_Framework_ExpectationFailedException $e) {
326 "custom message\nFailed asserting that <integer:1> is not greater than <integer:1>.",
336 public function testConstraintIsAnything()
338 $constraint = new PHPUnit_Framework_Constraint_IsAnything;
340 $this->assertTrue($constraint->evaluate(NULL));
341 $this->assertNull($constraint->fail(NULL, ''));
342 $this->assertEquals('is anything', $constraint->toString());
345 public function testConstraintNotIsAnything()
347 $constraint = new PHPUnit_Framework_Constraint_Not(
348 new PHPUnit_Framework_Constraint_IsAnything
351 $this->assertFalse($constraint->evaluate(NULL));
352 $this->assertNull($constraint->fail(NULL, ''));
353 $this->assertEquals('is not anything', $constraint->toString());
356 public function testConstraintIsEqual()
358 $constraint = new PHPUnit_Framework_Constraint_IsEqual(1);
360 $this->assertFalse($constraint->evaluate(0));
361 $this->assertTrue($constraint->evaluate(1));
362 $this->assertEquals('is equal to <integer:1>', $constraint->toString());
365 $constraint->fail(0, '');
368 catch (PHPUnit_Framework_ExpectationFailedException $e) {
370 "Failed asserting that <integer:0> is equal to <integer:1>.",
380 public function testConstraintIsEqual2()
382 $constraint = new PHPUnit_Framework_Constraint_IsEqual(1);
385 $constraint->fail(0, 'custom message');
388 catch (PHPUnit_Framework_ExpectationFailedException $e) {
390 "custom message\nFailed asserting that <integer:0> is equal to <integer:1>.",
400 public function testConstraintIsNotEqual()
402 $constraint = new PHPUnit_Framework_Constraint_Not(
403 new PHPUnit_Framework_Constraint_IsEqual(1)
406 $this->assertTrue($constraint->evaluate(0));
407 $this->assertFalse($constraint->evaluate(1));
408 $this->assertEquals('is not equal to <integer:1>', $constraint->toString());
411 $constraint->fail(1, '', TRUE);
414 catch (PHPUnit_Framework_ExpectationFailedException $e) {
416 "Failed asserting that <integer:1> is not equal to <integer:1>.",
426 public function testConstraintIsNotEqual2()
428 $constraint = new PHPUnit_Framework_Constraint_Not(
429 new PHPUnit_Framework_Constraint_IsEqual(1)
433 $constraint->fail(1, 'custom message', TRUE);
436 catch (PHPUnit_Framework_ExpectationFailedException $e) {
438 "custom message\nFailed asserting that <integer:1> is not equal to <integer:1>.",
448 public function testConstraintIsIdentical()
453 $constraint = new PHPUnit_Framework_Constraint_IsIdentical($a);
455 $this->assertFalse($constraint->evaluate($b));
456 $this->assertTrue($constraint->evaluate($a));
457 $this->assertEquals('is identical to an object of class "stdClass"', $constraint->toString());
460 $constraint->fail($b, '');
463 catch (PHPUnit_Framework_ExpectationFailedException $e) {
465 "Failed asserting that \nstdClass Object\n(\n)\n is identical to an object of class \"stdClass\".",
475 public function testConstraintIsIdentical2()
480 $constraint = new PHPUnit_Framework_Constraint_IsIdentical($a);
483 $constraint->fail($b, 'custom message');
486 catch (PHPUnit_Framework_ExpectationFailedException $e) {
488 "custom message\nFailed asserting that \nstdClass Object\n(\n)\n is identical to an object of class \"stdClass\".",
498 public function testConstraintIsNotIdentical()
503 $constraint = new PHPUnit_Framework_Constraint_Not(
504 new PHPUnit_Framework_Constraint_IsIdentical($a)
507 $this->assertTrue($constraint->evaluate($b));
508 $this->assertFalse($constraint->evaluate($a));
509 $this->assertEquals("is not identical to an object of class \"stdClass\"", $constraint->toString());
512 $constraint->fail($a, '', TRUE);
515 catch (PHPUnit_Framework_ExpectationFailedException $e) {
517 "Failed asserting that \nstdClass Object\n(\n)\n is not identical to an object of class \"stdClass\".",
527 public function testConstraintIsNotIdentical2()
531 $constraint = new PHPUnit_Framework_Constraint_Not(
532 new PHPUnit_Framework_Constraint_IsIdentical($a)
536 $constraint->fail($a, 'custom message', TRUE);
539 catch (PHPUnit_Framework_ExpectationFailedException $e) {
541 "custom message\nFailed asserting that \nstdClass Object\n(\n)\n is not identical to an object of class \"stdClass\".",
551 public function testConstraintIsInstanceOf()
553 $constraint = new PHPUnit_Framework_Constraint_IsInstanceOf('Exception');
555 $this->assertFalse($constraint->evaluate(new stdClass));
556 $this->assertTrue($constraint->evaluate(new Exception));
557 $this->assertEquals('is instance of class "Exception"', $constraint->toString());
560 $constraint->fail(new stdClass, '');
563 catch (PHPUnit_Framework_ExpectationFailedException $e) {
565 'Failed asserting that <stdClass> is an instance of class "Exception".',
575 public function testConstraintIsInstanceOf2()
577 $constraint = new PHPUnit_Framework_Constraint_IsInstanceOf('Exception');
580 $constraint->fail(new stdClass, 'custom message');
583 catch (PHPUnit_Framework_ExpectationFailedException $e) {
585 "custom message\nFailed asserting that <stdClass> is an instance of class \"Exception\".",
595 public function testConstraintIsNotInstanceOf()
597 $constraint = new PHPUnit_Framework_Constraint_Not(
598 new PHPUnit_Framework_Constraint_IsInstanceOf('stdClass')
601 $this->assertFalse($constraint->evaluate(new stdClass));
602 $this->assertTrue($constraint->evaluate(new Exception));
603 $this->assertEquals('is not instance of class "stdClass"', $constraint->toString());
606 $constraint->fail(new stdClass, '', TRUE);
609 catch (PHPUnit_Framework_ExpectationFailedException $e) {
611 'Failed asserting that <stdClass> is not an instance of class "stdClass".',
621 public function testConstraintIsNotInstanceOf2()
623 $constraint = new PHPUnit_Framework_Constraint_Not(
624 new PHPUnit_Framework_Constraint_IsInstanceOf('stdClass')
628 $constraint->fail(new stdClass, 'custom message', TRUE);
631 catch (PHPUnit_Framework_ExpectationFailedException $e) {
633 "custom message\nFailed asserting that <stdClass> is not an instance of class \"stdClass\".",
643 public function testConstraintIsType()
645 $constraint = new PHPUnit_Framework_Constraint_IsType('string');
647 $this->assertFalse($constraint->evaluate(0));
648 $this->assertTrue($constraint->evaluate(''));
649 $this->assertEquals('is of type "string"', $constraint->toString());
652 $constraint->fail(new stdClass, '');
655 catch (PHPUnit_Framework_ExpectationFailedException $e) {
657 "Failed asserting that \nstdClass Object\n(\n)\n is of type \"string\".",
667 public function testConstraintIsType2()
669 $constraint = new PHPUnit_Framework_Constraint_IsType('string');
672 $constraint->fail(new stdClass, 'custom message');
675 catch (PHPUnit_Framework_ExpectationFailedException $e) {
677 "custom message\nFailed asserting that \nstdClass Object\n(\n)\n is of type \"string\".",
687 public function testConstraintIsNotType()
689 $constraint = new PHPUnit_Framework_Constraint_Not(
690 new PHPUnit_Framework_Constraint_IsType('string')
693 $this->assertTrue($constraint->evaluate(0));
694 $this->assertFalse($constraint->evaluate(''));
695 $this->assertEquals('is not of type "string"', $constraint->toString());
698 $constraint->fail('', '', TRUE);
701 catch (PHPUnit_Framework_ExpectationFailedException $e) {
703 'Failed asserting that <string:> is not of type "string".',
713 public function testConstraintIsNotType2()
715 $constraint = new PHPUnit_Framework_Constraint_Not(
716 new PHPUnit_Framework_Constraint_IsType('string')
720 $constraint->fail('', 'custom message', TRUE);
723 catch (PHPUnit_Framework_ExpectationFailedException $e) {
725 "custom message\nFailed asserting that <string:> is not of type \"string\".",
735 public function testConstraintLessThan()
737 $constraint = new PHPUnit_Framework_Constraint_LessThan(1);
739 $this->assertTrue($constraint->evaluate(0));
740 $this->assertFalse($constraint->evaluate(2));
741 $this->assertEquals('is less than <integer:1>', $constraint->toString());
744 $constraint->fail(0, '');
747 catch (PHPUnit_Framework_ExpectationFailedException $e) {
749 "Failed asserting that <integer:0> is less than <integer:1>.",
759 public function testConstraintLessThan2()
761 $constraint = new PHPUnit_Framework_Constraint_LessThan(1);
764 $constraint->fail(0, 'custom message');
767 catch (PHPUnit_Framework_ExpectationFailedException $e) {
769 "custom message\nFailed asserting that <integer:0> is less than <integer:1>.",
779 public function testConstraintNotLessThan()
781 $constraint = new PHPUnit_Framework_Constraint_Not(
782 new PHPUnit_Framework_Constraint_LessThan(1)
785 $this->assertTrue($constraint->evaluate(1));
786 $this->assertEquals('is not less than <integer:1>', $constraint->toString());
789 $constraint->fail(1, '', TRUE);
792 catch (PHPUnit_Framework_ExpectationFailedException $e) {
794 "Failed asserting that <integer:1> is not less than <integer:1>.",
804 public function testConstraintNotLessThan2()
806 $constraint = new PHPUnit_Framework_Constraint_Not(
807 new PHPUnit_Framework_Constraint_LessThan(1)
811 $constraint->fail(1, 'custom message', TRUE);
814 catch (PHPUnit_Framework_ExpectationFailedException $e) {
816 "custom message\nFailed asserting that <integer:1> is not less than <integer:1>.",
826 public function testConstraintObjectHasAttribute()
828 $constraint = new PHPUnit_Framework_Constraint_ObjectHasAttribute('foo');
830 $this->assertFalse($constraint->evaluate(new stdClass));
831 $this->assertEquals('has attribute "foo"', $constraint->toString());
834 $constraint->fail(new stdClass, '');
837 catch (PHPUnit_Framework_ExpectationFailedException $e) {
839 'Failed asserting that object of class "stdClass" has attribute "foo".',
849 public function testConstraintObjectHasAttribute2()
851 $constraint = new PHPUnit_Framework_Constraint_ObjectHasAttribute('foo');
854 $constraint->fail(new stdClass, 'custom message');
857 catch (PHPUnit_Framework_ExpectationFailedException $e) {
859 "custom message\nFailed asserting that object of class \"stdClass\" has attribute \"foo\".",
869 public function testConstraintObjectNotHasAttribute()
871 $constraint = new PHPUnit_Framework_Constraint_Not(
872 new PHPUnit_Framework_Constraint_ObjectHasAttribute('foo')
875 $this->assertTrue($constraint->evaluate(new stdClass));
876 $this->assertEquals('does not have attribute "foo"', $constraint->toString());
882 $constraint->fail($o, '', TRUE);
885 catch (PHPUnit_Framework_ExpectationFailedException $e) {
887 'Failed asserting that object of class "stdClass" does not have attribute "foo".',
897 public function testConstraintObjectNotHasAttribute2()
899 $constraint = new PHPUnit_Framework_Constraint_Not(
900 new PHPUnit_Framework_Constraint_ObjectHasAttribute('foo')
907 $constraint->fail($o, 'custom message', TRUE);
910 catch (PHPUnit_Framework_ExpectationFailedException $e) {
912 "custom message\nFailed asserting that object of class \"stdClass\" does not have attribute \"foo\".",
922 public function testConstraintPCREMatch()
924 $constraint = new PHPUnit_Framework_Constraint_PCREMatch('/foo/');
926 $this->assertFalse($constraint->evaluate('barbazbar'));
927 $this->assertTrue($constraint->evaluate('barfoobar'));
928 $this->assertEquals('matches PCRE pattern "/foo/"', $constraint->toString());
931 $constraint->fail('barbazbar', '');
934 catch (PHPUnit_Framework_ExpectationFailedException $e) {
936 'Failed asserting that <string:barbazbar> matches PCRE pattern "/foo/".',
946 public function testConstraintPCREMatch2()
948 $constraint = new PHPUnit_Framework_Constraint_PCREMatch('/foo/');
951 $constraint->fail('barbazbar', 'custom message');
954 catch (PHPUnit_Framework_ExpectationFailedException $e) {
956 "custom message\nFailed asserting that <string:barbazbar> matches PCRE pattern \"/foo/\".",
966 public function testConstraintPCRENotMatch()
968 $constraint = new PHPUnit_Framework_Constraint_Not(
969 new PHPUnit_Framework_Constraint_PCREMatch('/foo/')
972 $this->assertTrue($constraint->evaluate('barbazbar'));
973 $this->assertFalse($constraint->evaluate('barfoobar'));
974 $this->assertEquals('does not match PCRE pattern "/foo/"', $constraint->toString());
977 $constraint->fail('barfoobar', '', TRUE);
980 catch (PHPUnit_Framework_ExpectationFailedException $e) {
982 'Failed asserting that <string:barfoobar> does not match PCRE pattern "/foo/".',
992 public function testConstraintPCRENotMatch2()
994 $constraint = new PHPUnit_Framework_Constraint_Not(
995 new PHPUnit_Framework_Constraint_PCREMatch('/foo/')
999 $constraint->fail('barfoobar', 'custom message', TRUE);
1002 catch (PHPUnit_Framework_ExpectationFailedException $e) {
1003 $this->assertEquals(
1004 "custom message\nFailed asserting that <string:barfoobar> does not match PCRE pattern \"/foo/\".",
1005 $e->getDescription()
1014 public function testConstraintStringContains()
1016 $constraint = new PHPUnit_Framework_Constraint_StringContains('foo');
1018 $this->assertFalse($constraint->evaluate('barbazbar'));
1019 $this->assertTrue($constraint->evaluate('barfoobar'));
1020 $this->assertEquals('contains "foo"', $constraint->toString());
1023 $constraint->fail('barbazbar', '');
1026 catch (PHPUnit_Framework_ExpectationFailedException $e) {
1027 $this->assertEquals(
1028 'Failed asserting that <string:barbazbar> contains "foo".',
1029 $e->getDescription()
1038 public function testConstraintStringContains2()
1040 $constraint = new PHPUnit_Framework_Constraint_StringContains('foo');
1043 $constraint->fail('barbazbar', 'custom message');
1046 catch (PHPUnit_Framework_ExpectationFailedException $e) {
1047 $this->assertEquals(
1048 "custom message\nFailed asserting that <string:barbazbar> contains \"foo\".",
1049 $e->getDescription()
1058 public function testConstraintStringNotContains()
1060 $constraint = new PHPUnit_Framework_Constraint_Not(
1061 new PHPUnit_Framework_Constraint_StringContains('foo')
1064 $this->assertTrue($constraint->evaluate('barbazbar'));
1065 $this->assertFalse($constraint->evaluate('barfoobar'));
1066 $this->assertEquals('does not contain "foo"', $constraint->toString());
1069 $constraint->fail('barfoobar', '', TRUE);
1072 catch (PHPUnit_Framework_ExpectationFailedException $e) {
1073 $this->assertEquals(
1074 'Failed asserting that <string:barfoobar> does not contain "foo".',
1075 $e->getDescription()
1084 public function testConstraintStringNotContains2()
1086 $constraint = new PHPUnit_Framework_Constraint_Not(
1087 new PHPUnit_Framework_Constraint_StringContains('foo')
1091 $constraint->fail('barfoobar', 'custom message', TRUE);
1094 catch (PHPUnit_Framework_ExpectationFailedException $e) {
1095 $this->assertEquals(
1096 "custom message\nFailed asserting that <string:barfoobar> does not contain \"foo\".",
1097 $e->getDescription()
1106 public function testConstraintArrayContains()
1108 $constraint = new PHPUnit_Framework_Constraint_TraversableContains('foo');
1110 $this->assertFalse($constraint->evaluate(array('bar')));
1111 $this->assertTrue($constraint->evaluate(array('foo')));
1112 $this->assertEquals('contains <string:foo>', $constraint->toString());
1115 $constraint->fail(array('bar'), '');
1118 catch (PHPUnit_Framework_ExpectationFailedException $e) {
1119 $this->assertEquals(
1120 'Failed asserting that an array contains <string:foo>.',
1121 $e->getDescription()
1130 public function testConstraintArrayContains2()
1132 $constraint = new PHPUnit_Framework_Constraint_TraversableContains('foo');
1135 $constraint->fail(array('bar'), 'custom message');
1138 catch (PHPUnit_Framework_ExpectationFailedException $e) {
1139 $this->assertEquals(
1140 "custom message\nFailed asserting that an array contains <string:foo>.",
1141 $e->getDescription()
1150 public function testConstraintArrayNotContains()
1152 $constraint = new PHPUnit_Framework_Constraint_Not(
1153 new PHPUnit_Framework_Constraint_TraversableContains('foo')
1156 $this->assertTrue($constraint->evaluate(array('bar')));
1157 $this->assertFalse($constraint->evaluate(array('foo')));
1158 $this->assertEquals('does not contain <string:foo>', $constraint->toString());
1161 $constraint->fail(array('foo'), '', TRUE);
1164 catch (PHPUnit_Framework_ExpectationFailedException $e) {
1165 $this->assertEquals(
1166 'Failed asserting that an array does not contain <string:foo>.',
1167 $e->getDescription()
1176 public function testConstraintArrayNotContains2()
1178 $constraint = new PHPUnit_Framework_Constraint_Not(
1179 new PHPUnit_Framework_Constraint_TraversableContains('foo')
1183 $constraint->fail(array('foo'), 'custom message', TRUE);
1186 catch (PHPUnit_Framework_ExpectationFailedException $e) {
1187 $this->assertEquals(
1188 "custom message\nFailed asserting that an array does not contain <string:foo>.",
1189 $e->getDescription()
1199 * @covers PHPUnit_Framework_Constraint_TraversableContains
1201 public function testConstraintSplObjectStorageContains()
1203 $object = new StdClass;
1204 $constraint = new PHPUnit_Framework_Constraint_TraversableContains($object);
1205 $this->assertEquals("contains \nstdClass Object\n(\n)\n", $constraint->toString());
1207 $storage = new SplObjectStorage;
1208 $this->assertFalse($constraint->evaluate($storage));
1210 $storage->attach($object);
1211 $this->assertTrue($constraint->evaluate($storage));
1214 $constraint->fail(new SplObjectStorage, '');
1217 catch (PHPUnit_Framework_ExpectationFailedException $e) {
1218 $this->assertEquals(
1219 "Failed asserting that an iterator contains \nstdClass Object\n(\n)\n.",
1220 $e->getDescription()
1230 * @covers PHPUnit_Framework_Constraint_TraversableContains
1232 public function testConstraintSplObjectStorageContains2()
1234 $object = new StdClass;
1235 $constraint = new PHPUnit_Framework_Constraint_TraversableContains($object);
1238 $constraint->fail(new SplObjectStorage, 'custom message');
1241 catch (PHPUnit_Framework_ExpectationFailedException $e) {
1242 $this->assertEquals(
1243 "custom message\nFailed asserting that an iterator contains \nstdClass Object\n(\n)\n.",
1244 $e->getDescription()