~/talk

Testing Legacy Code: Safe Refactoring

Talkat PHP UK Conference 2020 · 2020-02-19..02-21· [testing]
slides:none on file

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

  1. 0:00Intro
  2. 0:47What is legacy code?
  3. 1:17What is refactoring?
  4. 2:09What is unit testing?
  5. 2:47Why would I unit test?
  6. 3:45A solution
  7. 3:58A better solution
  8. 5:00PHPUnit - installation
  9. 5:17Anatomy of a unit test
  10. 6:20Running the tests
  11. 7:27Mocking - Caution!
  12. 8:25Mockery - Installation
  13. 10:39A method that echoes
  14. 13:52A static method call
  15. 18:50Testing: hard-coded dependencies
  16. 20:28Refactoring hard-coded dependencies
  17. 20:58A hard-coded dependency
  18. 25:03Refactoring Redirections
  19. 27:24Refactoring Exiting
  20. 30:41Refactoring: Updating a file
  21. 32:14Fake filesystem
  22. 35:09Testing: Spaghetti Code
  23. 37:46Private methods
  24. 39:04Time for a recap...
~/search
type to search 6,249 conferences, 138,987 speakers and 185,172 talks
~/help
cmdctrl k
search every conference, speaker and series
/
focus the filter search
h
home
c
conferences
s
speakers
e
series
t
light / dark — the status bar button does the same
?
this help
esc
close this, then clear every filter — or just the search, while you are typing in it

Ignored while you are typing. Pages without a filter rail have no search to focus.