cvs: pear /PHPUnit2 package.xml /PHPUnit2/Framework Assert.php /PHPUnit2/Tests/Framework AssertTest.php

From: Date: Mon, 25 Oct 2004 14:36:25 +0000
Subject: cvs: pear /PHPUnit2 package.xml /PHPUnit2/Framework Assert.php /PHPUnit2/Tests/Framework AssertTest.php
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-25198@lists.php.net to get a copy of this message
sebastian Mon Oct 25 10:36:25 2004 EDT Modified files: /pear/PHPUnit2 package.xml /pear/PHPUnit2/Framework Assert.php /pear/PHPUnit2/Tests/Framework AssertTest.php Log: Let PHPUnit2_Framework_Assert::assertContains() and PHPUnit2_Framework_Assert::assertNotContains() accept an object that offers the Iterator interface for the $haystack parameter. http://cvs.php.net/diff.php/pear/PHPUnit2/package.xml?r1=1.63&r2=1.64&ty=u Index: pear/PHPUnit2/package.xml diff -u pear/PHPUnit2/package.xml:1.63 pear/PHPUnit2/package.xml:1.64 --- pear/PHPUnit2/package.xml:1.63 Sun Oct 24 15:50:03 2004 +++ pear/PHPUnit2/package.xml Mon Oct 25 10:36:24 2004 @@ -25,6 +25,8 @@ + Added a Templating API to the test class skeleton generator to customize the generated source. + Added PHPUnit2_Extensions_ExceptionTestCase::getExpectedException() and PHPUnit2_Extensions_ExceptionTestCase::setExpectedException(). + +* PHPUnit2_Framework_Assert::assertContains() and PHPUnit2_Framework_Assert::assertNotContains() now accept an object that offers the Iterator interface for the $haystack parameter. ]]> </notes> <filelist> http://cvs.php.net/diff.php/pear/PHPUnit2/Framework/Assert.php?r1=1.19&r2=1.20&ty=u Index: pear/PHPUnit2/Framework/Assert.php diff -u pear/PHPUnit2/Framework/Assert.php:1.19 pear/PHPUnit2/Framework/Assert.php:1.20 --- pear/PHPUnit2/Framework/Assert.php:1.19 Thu Oct 7 05:05:23 2004 +++ pear/PHPUnit2/Framework/Assert.php Mon Oct 25 10:36:25 2004 @@ -12,7 +12,7 @@ // | license@php.net so we can mail you a copy immediately. | // +------------------------------------------------------------------------+ // -// $Id: Assert.php,v 1.19 2004/10/07 09:05:23 sebastian Exp $ +// $Id: Assert.php,v 1.20 2004/10/25 14:36:25 sebastian Exp $ // require_once 'PHPUnit2/Framework/AssertionFailedError.php'; @@ -63,30 +63,25 @@ * @since 2.1.0 */ public static function assertContains($needle, $haystack, $message = '') { - if (is_string($needle) && is_string($haystack)) { - if (strpos($haystack, $needle) === FALSE) { + if (is_array($haystack) || + (is_object($haystack) && $haystack instanceof Iterator)) { + $found = FALSE; + + foreach ($haystack as $straw) { + if ($straw === $needle) { + $found = TRUE; + break; + } + } + + if (!$found) { self::failNotContains($needle, $haystack, $message); } } - else if (is_array($haystack)) { - if (is_object($needle)) { - $found = FALSE; - - foreach ($haystack as $straw) { - if ($straw === $needle) { - $found = TRUE; - break; - } - } - - if (!$found) { - self::failNotContains($needle, $haystack, $message); - } - } else { - if (!in_array($needle, $haystack)) { - self::failNotContains($needle, $haystack, $message); - } + else if (is_string($needle) && is_string($haystack)) { + if (strpos($haystack, $needle) === FALSE) { + self::failNotContains($needle, $haystack, $message); } } @@ -109,30 +104,25 @@ * @since 2.1.0 */ public static function assertNotContains($needle, $haystack, $message = '') { - if (is_string($needle) && is_string($haystack)) { - if (strpos($haystack, $needle) !== FALSE) { - self::failContains($needle, $haystack, $message); + if (is_array($haystack) || + (is_object($haystack) && $haystack instanceof Iterator)) { + $found = FALSE; + + foreach ($haystack as $straw) { + if ($straw === $needle) { + $found = TRUE; + break; + } } - } - - else if (is_array($haystack)) { - if (is_object($needle)) { - $found = FALSE; - foreach ($haystack as $straw) { - if ($straw === $needle) { - $found = TRUE; - break; - } - } + if ($found) { + self::failNotContains($needle, $haystack, $message); + } + } - if ($found) { - self::failContains($needle, $haystack, $message); - } - } else { - if (in_array($needle, $haystack)) { - self::failContains($needle, $haystack, $message); - } + else if (is_string($needle) && is_string($haystack)) { + if (strpos($haystack, $needle) !== FALSE) { + self::failNotContains($needle, $haystack, $message); } } http://cvs.php.net/diff.php/pear/PHPUnit2/Tests/Framework/AssertTest.php?r1=1.11&r2=1.12&ty=u Index: pear/PHPUnit2/Tests/Framework/AssertTest.php diff -u pear/PHPUnit2/Tests/Framework/AssertTest.php:1.11 pear/PHPUnit2/Tests/Framework/AssertTest.php:1.12 --- pear/PHPUnit2/Tests/Framework/AssertTest.php:1.11 Fri Oct 1 02:11:29 2004 +++ pear/PHPUnit2/Tests/Framework/AssertTest.php Mon Oct 25 10:36:25 2004 @@ -12,10 +12,11 @@ // | license@php.net so we can mail you a copy immediately. | // +------------------------------------------------------------------------+ // -// $Id: AssertTest.php,v 1.11 2004/10/01 06:11:29 sebastian Exp $ +// $Id: AssertTest.php,v 1.12 2004/10/25 14:36:25 sebastian Exp $ // require_once 'PHPUnit2/Framework/TestCase.php'; +require_once 'PHPUnit2/Framework/IncompleteTestError.php'; /** * @author Sebastian Bergmann <sb@sebastian-bergmann.de> @@ -69,6 +70,14 @@ $this->fail(); } + public function testAssertIteratorContainsObject() { + throw new PHPUnit2_Framework_IncompleteTestError; + } + + public function testAssertIteratorContainsString() { + throw new PHPUnit2_Framework_IncompleteTestError; + } + public function testAssertStringContainsString() { $this->assertContains('foo', 'foobar');

« previous php.pear.cvs (#25198) next »