Feature request: Validate `with` and `willReturn` types on mocks
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 48/100
Research direction
Start with the PHPStan/PHPUnit integration and the example in the issue, since no files or tests are named. Done means detecting mismatched parameter types passed to with and an incompatible return value supplied to willReturn, with coverage demonstrating both reports.
Written by the indexing model from the issue text.
Description
Given the following example, i'd expect PHPStan to report the following issues:
- The parameter types in
withdon't match the function signature - The return value does not match the function signature.
This would be usefull for projects with a large test suite, where you do a refactor of a method that is used in a lot of places. It would allow to fix these issues before running the entire test suite to get the errors from PHPUnit.
class T1 {
public function myMethod(int $a, string $b): int {
return 3;
}
}
class T1Test extends TestCase {
public function testStuff(): void {
$mock = $this->createMock(T1::class);
$mock->expects($this->once())
->method('myMethod')
->with(
new \stdClass(),
new \stdClass(),
)->willReturn(true);
}
}
- 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
-
bug
Difficulty 3/5 1-2 days Newbie friendliness 68/100
phpstan/phpstan-phpunit#332 · 2 comments ·
-
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 ·
-
Difficulty 4/5 3-5 days Newbie friendliness 20/100
phpstan/phpstan-phpunit#291 ·
All issues in phpstan/phpstan-phpunit
Similar issues
-
status/awaiting_triage
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
-
Difficulty 1/5 Under an hour Newbie friendliness 90/100
WordPress/plugin-check#1486 ·
-
enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
az-digital/az_quickstart#6019 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
grokability/snipe-it#19688 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 85/100