Menu
Error Identifier: phpunit.assertTrue
Every error reported by PHPStan has an error identifier. Here’s a list of all error identifiers. In PHPStan Pro you can see the error identifier next to each error and filter errors by their identifiers.
Code example #
<?php declare(strict_types = 1);
use PHPUnit\Framework\TestCase;
class MyTest extends TestCase
{
public function testSomething(): void
{
$this->assertSame(true, $this->isValid());
}
}
Why is it reported? #
When the expected value in assertSame() is the literal true, using assertTrue() is more idiomatic and produces clearer failure messages. PHPUnit provides dedicated assertion methods for boolean values.
How to fix it #
Replace assertSame(true, ...) with assertTrue(...):
-$this->assertSame(true, $this->isValid());
+$this->assertTrue($this->isValid());
How to ignore this error #
You can use the identifier phpunit.assertTrue to ignore this error using a comment:
// @phpstan-ignore phpunit.assertTrue
codeThatProducesTheError();
You can also use only the identifier key to ignore all errors of the same type in your configuration file in the ignoreErrors parameter:
parameters:
ignoreErrors:
-
identifier: phpunit.assertTrue
Rules that report this error #
- PHPStan\Rules\PHPUnit\AssertSameBooleanExpectedRule [1] phpstan/phpstan-phpunit