Anna Filina has a quick post to her site with some recommendations around testing legacy PHP scripts giving an example of a challenge to test a controller in isolation from the rest of the application.
I gave myself a challenge: to test a legacy "controller" in isolation, yet with minimal impact on the original code.
She starts with the example code she'll be testing and then works through the steps to effectively test it:
- isolating it from the other functionality in the application
- mocking a statically called method
- requiring necessary files
- executing the controller under test
The post ends with the test class she created showing how to evaluate the result of a call with one invoice in the billing system. She makes one comment at the end to answer the question "why not just refactor" but points out that, especially in larger legacy applications, that's just not always an option.