mockery / mockery

Mockery is a simple yet flexible PHP mock object framework for use in unit testing with PHPUnit, PHPSpec or any other testing framework. Its core goal is to offer a test double framework with a succinct API capable of clearly defining all possible object operations and interactions using a human readable Domain Specific Language (DSL).
http://docs.mockery.io/en/stable/
BSD 3-Clause "New" or "Revised" License
10.63k stars 456 forks source link

1.6.12 typehint issue with spy methods #1421

Open brettmc opened 5 months ago

brettmc commented 5 months ago

Mockery Version

1.6.12

PHP Version

PHP 8.3

Issue Description

After updating to mockery 1.6.12 today, both my IDE (phpstorm 2024.1.1) and psalm (5.24.0) started complaining about missing methods, which seems to only happen on mocks created via Mockery::spy():

Method Mockery\LegacyMockInterface::once does not exist (see https://psalm.dev/181)
Method Mockery\LegacyMockInterface::with does not exist (see https://psalm.dev/181)

It still works (as in, tests with these spies run and work as expected), but static analysis is not happy. We also use psalm/plugin-mockery (latest version).

Steps to Reproduce

$mock = Mockery::spy(SpanProcessorInterface::class);
$mock
  ->shouldHaveReceived('some.method')
  ->once()
  ->with('some.parameter');

Expected Behavior

No response

Actual Behavior

No response

Exception or Error

No response

Additional Information

The phpunit tests extend MockeryTestCase. I also tried using mock()->shouldIgnoreMissing() which had the same issue.

ghostwriter commented 5 months ago

Hey @brettmc,

Thanks for reporting this issue.

I'm actively working on a patch on a local branch to fix this and other similar issues.

I'll provide a link to the pull request once it's ready for review.

ghostwriter commented 5 months ago

Hey @brettmc,

Thanks for your patience, pull request #1427 is ready for review.