Using makeWith in combination with mocking
Using makeWith in combination with mocking
In my code I'm using makeWith
to resolve dependencies.
In my tests I'm creating a mock that should be resolved in the code by calling the makeWith
. However it's not the case.
makeWith
makeWith
App::make('AppItem'); //ok: returns mock
App::makeWith('AppItem', ['name' => 'apple'];//not ok: doesn't return the mock but the class to be used outside the test environment
Is this a bug or am I missing something?
1 Answer
1
To set mock object use
App::offsetSet('AppItem', $itemMock);
Now
App::makeWith('AppItem', ['name' => 'apple']);
Returns $itemMock
$itemMock
Thanks for contributing an answer to Stack Overflow!
But avoid …
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
But avoid …
To learn more, see our tips on writing great answers.
Required, but never shown
Required, but never shown
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.