Tests fight legacy

Automated tests are the best tool to fight legacy code.

By having automated tests such as unit tests or behavioral tests, you are able to refactor legacy code effectively with confidence that little can be broken.

Badly written systems often consist of tightly coupled functions. One change to a function in one class may well break a function in a completely different class, leading to a domino effect of more classes being broken until the entire application is broken.

In order to decouple classes and follow practices such as the Single Responsibility Principle, refactoring must be carried out. Any refactoring effort must be sure not to break code elsewhere in an application.

This brings us onto the topic of test coverage: is it ...

Get Mastering PHP Design Patterns now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.