I’m trying to find out the best way to write my code for better unit testing and such. Currently I have 2 main concerns:
- I use the service container to get the service I need within a class method, I’m concerned that this may not be the best way to do it as I rely on those services to be ready first
- I also use a main “settings” class which I can access many settings across modules/plugins. I’m also concerned that this creates an unnecessary dependency on this settings
Some sample code to clarify my issues:
class ABC
{
function someFunction(){
if(Container::get('settings')->get('status'))
{
Container::get('mailer')->send();
}
}
}
Perhaps all I should do is to inject these via the constructor method first?
You could to make the folow:
The test class: