psalm-plugin-phpunit icon indicating copy to clipboard operation
psalm-plugin-phpunit copied to clipboard

Regression: ObjectProphecy no longer correctly handled

Open Jean85 opened this issue 7 months ago • 0 comments

I'm using:

  • Psalm 6.10.3
  • psalm/plugin-phpunit 0.19.4
  • psalm/plugin-symfony 5.2.7
  • phpspec/prophecy-phpunit 2.3.0

Using this as a minimal reproduction:

<?php

declare(strict_types=1);

namespace Tests\Functional\Client;

use PHPUnit\Framework\TestCase;
use Prophecy\PhpUnit\ProphecyTrait;
use Prophecy\Prophecy\ObjectProphecy;
use Psr\Http\Message\ResponseInterface;

class ClientTest extends TestCase
{
    use ProphecyTrait;
    
    public function test(): void
    {
        $response = $this->prophesize(ResponseInterface::class);
        /** @psalm-check-type $response = ObjectProphecy<ResponseInterface> */
        $response->getStatusCode()->shouldBeCalled()->willReturn(202);

        $response = $response->reveal();
        $this->assertSame(202, $response->reveal()->getStatusCode());
    }
}

When upgrading from 0.19.3 to 0.19.4, I get this error:

ERROR: UndefinedMagicMethod - tests/Functional/Client/ClientTest.php:18:20 - Magic method Prophecy\Prophecy\ObjectProphecy::getstatuscode does not exist (see https://psalm.dev/219)
        $response->getStatusCode()->shouldBeCalled()->willReturn(202);

I checked with @psalm-check-type so the generic is correctly recognised.

Jean85 avatar May 15 '25 16:05 Jean85