The source and idea for this post is via Google TechTalksWHY? To test a method: 1) we need to instantiate an object (system under test) and all the helpers(mock providers, stubs), etc. but it turns out that we put a lot of code in the constructor which makes it very difficult to create an object of it.

But instead of this, if I ask for what I need : What I can do now is, while testing, I can mock get method of $pestObj and we won't actually have to make get request.

So here we have a problem, in order to give a class we need to give service locator and in order to give service locator we need to give most part of our application.
Newsletter

Get the latest Laravel/PHP jobs, events and curated articles straight to your inbox, once a week

Glimpse streamlines Laravel development by seamlessly deploying GitHub pull requests to preview environments with the help of Laravel Forge. Glimpse streamlines Laravel development by seamlessly deploying GitHub pull requests to preview environments with the help of Laravel Forge.
Fathom Analytics | Fast, simple and privacy-focused website analytics. Fathom Analytics | Fast, simple and privacy-focused website analytics.
Shirts painstakingly handcrafted by under-caffeinated developers. Shirts painstakingly handcrafted by under-caffeinated developers.
Community Partners