#85 assertEmpty()

open
nobody
5
2011-12-02
2011-12-02
No

I've added these simple one to my own UnitTestCase subclass and am using them all the time to test if an array is empty or not.
For some reason using empty() directing in an assertTrue fails to compile, so these may be convenient to include.

function assertEmpty($value, $message = '%s') {
$dumper = new SimpleDumper();
$message = sprintf(
$message,
'[' . $dumper->describeValue($value) . '] should be empty');
return $this->assertTrue(empty($value), $message);
}

function assertNotEmpty($value, $message = '%s') {
$dumper = new SimpleDumper();
$message = sprintf(
$message,
'[' . $dumper->describeValue($value) . '] should not be empty');
return $this->assertTrue(! empty($value), $message);
}

Discussion