Testing Legacy Code - Safe Refactoring
Offered By: PHP UK Conference via YouTube
Course Description
Overview
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
Related Courses
What's New in PHP 8.1PHP UK Conference via YouTube From Betamax to VCR - Harden Your API Integration Testing
PHP UK Conference via YouTube Levelling Up Your Web Scraping Game
PHP UK Conference via YouTube Practical Advanced Static Analysis
PHP UK Conference via YouTube PHP Fibers
PHP UK Conference via YouTube