Code Inspection: Assertion can be replaced with 'assertEmpty/assertNotEmpty'
Reports the assertTrue
/ assertFalse
usages that can be replaced with assertEmpty
/ assertNotEmpty
in PHPUnit tests.
See assertEmpty (phpunit.readthedocs.io) for details.
In the following example, asserting whether the $arr
array is empty is initially performed by providing the empty()
and count()
functions calls as the conditions for the assertTrue
method. After the quick-fix is applied, the more specific assertEmpty
and assertNotEmpty
are used directly on the $arr
array.
class Test extends \PHPUnit\Framework\TestCase {
public function doTestTrue() {
$arr = ["a", "b", "c"];
$this->assertTrue(empty($arr));
$this->assertTrue(count($arr) <= 0);
$this->assertTrue(count($arr) != 0);
}
}
class Test extends \PHPUnit\Framework\TestCase {
public function doTestTrue() {
$arr = ["a", "b", "c"];
$this->assertEmpty($arr);
$this->assertEmpty($arr);
$this->assertNotEmpty($arr);
}
}
Suppress an inspection in the editor
Place the caret at the highlighted line and press Alt+Enter or click .
Click the arrow next to the inspection you want to suppress and select the necessary suppress action.
Last modified: 16 May 2022