-
Notifications
You must be signed in to change notification settings - Fork 55
Open
Description
Problem
PHPStan includes phpstan/phpstan-phpunit, but it doesn't seem to recognize mocks.
- phpstan-phpunit 2.0.16 ships with a stub file, MockObject.stub, which contains an empty
MockObjectinterface without anexpects()method. - When PHPStan analyzes your code, it uses the stub file instead of the real PHPUnit interface.
- This causes PHPStan to not see the expects() method on mock objects.
This is a bug in phpstan-phpunit 2.0.16. The stub file, MockObject.stub, must contain a definition of theexpects()method.
Reason
Bug in phpstan/phpstan-phpunit version 2.0.16
The stub file /home/mihail/proj/task/vendor/phpstan/phpstan-phpunit/stubs/MockObject.stub contains an empty MockObject interface without an expects() method:
// vendor/phpstan/phpstan-phpunit/stubs/MockObject.stub
namespace PHPUnit\Framework\MockObject;
interface MockObject
{
// EMPTY - no expects() method!
}
However, the real MockObject interface in PHPUnit 11.x has an expects() method:
// vendor/phpunit/phpunit/src/Framework/MockObject/Runtime/Interface/MockObject.php
interface MockObject extends Stub
{
public function expects(InvocationOrder $invocationRule): InvocationMocker;
}
PHPStan uses the stub file instead of the real class, so it doesn't see the expects() method.
Solution
Correct the stub file in phpstan-phpunit. You need to add the expects() method to MockObject.stub.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels