Missing mock type information for Mockery\Expectation::getMock()
Nobody has claimed this yet.
Assessment
- Difficulty
- 5/5
- Estimated time
- Over a week
- Newbie friendliness
- 30/100
Research direction
Start at the Mockery::mock(), MockInterface::shouldReceive(), and Expectation::getMock() entry points described in the issue, then trace how this extension represents their return types. Done means the mocked type is preserved through the fluent chain so the shown getMock() example is accepted by PHPStan; the payload names no repository files or tests to run.
Written by the indexing model from the issue text.
Description
Mockery::mock() returns a Mockery\MockInterface. MockInterface::shouldReceive() et al returns an Mockery\Expectation, which in turn has a getMock() method to return the MockInterface the Expectation belongs to.
The problem is that phpstan says the return type of Expectation::getMock() is Mockery\MockInterface with no type information on what was originally mocked. So for example
interface A {
foo(): void
}
function getMock(): A
{
return Mockery::mock(A::class)
->shouldReceive('foo')
->getMock();
}
will cause the following phpstan error: Function getMock() should return A but returns Mockery\MockInterface.
Of course the code in getMock() can be rewritten to not be fluent so that the return value of Mockery::mock() is returned instead, however in many cases I mock objects inline in some other expression and when I do that it's really helpful to be able to use the fluent way of writing the expectations.
Is it possible to change the type of the return value of Mockery\Expectation::getMock() to include the type information of the original mock? With generics I guess it should be something like Mockery::mock(T): MockInterface<T>, MockInterface<T>::shouldReceive(): Expectation<T> and Expectation<T>::getMock(): MockInterface<T>.
- Dominant language
- PHP
- Stars
- 109
- Forks
- 25
- Avg merge
- 1h 41m
- Merged PRs (30d)
- 1
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-mockery
-
Difficulty 4/5 3-5 days Newbie friendliness 45/100
phpstan/phpstan-mockery#78 ·
-
Difficulty 3/5 1-2 days Newbie friendliness 35/100
phpstan/phpstan-mockery#77 · 1 reaction ·
-
Dependency DashboardOpen
Difficulty 4/5 3-5 days Newbie friendliness 10/100
phpstan/phpstan-mockery#46 ·
-
Difficulty 3/5 1-2 days Newbie friendliness 35/100
phpstan/phpstan-mockery#34 · 1 comment ·
-
Difficulty 4/5 3-5 days Newbie friendliness 28/100
phpstan/phpstan-mockery#18 · 1 comment · 6 reactions ·
All issues in phpstan/phpstan-mockery
Similar issues
-
bug
Difficulty 1/5 Under an hour Newbie friendliness 85/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 63/100
smarty-php/smarty#1215 ·
-
sync-en
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
Maintainers usually reply within 1 day
-
sync-en
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Maintainers usually reply within 4 days
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
ProfessionalWiki/NeoWiki#1637 ·
Maintainers usually reply within 1 day