Chris begins by explaining the difference between test-driven development as a design pattern and writing tests after the code is already designed. Next, he shares some reasons why legacy code can be tough to test, including poor package management practices and hard-coded dependencies. He then covers how—and what—you should be testing, how to plan out testing scenarios, and how to refactor a test suite. Upon wrapping up this course, you'll have the skills you need to test your legacy PHP code with confidence.
- What changes when testing legacy code
- Why legacy code can be difficult to test
- Identifying hard-coded dependencies in code
- Deciding what to test
- Testing legacy code
- Planning a scenario
- Building a testing scenario from scratch
- Refactoring a test suite
Skill Level Intermediate
- [Chris] Imagine this scenario. You're a PHP developer who has an old legacy code base that you need to fix bugs and add new features to. This code is old and crufty, and you are often afraid to change anything out of fear of breaking it. You also know that you should be writing tests for this application, because you've heard so many other people talk about unit testing, but have no idea where to start. Test-driven development sounds great, but you have all this existing code to worry about. Wouldn't it be great if you knew someone who could guide you through all the concepts you need to understand, and show you how to actually build these testing scenarios and then turn them into working tests? I'm that person.
My name is Chris Hartjes, and I'm here to help you learn how to write tests for legacy PHP code bases. I've been using PHP since 1998 and talking to folks about writing tests for their code since 2003. In this course, I want to teach you the fundamental concepts and skills so you can add tests to your application to give you confidence that the changes you make don't break anything, and the bugs you fix stay fixed. First, I'm going to explain how the testing tools change when you already have code that needs tests as opposed to the perfect world test-driven development imagines you are in.
Next, I'm going to talk about why legacy code bases can be so difficult to wrap tests around. Difficult people, weird bootstrapping sequences, hard-coded dependencies, challenging deployments, and poor package management can really derail your attempts to get automated tests in place. Then I lay the foundation by introducing you to the concepts that make up the backbone of your testing skillset. We'll talk about how and what you should be testing, along with explaining how test doubles work and showing how I plan out my testing scenarios using plain English.
And finally, how we can refactor our tests and the code itself to lead to better testing outcomes. I want to help you get up to speed on testing your code a lot faster than I did. There's a lot of things to cover, so sit back, relax, and let's get started.