PEAR is discontinued

This is a static archive preserving historical releases and metadata. No new packages or updates will be published. For updates to existing packages, or to publish new packages, please use Composer and Packagist.

Home » Testing » PHPUnit » Bug #4529

$message is not used in assertContains()

Details

Submitted2005-06-04 22:11 UTC
Fromphp040604 at awks dot org
StatusClosed
PackagePHPUnit
PHP Version5.0.4
Roadmaps(Not assigned)

Comments

[2005-06-04 22:11 UTC] php040604 at awks dot org

Description:
------------
The $message parameter is ignored in assertContains()
and assertNotContains() when the parameters are strings.
This is similar to bug #2460.

patch:

--- Assert.php.orig Sat Jun 4 17:49:47 2005
+++ Assert.php Sat Jun 4 17:50:14 2005
@@ -42,7 +42,7 @@
*/
function assertContains($needle, $haystack,
$message = '') {
if (is_string($needle) && is_string($haystack))
{
- $this->assertTrue(strpos($haystack,
$needle) !== FALSE ? TRUE : FALSE);
+ $this->assertTrue(strpos($haystack,
$needle) !== FALSE, $message);
}

else if (is_array($haystack) && !
is_object($needle)) {
@@ -65,7 +65,7 @@
*/
function assertNotContains($needle, $haystack,
$message = '') {
if (is_string($needle) && is_string($haystack))
{
- $this->assertFalse(strpos($haystack,
$needle) !== FALSE ? TRUE : FALSE);
+ $this->assertFalse(strpos($haystack,
$needle) !== FALSE, $message);
}

else if (is_array($haystack) && !
is_object($needle)) {

This patch also removes the redundant "$bool ? TRUE :
FALSE" construct which reduces readability.

Reproduce code:
---------------
$this->assertContains('string', $var, 'custom message here');

Expected result:
----------------
Expected PHPUnit to include "custom message here" in the
output when that assertion fails.

Actual result:
--------------
Only prints: "expected TRUE, actual FALSE"

[2005-06-04 22:14 UTC] php040604 at awks dot org

Apologies for the messed-up patch. Here is a clean copy:
http://bnt.com/~awk/PHPUnit-4529.patch