PHPStan includes phpstan/phpstan-phpunit, but it doesn't seem to recognize mocks.
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 55/100
Research direction
Start with vendor/phpstan/phpstan-phpunit/stubs/MockObject.stub and compare it with vendor/phpunit/phpunit/src/Framework/MockObject/Runtime/Interface/MockObject.php. Check how PHPStan uses the stub, then update the stub so the MockObject interface exposes the expects() method shown in the PHPUnit interface. Done means PHPStan recognizes expects() on PHPUnit mock objects.
Written by the indexing model from the issue text.
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.
- Dominant language
- PHP
- Stars
- 544
- Forks
- 58
- Avg merge
- 2d 1h
- Merged PRs (30d)
- 5
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from phpstan/phpstan-phpunit
-
Difficulty 3/5 1-2 days Newbie friendliness 68/100
phpstan/phpstan-phpunit#332 ·
-
Difficulty 4/5 3-5 days Newbie friendliness 48/100
phpstan/phpstan-phpunit#321 ·
-
Difficulty 4/5 3-5 days Newbie friendliness 48/100
phpstan/phpstan-phpunit#309 ·
-
Difficulty 3/5 1-2 days Newbie friendliness 45/100
phpstan/phpstan-phpunit#299 · 2 comments ·
-
Difficulty 3/5 1-2 days Newbie friendliness 52/100
phpstan/phpstan-phpunit#292 · 3 comments ·
All issues in phpstan/phpstan-phpunit
Similar issues
-
sync-en
Difficulty 1/5 1-3 hours Newbie friendliness 88/100
-
sync-en
Difficulty 1/5 1-3 hours Newbie friendliness 88/100
-
Перевод устарел
Difficulty 1/5 1-3 hours Newbie friendliness 88/100
-
status/awaiting_triage
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
-
Issue: ready for confirmation Reported on 2.4.x
Difficulty 2/5 1-3 hours Newbie friendliness 88/100