Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow code completion for andReturnSelf() #1021

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

kohlerdominik
Copy link

@kohlerdominik kohlerdominik commented Nov 7, 2019

This PR allows code completion for the andReturnSelf()-method by adding the MockInterface as return type.
It uses the same return types as the getMock()-method.


For this example, code completion would now the way we'd expect:

$builder->shouldReceive('addThis')
	->andReturnSelf()
	->shouldReceive('addThat')
	->with(13)
	->andReturnSelf()
	->shouldReceive('get')
	->with(23)
	->andReturn($object);

updated to add parameter example

@robertbasic
Copy link
Collaborator

Wouldn't you do this with a demeter chain mock?

@kohlerdominik
Copy link
Author

kohlerdominik commented Nov 7, 2019

Wouldn't you do this with a demeter chain mock?

Thanks for your input!
I stripped my example a little to much. My use case would be with parameters, which isn't supported by the demeter chain:

$builder->shouldReceive('addThis')
	->andReturnSelf()
	->shouldReceive('addThat')
	->with(13)
	->andReturnSelf()
	->shouldReceive('get')
	->with(23)
	->andReturn($object);

@davedevelopment
Copy link
Collaborator

Not sure on this one. It works in practice, but only because you usually receive a CompositeExpectation from Mock::shouldReceive. CompositeExpectation has the __call to pass unknown calls back to the mock.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants