psalm: assertEmpty in \PHPUnit\Framework\TestCase leasds to false positive

Unit test:

<?php declare(strict_types=1);

use \PHPUnit\Framework\TestCase;

class Foo implements \Countable
{
    /** @var array */
    protected $data;

    public function __construct()
    {
        $this->data = [];
    }

    public function count() : int
    {
        return count($this->data);
    }
}

class Test extends TestCase
{
    public function test() : void
    {
        $foo = new Foo();

        $this->assertEmpty($foo);
    }
}

False positive Error:

ERROR: TypeDoesNotContainType - testTest.php:29:16 - Found a contradiction when evaluating $foo and trying to reconcile type 'Vgl\Tests\Unit\Foo' to empty
        $this->assertEmpty($foo);

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 15

Most upvoted comments

It should be @psalm-assert empty|Countable $actual

Oh sorry, didn’t see it’s countable