Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Update all the assertions that depend on TraversableContains.

Also add tests for all the impacted assertions. (assert*Contains)
  • Loading branch information...
commit b0b0eda2f3dc475c5efc605277e7a91f6daf838d 1 parent 255f5cc
@farnoux farnoux authored
View
12 PHPUnit/Framework/Assert.php
@@ -160,16 +160,18 @@ public static function assertContains($needle, $haystack, $message = '', $ignore
* @param string $message
* @param boolean $ignoreCase
* @param boolean $checkForObjectIdentity
+ * @param boolean $checkForNonObjectIdentity
* @since Method available since Release 3.0.0
*/
- public static function assertAttributeContains($needle, $haystackAttributeName, $haystackClassOrObject, $message = '', $ignoreCase = FALSE, $checkForObjectIdentity = TRUE)
+ public static function assertAttributeContains($needle, $haystackAttributeName, $haystackClassOrObject, $message = '', $ignoreCase = FALSE, $checkForObjectIdentity = TRUE, $checkForNonObjectIdentity = FALSE)
{
self::assertContains(
$needle,
self::readAttribute($haystackClassOrObject, $haystackAttributeName),
$message,
$ignoreCase,
- $checkForObjectIdentity
+ $checkForObjectIdentity,
+ $checkForNonObjectIdentity
);
}
@@ -222,16 +224,18 @@ public static function assertNotContains($needle, $haystack, $message = '', $ign
* @param string $message
* @param boolean $ignoreCase
* @param boolean $checkForObjectIdentity
+ * @param boolean $checkForNonObjectIdentity
* @since Method available since Release 3.0.0
*/
- public static function assertAttributeNotContains($needle, $haystackAttributeName, $haystackClassOrObject, $message = '', $ignoreCase = FALSE, $checkForObjectIdentity = TRUE)
+ public static function assertAttributeNotContains($needle, $haystackAttributeName, $haystackClassOrObject, $message = '', $ignoreCase = FALSE, $checkForObjectIdentity = TRUE, $checkForNonObjectIdentity = FALSE)
{
self::assertNotContains(
$needle,
self::readAttribute($haystackClassOrObject, $haystackAttributeName),
$message,
$ignoreCase,
- $checkForObjectIdentity
+ $checkForObjectIdentity,
+ $checkForNonObjectIdentity
);
}
View
20 PHPUnit/Framework/Assert/Functions.php
@@ -114,11 +114,12 @@ function assertArrayNotHasKey($key, array $array, $message = '')
* @param string $message
* @param boolean $ignoreCase
* @param boolean $checkForObjectIdentity
+ * @param boolean $checkForNonObjectIdentity
* @since Method available since Release 3.0.0
*/
-function assertAttributeContains($needle, $haystackAttributeName, $haystackClassOrObject, $message = '', $ignoreCase = FALSE, $checkForObjectIdentity = TRUE)
+function assertAttributeContains($needle, $haystackAttributeName, $haystackClassOrObject, $message = '', $ignoreCase = FALSE, $checkForObjectIdentity = TRUE, $checkForNonObjectIdentity = FALSE)
{
- return PHPUnit_Framework_Assert::assertAttributeContains($needle, $haystackAttributeName, $haystackClassOrObject, $message, $ignoreCase, $checkForObjectIdentity);
+ return PHPUnit_Framework_Assert::assertAttributeContains($needle, $haystackAttributeName, $haystackClassOrObject, $message, $ignoreCase, $checkForObjectIdentity, $checkForNonObjectIdentity);
}
/**
@@ -277,11 +278,12 @@ function assertAttributeLessThanOrEqual($expected, $actualAttributeName, $actual
* @param string $message
* @param boolean $ignoreCase
* @param boolean $checkForObjectIdentity
+ * @param boolean $checkForNonObjectIdentity
* @since Method available since Release 3.0.0
*/
-function assertAttributeNotContains($needle, $haystackAttributeName, $haystackClassOrObject, $message = '', $ignoreCase = FALSE, $checkForObjectIdentity = TRUE)
+function assertAttributeNotContains($needle, $haystackAttributeName, $haystackClassOrObject, $message = '', $ignoreCase = FALSE, $checkForObjectIdentity = TRUE, $checkForNonObjectIdentity = FALSE)
{
- return PHPUnit_Framework_Assert::assertAttributeNotContains($needle, $haystackAttributeName, $haystackClassOrObject, $message, $ignoreCase, $checkForObjectIdentity);
+ return PHPUnit_Framework_Assert::assertAttributeNotContains($needle, $haystackAttributeName, $haystackClassOrObject, $message, $ignoreCase, $checkForObjectIdentity, $checkForNonObjectIdentity);
}
/**
@@ -463,11 +465,12 @@ function assertClassNotHasStaticAttribute($attributeName, $className, $message =
* @param string $message
* @param boolean $ignoreCase
* @param boolean $checkForObjectIdentity
+ * @param boolean $checkForNonObjectIdentity
* @since Method available since Release 2.1.0
*/
-function assertContains($needle, $haystack, $message = '', $ignoreCase = FALSE, $checkForObjectIdentity = TRUE)
+function assertContains($needle, $haystack, $message = '', $ignoreCase = FALSE, $checkForObjectIdentity = TRUE, $checkForNonObjectIdentity = FALSE)
{
- return PHPUnit_Framework_Assert::assertContains($needle, $haystack, $message, $ignoreCase, $checkForObjectIdentity);
+ return PHPUnit_Framework_Assert::assertContains($needle, $haystack, $message, $ignoreCase, $checkForObjectIdentity, $checkForNonObjectIdentity);
}
/**
@@ -771,11 +774,12 @@ function assertLessThanOrEqual($expected, $actual, $message = '')
* @param string $message
* @param boolean $ignoreCase
* @param boolean $checkForObjectIdentity
+ * @param boolean $checkForNonObjectIdentity
* @since Method available since Release 2.1.0
*/
-function assertNotContains($needle, $haystack, $message = '', $ignoreCase = FALSE, $checkForObjectIdentity = TRUE)
+function assertNotContains($needle, $haystack, $message = '', $ignoreCase = FALSE, $checkForObjectIdentity = TRUE, $checkForNonObjectIdentity = FALSE)
{
- return PHPUnit_Framework_Assert::assertNotContains($needle, $haystack, $message, $ignoreCase, $checkForObjectIdentity);
+ return PHPUnit_Framework_Assert::assertNotContains($needle, $haystack, $message, $ignoreCase, $checkForObjectIdentity, $checkForNonObjectIdentity);
}
/**
View
77 Tests/Framework/AssertTest.php
@@ -152,6 +152,25 @@ public function testAssertArrayContainsString()
$this->fail();
}
+
+ /**
+ * @covers PHPUnit_Framework_Assert::assertContains
+ */
+ public function testAssertArrayContainsNonObject()
+ {
+ $this->assertContains('foo', array(TRUE));
+
+ try {
+ $this->assertContains('foo', array(TRUE), '', FALSE, TRUE, TRUE);
+ }
+
+ catch (PHPUnit_Framework_AssertionFailedError $e) {
+ return;
+ }
+
+ $this->fail();
+ }
+
/**
* @covers PHPUnit_Framework_Assert::assertContainsOnlyInstancesOf
*/
@@ -446,6 +465,24 @@ public function testAssertArrayNotContainsString()
/**
* @covers PHPUnit_Framework_Assert::assertNotContains
*/
+ public function testAssertArrayNotContainsNonObject()
+ {
+ $this->assertNotContains('foo', array(TRUE), '', FALSE, TRUE, TRUE);
+
+ try {
+ $this->assertNotContains('foo', array(TRUE));
+ }
+
+ catch (PHPUnit_Framework_AssertionFailedError $e) {
+ return;
+ }
+
+ $this->fail();
+ }
+
+ /**
+ * @covers PHPUnit_Framework_Assert::assertNotContains
+ */
public function testAssertStringNotContainsString()
{
$this->assertNotContains('foo', 'bar');
@@ -1882,6 +1919,46 @@ public function testAssertPrivateAttributeNotContains()
}
/**
+ * @covers PHPUnit_Framework_Assert::assertAttributeContains
+ */
+ public function testAssertAttributeContainsNonObject()
+ {
+ $obj = new ClassWithNonPublicAttributes;
+
+ $this->assertAttributeContains(TRUE, 'privateArray', $obj);
+
+ try {
+ $this->assertAttributeContains(TRUE, 'privateArray', $obj, '', FALSE, TRUE, TRUE);
+ }
+
+ catch (PHPUnit_Framework_AssertionFailedError $e) {
+ return;
+ }
+
+ $this->fail();
+ }
+
+ /**
+ * @covers PHPUnit_Framework_Assert::assertAttributeNotContains
+ */
+ public function testAssertAttributeNotContainsNonObject()
+ {
+ $obj = new ClassWithNonPublicAttributes;
+
+ $this->assertAttributeNotContains(TRUE, 'privateArray', $obj, '', FALSE, TRUE, TRUE);
+
+ try {
+ $this->assertAttributeNotContains(TRUE, 'privateArray', $obj);
+ }
+
+ catch (PHPUnit_Framework_AssertionFailedError $e) {
+ return;
+ }
+
+ $this->fail();
+ }
+
+ /**
* @covers PHPUnit_Framework_Assert::assertAttributeEquals
*/
public function testAssertPublicAttributeEquals()
Please sign in to comment.
Something went wrong with that request. Please try again.