Hello.
This week I was researching how to increase code coverage and found a few
things that would make it easier to write unit tests and make the code
cleaner.
The main point is to use dependency injection whenever possible, as this
makes it easier to mock the dependencies. To facilitate this, we can reduce
the use of static methods in favor of instance methods. This would give us
a constructor method, which would make it easier to manage dependencies.
Another point is that we currently use $GLOBALS as a simplified service
locator. We can replace this with the dependency injection container. This
would reduce the 'action at a distance' problems, in addition to decoupling
the classes.
I would like to know what you think about it. Any feedback is welcome.
Maurício Meneghini Fauth