Menu

← Back to phpunit.*

Error Identifier: phpunit.assertFalse

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(false, $this->getValue());
	}

	private function getValue(): bool
	{
		return false;
	}
}

Why is it reported? #

When assertSame() is called with the literal false as the expected value, it is clearer and more idiomatic to use assertFalse() instead. The assertFalse() method is specifically designed for this purpose and produces better failure messages.

This rule is provided by the phpstan-phpunit extension.

How to fix it #

Replace assertSame(false, ...) with assertFalse(...):

 <?php declare(strict_types = 1);
 
 use PHPUnit\Framework\TestCase;

 class MyTest extends TestCase
 {
 	public function testSomething(): void
 	{
-		$this->assertSame(false, $this->getValue());
+		$this->assertFalse($this->getValue());
 	}
 }

How to ignore this error #

You can use the identifier phpunit.assertFalse to ignore this error using a comment:

// @phpstan-ignore phpunit.assertFalse
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.assertFalse

Rules that report this error #

  • PHPStan\Rules\PHPUnit\AssertSameBooleanExpectedRule [1] phpstan/phpstan-phpunit

Edit this page on GitHub

Theme
A
© 2026 PHPStan s.r.o.