Feature request: Validate `with` and `willReturn` types on mocks
Maintainers usually reply within 1 day
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
- 547
- Forks
- 61
- Avg merge
- 1d 9h
- Merged PRs (30d)
- 13
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
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 2/5 1-3 hours Newbie friendliness 63/100
phpstan/phpstan-phpunit#361 ·
Maintainers usually reply within 1 day
-
Difficulty 4/5 3-5 days Newbie friendliness 48/100
phpstan/phpstan-phpunit#309 ·
Maintainers usually reply within 1 day
-
Difficulty 3/5 1-2 days Newbie friendliness 45/100
phpstan/phpstan-phpunit#299 · 2 comments ·
Maintainers usually reply within 1 day
-
Difficulty 3/5 1-2 days Newbie friendliness 52/100
phpstan/phpstan-phpunit#292 · 3 comments ·
Maintainers usually reply within 1 day
-
Difficulty 4/5 3-5 days Newbie friendliness 20/100
phpstan/phpstan-phpunit#291 ·
Maintainers usually reply within 1 day
All issues in phpstan/phpstan-phpunit
Similar issues
-
bug needs grooming
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
HE-Arc/le-panier-du-coin#49 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
Maintainers usually reply within 2 days
-
15.0
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
woocommerce/woocommerce-subscriptions-importer-exporter#298 ·