-
Notifications
You must be signed in to change notification settings - Fork 58
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
Support for testing/mocking #16
Comments
Yup this is a must. I like the general interface you've lined out here. I'll think on it, and also take a look at the Laravel Event and Bus fakes to see if there's something I can leverage there. I might be able to knock something out here in the next day or two, depending on how much the new kiddos sleep 😅 |
No worries, I have a proof of concept on a fork that I can use in the meantime. Just working on one last piece and then I'll link it here. |
That would be wonderful! |
Okay here it is: https://github.com/owenconti/sidecar/pull/1/files Everything is new code except for the You'd probably want to add a dedicated method for asserting an async execution vs a sync execution too. |
This is amazing. Thank you for doing this! |
No worries, hopefully it helps some! |
Since
https://laravel.com/docs/9.x/mocking#mocking-facades Your method is also adding testing code in runtime classes. Laravel's strategy with fakes is to encapsulate the testing code in a separate fake class and swap them out in the fake method. This ensures that the testing code affects the runtime code as little as possible. Here's code for the Mail fake method as an example: But I don't believe it's necessary to create a fake class for just recording method executions. The mocking illustrated above does that already. Also read further in the docs about Facade spies. |
I tried to do it as you indicated as I think it looks great, but I couldn't do it, I get an error about an incorrect number of parameters.
|
If you look at the error you can see sidecar is adding two additional parameters to the execute call, false and 'RequestResponse'. Setting up my test like this worked as described:
|
It would be awesome if the package supported the ability to fake/mock a Sidecar execution, ie:
The idea here would be to keep the faking pattern similar to the Laravel first-party fakes (Http, Queue, etc):
fake()
with a mocked response for the lambdaThe text was updated successfully, but these errors were encountered: