-
Notifications
You must be signed in to change notification settings - Fork 461
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
Feature request: a way to capture arguments #508
Comments
@marcaube thank you for adding this! Just so you know, the way to do it now is to use I don't use $emitter->shouldReceive('addListener')->once()->with('foo.bar', m::on(function ($callable) {
$callable(new Event(), new Payload()); // I don't know the correct types, but you get the idea
}); That is, on receiving the second argument to "EmitterInterface::addListener", run it through this anonymous function, which in turn just runs the callable that was sent. |
Thanks for the workaround, I couldn't figure out how to do it on my own. |
Wow. I never knew, that |
@aik099 it's there for complicated matchers I believe |
For what it's worth, Mockery::on has a cookbook entry: http://docs.mockery.io/en/latest/cookbook/mockery_on.html |
@marcaube is the |
@robertbasic I think |
@marcaube fair enough, thanks for taking the time to reply! :) Given that the feature is in there, I'm going to close this issue. If someone still wants to see this done/improved in Mockery, feel free to reopen the ticket. You'll get bonus karma if you provide a pull request as well :) |
Took a stab at making this a bit more expressive with |
As requested by @davedevelopment on twitter, here's a feature request for a method to capture arguments, just like Phake::capture().
I had a situation recently where this would have been useful. I was writing a class to implement our
EventDispatcherInterface
usingleague/event
. With this library, listeners can be of typecallable
orLeague\Event\ListenerInterface
. To make it compatible with ourListenerInterface
, our dispatcher wraps the listeners in an anonymous function.In my unit tests, I'd like to make sure this
handle()
method is called on the listener with the proper arguments. But the only (obvious) way to do it would be to capture the second argument of theaddListener
expectation.The text was updated successfully, but these errors were encountered: