Overview
Save Big on Coursera Plus. 7,000+ courses at $160 off. Limited Time Only!
Explore safe refactoring techniques for legacy PHP code in this 40-minute conference talk from PHP UK 2020. Learn how to make untestable code testable without breaking existing functionality. Dive into unit testing concepts, PHPUnit installation, and test anatomy. Discover mocking strategies using Mockery, and tackle common challenges like hard-coded dependencies, redirections, and exiting. Master techniques for refactoring spaghetti code and private methods. Gain practical insights to confidently update and maintain legacy PHP projects while ensuring code integrity and reliability.
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