Skip to content

Regression: ObjectProphecy no longer correctly handled #154

@Jean85

Description

@Jean85

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions