phpunit icon indicating copy to clipboard operation
phpunit copied to clipboard

Is assertEmpty( x ) supposed to behave like assertTrue( empty( x ) )?

Open isokissa opened this issue 11 years ago • 2 comments

The following code will complain that element with index "nonexisting" does not exist:

$a = array();
$this->assertEmpty( $a["nonexisting"] );

I wonder is it expected behavior, because it is not what empty() will do. Somehow logical would be that assertEmpty(x) is equivalent to assertTrue(empty(x)), at least in my opinion.

isokissa avatar Dec 29 '14 00:12 isokissa

Thanks for the bug report, @isokissa. It's called assertEmpty() because the implementation uses empty() (see here). There's not really much we can do about the notice since it's generated outside of PHPUnit's code. You might want to try assertArrayHasKey().

whatthejeff avatar Dec 29 '14 09:12 whatthejeff

I see, it is a PHP feature, a bit not nice one. Maybe this detail can be mentioned in the documentation for assertEmpty(), when committing next time ;)

isokissa avatar Dec 29 '14 15:12 isokissa