AI, Data Science & Cloud Certificates from Google, IBM & Meta
Get 20% off all career paths from fullstack to AI
Overview
Google, IBM & Meta Certificates – 40% Off
One Coursera Plus subscription covers most Professional Certificates on Coursera.
Unlock All Certificates
This talk shows how to make legacy PHP code testable and refactor it while preserving existing behavior. It covers unit testing, mocking, and ways to handle hard-coded dependencies and other difficult code patterns.
Syllabus
Intro
What is legacy code?
What is refactoring?
What is unit testing?
Why would I unit test?
A solution
A better solution
PHPUnit - installation
Anatomy of a unit test
Running the tests
Mocking - Caution!
Mockery - Installation
Mockery - Usage
A method that echoes
A static method call
Testing: hard-coded dependencies
Refactoring hard-coded dependencies
A hard-coded dependency
Refactoring Redirections
Refactoring Exiting
Refactoring: Updating a file
Fake filesystem
Testing: Spaghetti Code
Private methods
Time for a recap...
Taught by
PHP UK Conference