Code Inspection: 'assertTrue()' with incompatible argument type
Configure inspections: Settings | Editor | Inspections
Show intention actions: AltEnter
Reports the PHPUnit assertTrue()
calls whose arguments are of incompatible types. Since the assertTrue()
method relies on strict types comparison with true
, such assertions will always fail.
In the following example, the performAction()
function returns a value of integer
type, so the PHPUnit assertion will always fail. After the quick-fix is applied, the returned value is cast to boolean
; as a result, the assertion will only fail in case 0
is returned and will pass otherwise. For more information about type conversions in PHP, refer to Type Casting (php.net).
Before the quick-fix
function performAction() : int {}class Test extends TestCase { function doTest() { $this->assertTrue(performAction()); }}
After the quick-fix
function performAction() : int {}class Test extends TestCase { function doTest() { $this->assertTrue((bool)performAction()); }}
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.