website/errors/phpunit.assertNull.md
<?php declare(strict_types = 1);
use PHPUnit\Framework\TestCase;
class MyTest extends TestCase
{
public function testFoo(): void
{
$value = null;
$this->assertSame(null, $value);
}
}
This rule is part of phpstan-phpunit.
When asserting that a value is null, assertNull() should be used instead of assertSame(null, $value). The dedicated method is more readable and provides clearer failure messages.
Replace assertSame(null, ...) with assertNull():
<?php declare(strict_types = 1);
use PHPUnit\Framework\TestCase;
class MyTest extends TestCase
{
public function testFoo(): void
{
$value = null;
- $this->assertSame(null, $value);
+ $this->assertNull($value);
}
}