Hello
On Sat, 2018-01-20 at 15:30 -0200, Maurício Meneghini Fauth wrote:
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.
This seems as reasonable approach to make the code easier to test.
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.
Indeed getting rid of using global variables is good way - current code with several hidden dependecies on global variables is hard to test and diagnose.