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

Add capture argument matcher #1020

Merged
merged 2 commits into from Nov 20, 2019
Merged

Conversation

jasonmccreary
Copy link
Contributor

@jasonmccreary jasonmccreary commented Nov 6, 2019

This adds a simple closure argument matcher which will capture the argument into a local variable. This provides an easy way to store an argument passed to a mocked method for more complex validation without having to wrap all the logic inline within a Mockery::on() closure.

Example:

$temp = null;
$mock->expects('foo')
    ->with(Mockery::capture($temp));

$mock->foo($someObject);

// $temp === $someObject

@jasonmccreary
Copy link
Contributor Author

If approved, glad to add a section to the documentation. 👍

@davedevelopment
Copy link
Collaborator

Love it 👍

Copy link
Collaborator

@robertbasic robertbasic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, thanks! 👍

@mfn
Copy link
Contributor

mfn commented Nov 7, 2019

OMG, this looks so cool!

@jasonmccreary
Copy link
Contributor Author

@robertbasic great! Shall I open an accompanying PR for the docs?

@robertbasic
Copy link
Collaborator

@jasonmccreary maybe add it to this one? Either works fine, thanks :)

@jasonmccreary
Copy link
Contributor Author

@robertbasic oh, der, it's a monorepo. Will do. 👍

@jasonmccreary
Copy link
Contributor Author

@robertbasic took a stab at writing some documentation. Let me know.

@robertbasic
Copy link
Collaborator

@jasonmccreary looks good, thanks!

@robertbasic robertbasic merged commit 5963050 into mockery:master Nov 20, 2019
davedevelopment added a commit that referenced this pull request Nov 20, 2019
@jasonmccreary
Copy link
Contributor Author

@robertbasic Yay! Any chance for tagging a release. Would love to tweet/demo this new matcher afterward. 👍

@robertbasic
Copy link
Collaborator

@jasonmccreary I need to catch up on the changelog and then to tag a release. Early next week as it stands now, that ok?

@jasonmccreary jasonmccreary deleted the capture branch November 20, 2019 17:50
@jasonmccreary
Copy link
Contributor Author

@roberbase, Of course. I'll keep an eye out and do another tweet once it's tagged.

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

4 participants