Code Inspection: Assertion can be replaced with 'assertEmpty/assertNotEmpty'
Configure inspections: Settings | Editor | Inspections
Show intention actions: AltEnter
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.
Before the quick-fix
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); }}
After the quick-fix
class Test extends \PHPUnit\Framework\TestCase { public function doTestTrue() { $arr = ["a", "b", "c"]; $this->assertEmpty($arr); $this->assertEmpty($arr); $this->assertNotEmpty($arr); }}
Place the caret at the highlighted line and press AltEnter or click
.
Click the arrow next to the inspection you want to suppress and select the necessary suppress action.