Testing Legacy Code: Safe Refactoring
summary
Argues a concrete workflow: perform tiny, safe refactors to make code testable, then add tests and repeat, avoiding full rewrites; shows tools and results: PHPUnit for tests, Mockery for mocks (alias/overload for statics and hard-coded creations), and VFS stream for filesystem fakes; demonstrates patterns that become testable with defaults or injection (dependency injection), output buffering to capture echoes, wrappers for exits, separate-process runs when mocks leak, and examples where tests pass.
AI-written summary · about
chapters (24)
- 0:00Intro
- 0:47What is legacy code?
- 1:17What is refactoring?
- 2:09What is unit testing?
- 2:47Why would I unit test?
- 3:45A solution
- 3:58A better solution
- 5:00PHPUnit - installation
- 5:17Anatomy of a unit test
- 6:20Running the tests
- 7:27Mocking - Caution!
- 8:25Mockery - Installation
- 10:39A method that echoes
- 13:52A static method call
- 18:50Testing: hard-coded dependencies
- 20:28Refactoring hard-coded dependencies
- 20:58A hard-coded dependency
- 25:03Refactoring Redirections
- 27:24Refactoring Exiting
- 30:41Refactoring: Updating a file
- 32:14Fake filesystem
- 35:09Testing: Spaghetti Code
- 37:46Private methods
- 39:04Time for a recap...
related talks
41mTesting Legacy Code & Safe Refactoring
35mQuickly and Safely Refactoring Legacy Code
45mTesting Legacy Code - What To Do When It Seems Untestable
01h 01mYou Can Test Anything
52mTest, Transform, Refactor
29m6 Safe Refactoring's for Untested Legacy Code
30mRefactoring and Test Fakes: Crafting Resilient Code with Confidence
21mShaky to solid a test based approach to legacy code
