PEAR is archived and read-only

This mirror preserves historical PEAR package releases and metadata so existing references remain available.

Home » Testing » PHPUnit » Bug #8987

Assert::assertXXX() methods return type (value)

Details

Request #8987Assert::assertXXX() methods return type (value)
Submitted2006-10-12 08:32 UTC
Frommat127 at centrum dot cz
Assignedsebastian
StatusClosed
PackagePHPUnit
PHP Version4.3.8
OSLinux
Roadmaps(Not assigned)

Comments

[2006-10-12 08:32 UTC] mat127 at centrum dot cz

Description:
------------
It would be nice if the assertXXX() methods of the PHPUnit_Assert class will return the boolean result of requested check so that the caller TestCase class can react to it. Currently they return void according to documentation and even the code.

Test script:
---------------
/*
Our experience is that sometimes it is neccessary to break test method after some assertion call that fail because following assertions wold produce PHP errors or some other unwanted state. For example:
*/
function testSomething() {

$result = callSomeMethod();

/* now test that result is array */
$this->assertTrue(is_array($result));

/* if previous assertion fail other tests are
meaningless or produce errors so we need to ignore
following code*/
if(!is_array($result))
return;

/* test if it contains some value
without previous if -> return will produce error */
$this->assertTrue(in_array('value', $result))

}

Expected result:
----------------
/*
So what I am trying to show here is that it would be nice to rewrite previous example like this:
*/
function testSomething() {

$result = callSomeMethod();

/* now test that result is array and react immediately */
if(!$this->assertTrue(is_array($result)))
return;

/* test if it contains some value
without previous if -> return will produce error */
$this->assertTrue(in_array('value', $result))
}

[2006-10-12 08:46 UTC] sebastian at php dot net

There will be no new features for PHPUnit for PHP 4.
Also note that issues related PHPUnit should now be filed at http://www.phpunit.de/.