phpunit icon indicating copy to clipboard operation
phpunit copied to clipboard

assertContains is not type-safe for (non-object) primitive types

Open farnoux opened this issue 13 years ago • 3 comments

Currently the $checkForObjectIdentity parameter, as its name indicates, only check identity for object elements. Is there any reason the assertContains() method doesn't check identity also for primitive types?

Example:

$this->assertContains('hello', array(10, 45, 0)); // Success :(

This assert is unexpectedly successful due to the fact that 0 == 'hello' returns true. This is successful whatever the value of the $checkForObjectIdentity parameter, because it only applies for elements of type Object.

farnoux avatar Dec 11 '12 16:12 farnoux

Appears to be an issue again with latest stable as of the date of this writing.

mhousser avatar Mar 10 '16 03:03 mhousser

@mhousser Please open a new ticket that include a minimal, self-contained, reproducing test case.

sebastianbergmann avatar Mar 10 '16 06:03 sebastianbergmann

#2111 here you go. easy for me to reproduce in 5.2.10.

mhousser avatar Mar 10 '16 07:03 mhousser