Preface

For the past few years, I’ve been helping friends and colleagues learn more about PHP and Test-Driven Development (TDD). I realized that I found myself repeating some of the things I’m discussing with different people. I told myself, it would be great if I could just point my friends and colleagues to a collection of my notes so that I could help them with developing applications in PHP from the start of the project, up to deployment. Unfortunately, my notes only made sense to me.

In 2009, I was working as a C# developer and made friends with my colleagues who were fellow programming enthusiasts. Unfortunately, we haven’t been in touch for a long time. 11 years later, in 2020 while in COVID lockdown, I got in touch with my long-lost friends, and we started chatting about programming. They told me that they were very keen on learning about TDD with PHP. We then did a screen-sharing tutorial session on a weekend, and I realized that I seriously needed to start writing something a bit more organized to help other people who are interested in learning about this topic.

I do self-training most of the time. I buy books, read them, and watch tutorials about things I want to learn myself. I then decided to write a book about TDD with PHP. Since I have learned a lot from the books published by Packt, I thought I should reach out to them.

Reading this book will help you start organizing your thoughts and the things you need to build for a project as a software developer. You will learn how to write and use automated tests to help improve the quality of the software you produce, and you will also learn how to use tools to automate the execution of your tests, as well as the deployment of your code onto remote servers. I’m aiming for the reader to understand the value of TDD as a process, and not just learn about writing automated tests. That’s why I have covered topics from starting a project to deploying it on a public-facing server.

Who this book is for

If you’re a professional PHP developer who’s getting tired of working on applications that are not easily testable or maintainable, this book will help you be a better professional PHP developer. You will learn how to utilize Test-Driven Development (TDD) and Behaviour-Driven Development (BDD) to help you produce more structured and maintainable software.

What this book covers

Chapter 1, What is Test-Driven Development and Why Use it in PHP?, Goes through the definition of TDD, what problem it tries to solve, what are the benefits of PHP and what we developers will get from implementing it. This chapter will also make you understand the value of TDD in large projects and how it helps reduce regressions.

Chapter 2, Understanding and Organizing the Business Requirements of Our Project, explains how to interpret business requirements into an organized list. The list can be used to help developers prioritize and determine what features we need to build, and which features we need to build first.

Chapter 3, Setting Up Our Development Environment Using Docker Containers, is all about Docker containers for development. Using containers will help developers get more consistent application setups in different server environments.

Chapter 4, Using Object-Oriented Programming in PHP, goes through the Object-Oriented Programming (OOP) concept in PHP. Understanding OOP in PHP is crucial for implementing TDD, and BDD.

Chapter 5, Unit Testing, covers the basics of unit testing. The lessons learned in this chapter will be the foundations for the concepts that will be discussed in applying TDD and BDD in the following chapters.

Chapter 6, Applying Behavior-Driven Development, provides an introduction to the process of BDD. The BDD process will help software developers ensure that the expected behavior of a software product is achieved.

Chapter 7, Building Solution Code with BDD and TDD, demonstrates how to use BDD and TDD together. Implementing BDD and TDD together will help ensure that the expected behavior is delivered, and it will also help increase the reliability of the software being produced.

Chapter 8, Using TDD with SOLID Principles, involves following the SOLID principles in a project. This will help developers implement the SOLID principles while following TDD in a more realistic use scenario.

Chapter 9, Continuous Integration, details Continous Integration (CI) for test execution. CI is used to help merge reliable code to the master branch of a project by making sure that all automated tests pass first.

Chapter 10, Continuous Delivery, discusses using Continuous Delivery (CD) to automate the release process. Going further than CI, we will automate the deployment process of the product.

Chapter 11, Monitoring, unpacks how to use monitoring tools for deployed applications. Applications running in production will need to be maintained and having monitoring tools help developers to get on top of possible issues in production.

To get the most out of this book

The instructions in the book are Unix based. The development machine used as an example host machine in the book runs on MacOS 12.3 and should work on later versions as well. However, the Docker containers should also run on Windows and Linux machines.

Software/hardware covered in the book

Operating system requirements

Docker

macOS, Linux, or Windows

PHP 8.1

Linux

MySQL 8

Linux

PHPStorm

macOS, Linux, or Windows

If you are using the digital version of this book, we advise you to type the code yourself or access the code from the book’s GitHub repository (a link is available in the next section). Doing so will help you avoid any potential errors related to the copying and pasting of code.

Download the example code files

You can download the example code files for this book from GitHub at https://github.com/PacktPublishing/Test-Driven-Development-with-PHP-8. If there's an update to the code, it will be updated in the GitHub repository.

We also have other code bundles from our rich catalog of books and videos available at https://github.com/PacktPublishing/. Check them out!

Download the color images

We also provide a PDF file that has color images of the screenshots and diagrams used in this book. You can download it here: https://packt.link/BwjU3.

Conventions used

There are a number of text conventions used throughout this book.

Code in text: Indicates code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles. Here is an example: “The test class name needs to be suffixed with Test, and it extends the PHPUnitFrameworkTestCase class.”

A block of code is set as follows:

<?php
namespace AppValidator;
use AppModelToyCar;
use AppModelValidationModel;
interface ToyCarValidatorInterface
{
    public function validate(ToyCar $toyCar): ValidationModel;

Any command-line input or output is written as follows:

$ cd docker
$ docker-compose build && docker-compose up -d

Bold: Indicates a new term, an important word, or words that you see onscreen. For instance, words in menus or dialog boxes appear in bold. Here is an example: “Paste the script into the text area and click on the Commit File button.”

Tips or important notes

Appear like this.

Get in touch

Feedback from our readers is always welcome.

General feedback: If you have questions about any aspect of this book, email us at [email protected] and mention the book title in the subject of your message.

Errata: Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you have found a mistake in this book, we would be grateful if you would report this to us. Please visit www.packtpub.com/support/errata and fill in the form.

Piracy: If you come across any illegal copies of our works in any form on the internet, we would be grateful if you would provide us with the location address or website name. Please contact us at [email protected] with a link to the material.

If you are interested in becoming an author: If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, please visit authors.packtpub.com.

Share Your Thoughts

Once you’ve read Test-Driven Development with PHP 8, we’d love to hear your thoughts! Please click here to go straight to the Amazon review page for this book and share your feedback.

Your review is important to us and the tech community and will help us make sure we’re delivering excellent quality content.

Download a free PDF copy of this book

Thanks for purchasing this book!

Do you like to read on the go but are unable to carry your print books everywhere?

Is your eBook purchase not compatible with the device of your choice?

Don’t worry, now with every Packt book you get a DRM-free PDF version of that book at no cost.

Read anywhere, any place, on any device. Search, copy, and paste code from your favorite technical books directly into your application.

The perks don’t stop there, you can get exclusive access to discounts, newsletters, and great free content in your inbox daily

Follow these simple steps to get the benefits:

  1. Scan the QR code or visit the link below

https://packt.link/free-ebook/978-1-80323-075-7

  1. Submit your proof of purchase
  2. That’s it! We’ll send your free PDF and other benefits to your email directly
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset