Book Image

Test-Driven Development with PHP 8

By : Rainier Sarabia
Book Image

Test-Driven Development with PHP 8

By: Rainier Sarabia

Overview of this book

PHP web developers end up building complex enterprise projects without prior experience in test-driven and behavior-driven development which results in software that’s complex and difficult to maintain. This step-by-step guide helps you manage the complexities of large-scale web applications. It takes you through the processes of working on a project, starting from understanding business requirements and translating them into actual maintainable software, to automated deployments. You’ll learn how to break down business requirements into workable and actionable lists using Jira. Using those organized lists of business requirements, you’ll understand how to implement behavior-driven development (BDD) and test-driven development (TDD) to start writing maintainable PHP code. You’ll explore how to use the automated tests to help you stop introducing regressions to an application each time you release code by using continuous integration. By the end of this book, you’ll have learned how to start a PHP project, break down the requirements, build test scenarios and automated tests, and write more testable and maintainable PHP code. By learning these processes, you’ll be able to develop more maintainable, and reliable enterprise PHP applications.
Table of Contents (17 chapters)
1
Part 1 – Technical Background and Setup
6
Part 2 – Implementing Test-Driven Development in a PHP Project
11
Part 3 – Deployment Automation and Monitoring

Types of tests

Running PHPUnit tests can be very quick. In my experience, even with tens of thousands of unit tests, it can only take a few minutes to run them completely. This is because they only test small parts or units of the solution.

We can also add tests that will call programs that will interact with external web service APIs or databases. Now, imagine how complex those tests are and how long it would take to execute them. If we combine all the complex tests that use multiple object and unit tests into a single group, it will take a lot of time to run the entire group of tests. I’ve experienced working with a company where there are thousands of tests that are all grouped into a single suite – you run the suite and wait an hour, only to find out there’s one broken unit test. That’s very time-consuming and impractical.

Figure 5.13 – Grouping tests

Figure 5.13 – Grouping tests

Identifying what a test does and putting it in the right...