Writing Testable Php
Testable PHP is PHP where dependencies are injectable, side effects are isolated, and pure logic is separated from I/O. A function that reads a file, transforms the data, and writes a result is testing three concerns at once. A function that only transforms data is testable without any filesystem setup.
The biggest obstacle to testability is new inside methods — constructing dependencies rather than receiving them. Dependency injection (passing dependencies in) allows tests to substitute fakes or stubs. Static methods and global state ($_SESSION, $_GET) are harder to isolate; wrapping them in injectable classes or functions solves this.