[Feature request] Report willReturn values incompatible with method signature
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 35/100
- Issue type
- Feature
- Clarity
- Mostly clear
- Activity status
- Stale
- Tech stack
- php
- Domain
- devtools, testing-qa
Research direction
Start with the PHP example using createMock(), method('foo'), and willReturn(123), then trace the existing PHPStan PHPUnit rules that inspect mock configurations. Confirm how the declared string return type and the configured int value should be compared; done means PHPStan reports the incompatible willReturn value with an actionable diagnostic.
Written by the indexing model from the issue text.
Description
Given
class MyClass
{
public function foo(): string {}
}
class MyOtherClassTest extends \PHPUnit\Framework\TestCase
{
public function testFooMock()
{
$class = $this->createMock(MyClass::class);
$class
->expects(static::once())
->method('foo')
->willReturn(123)
;
}
}
PHPUnit reports:
PHPUnit 8.2.0 by Sebastian Bergmann and contributors.
W 1 / 1 (100%)
Time: 173 ms, Memory: 16.00 MB
There was 1 warning:
1) MyOtherClassTest::testFooMock
Method foo may not return value of type int
WARNINGS!
Tests: 1, Assertions: 0, Warnings: 1.
It would be awesome if PHPStan could report this errors too.
- 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#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
-
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
-
a11y admissions.uiowa.edu needs grooming SiteImprove best practice
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
-
Save States Menu Open
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
pluginsGLPI/datainjection#673 ·