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

andReturnArgument() #992

Closed
downsider opened this issue Aug 13, 2019 · 3 comments
Closed

andReturnArgument() #992

downsider opened this issue Aug 13, 2019 · 3 comments

Comments

@downsider
Copy link
Contributor

Hi

In my experience with mockery, a number of times I have found myself needing to return an argument that was passed to a mocked method. In such cases, I have done something like this:

$mock->shouldReceive("myMethod")->andReturnUsing(
    function($arg){
        return $arg;
    });

This feels really clunky and boilerplatey, but is something commonly required for mocks of classes that do normalisation or follow the decorator pattern.

Seeing as PHPUnit has had this functionality for a long time, I feel we should introduce it into Mockery too. I propose we add the following syntax to enable returning arguments

$mock->shouldReceive("myMethod")->andReturnArgument(2);
    // where "2" is the index of the argument to return

Do you think this is something that can be implemented?

@davedevelopment
Copy link
Collaborator

I don't see why not, fire away 👍

@downsider
Copy link
Contributor Author

Hi @davedevelopment I've submitted a PR for this. Could you have a look at the comment I raised please? I'm interested in your opinion on this point.

@robertbasic
Copy link
Collaborator

Closing as #1001 was merged.

Thank you @downsider!

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

No branches or pull requests

3 participants