How can I use a PHP-DI Container to pass mock objects while unit testing?
I have a controller that handles various cronjobs and I wanted to write unit tests for each function in the controller. The controller (lets call it TasksController) extends a base controller (let’s call it BaseController). Previously, I was creating new objects of individual Task classes inside each concerned function, but since that’s bad practice (ref1 ref2)that makes one’s code hard to test, I used DI container to inject dependencies instead. A sample function from Task Controller would look like: