Writing and Refactoring Testable PHP
2h 22mAdvanced2024-01-24
Authors

Gary Kovar
Senior Back-End Developer and Software Engineer
Course details
It’s difficult to innovate in a messy, disorganized PHP codebase. Enter test-driven development (TDD)—a more professional development approach that helps prevent regressions, increase developer confidence in a codebase, and keep the codebase clean to accommodate business logic pivots. In this course, learn how PHP developers can leverage TDD in new projects and refactor code in existing projects.
This course is integrated with GitHub Codespaces, an instant cloud developer environment that offers all the functionality of your favorite IDE without the need for any local machine setup. With GitHub Codespaces, you can get hands-on practice from any machine, at any time—all while using a tool that you’ll likely encounter in the workplace. Check out the “Using GitHub Codespaces with this course” video to learn how to get started.
Learning objectives
Define different types of testing and when to apply each type.
Demonstrate how to configure a new PHP project for automated tests.
Explain the three-step TDD process to create and refactor safely.
Identify large chunks of code that should be refactored.
Explore how to identify and remove PHP-specific antipatterns.
Examine ways to write code with high confidence of limited or no regressions.
Describe the risks and benefits of TDD and refactoring in real-world situations.
Explain the benefits of TDD and refactoring to teams/PMs who don’t see the value.
This course is integrated with GitHub Codespaces, an instant cloud developer environment that offers all the functionality of your favorite IDE without the need for any local machine setup. With GitHub Codespaces, you can get hands-on practice from any machine, at any time—all while using a tool that you’ll likely encounter in the workplace. Check out the “Using GitHub Codespaces with this course” video to learn how to get started.
Learning objectives
Define different types of testing and when to apply each type.
Demonstrate how to configure a new PHP project for automated tests.
Explain the three-step TDD process to create and refactor safely.
Identify large chunks of code that should be refactored.
Explore how to identify and remove PHP-specific antipatterns.
Examine ways to write code with high confidence of limited or no regressions.
Describe the risks and benefits of TDD and refactoring in real-world situations.
Explain the benefits of TDD and refactoring to teams/PMs who don’t see the value.
Skills covered
Software ArchitecturePHPSoftware TestingAdvancedProgramming LanguagesOpen SourceSoftware Development
Concepts
0. Introduction
- 01 - Test-driven development and refactoring in PHP
- 02 - Concepts and technologies you should know
- 03 - Using GitHub Codespaces with this course
1. What Are You Doing Here
- 04 - Automated testing
- 05 - Define types of testing
- 06 - What is refactoring
- 07 - When to refactor
2. TDD a New Project
- 08 - Configure a project for tests
- 09 - Write an acceptance test
- 10 - Write a failing unit test, make the test pass, refactor
- 11 - Write testable code
3. What to Refactor in Existing (Legacy) Projects
- 12 - Large chunks of logic
- 13 - Incorrect OOP logic
- 14 - Change lots of files for one feature
- 15 - Unnecessary code
- 16 - Strong coupling
- 17 - Using mocks
- 18 - Files that are modified often
- 19 - Identifying the best place to start
4. Examples of Test-Driven Refactoring
- 20 - Add one passing test
- 21 - Identify a brittle function and add tests
- 22 - Extract functionality (using TDD)
- 23 - Simplify conditionals
- 24 - Simplify function signatures
5. OOP Examples of Test-Driven Refactoring
- 25 - Identify objects from related functions
- 26 - Replace arrays with objects
- 27 - Add value objects (easy to test)
- 28 - Add null objects
- 29 - Replace conditionals with interfaced classes
6. Moving Fast by Moving Slower
- 30 - Make steady progress
- 31 - Prevent regressions
- 32 - Cleaner code
- 33 - Decoupled code
- 34 - Become a better developer
7. TDD and Refactoring in the Real World
- 35 - On a spaghetti-code project
- 36 - With a looming deadline
- 37 - With a team that doesn't understand TDD and refactoring
- 38 - With a PM that doesn t understand TDD and refactoring
Conclusion
- 39 - Next steps
Related courses
- Software Testing Assistance with GitHub Copilot AI
- Visual Studio Code for Python Developers
- ASP.NET Core: Test-Driven Development
- Automate Development Tasks with OpenAI’s Codex
- Software Design: From Requirements to Release
- Java Refactoring Best Practices
- Computer Science Principles: Programming
- Learning Lombok: Streamlined Java Programming