-
Notifications
You must be signed in to change notification settings - Fork 1
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
Inject methods with mocked dependencies #2
Comments
I've had a task open on this for Impersonator for a while. I think the hardest part is figuring out what is a dependency and what is not. Here's how I was planning to implementing it: // string -> string -> Map<string, mixed> -> mixed
$impersonator->call(SomeClass::class, 'someMethod', ['userId' => 456]); Everything that is not provided in the arguments array is considered a dependency. The developer is expected to fill out every argument without type hints. Everything else should be a mock previously provided by the developer or automatically mocked. |
Good idea 👍 The nice thing about |
For reference, here's my implementation: https://phabricator.chromabits.com/diffusion/NC/browse/master/src/Chromabits/Nucleus/Testing/Impersonator.php;37e11b98d0b851f4c01578ce73eef6b5d2342fe5$363 |
Another thing to consider is default values. I need to add that. Essentially, if an argument is not provided, we should try to find a default value first before failing. |
As of Laravel 5, Controller methods can utilize dependency injection. We should be able to deal with this by proxying the call to each method with a wrapper function
call
inInjectedTrait
.i.e.
In our tests, I'd like to be able to do:
The exact way this works is up for debate, but
args
should not be added directly to the test case, since the names of the dependencies may clash with class dependencies.The text was updated successfully, but these errors were encountered: