Published on

Review: Test-Driven Development with PHP 8 by Rainier Sarabia

Authors
  • avatar
    Name
    Adam Parrish
    Twitter

Disclaimer

Packt publishing provided me an early review copy of 'Test-Driven Development with PHP 8' free of charge and Rainier Sarabia is a former colleague of mine.

Summary

'Test-Driven Development with PHP 8' by Rainier Sarabia (2023) is a technical book focusing on "Build(ing) extensible, reliable, and maintainable enterprise-level applications using TDD and BDD with PHP".

It's a fantastic introduction for a junior developer or student wanting to bridge the gap between theory to implementing their first major project, or a mid level developer (potentially from a faster paced digital agency background or smaller business with legacy code) who hasn't been exposed to best practices in PHP8, test driven development, or how maintainable code is written in a mature software engineering environment and who wants to skill up.

If you are a PHP developer starting out and have ever wondered what POPO, ORM, SOLID or PSR means, what XDebug is used for, what the heck Red-Green-Refactor refers to, or the difference between an integration and a unit test, this book is for you.

Rain uses clear conceptual frameworks and analogies to help simplify complex topics for the layman, and I wish I had this earlier in my career when I was trying to get my head around TDD. One of my favourite parts of this book is how Rain uses JIRA and the concept of a Toy Car Museum application to build a real world project. Having run software development teams for over decade, this is a step many technical books never address, and its addition will be invaluable for those starting out wondering what all this would look like in practice.

If you are senior developer with significant test driven development, behavioural driven development and domain driven development experience, this book probably isn't for you as it covers a significant amount of foundational concepts, but you will still find value in part 2 and 3 if you haven't had exposure to some of the advanced topics like BDD, CI/CD, instrumentation or how to apply SOLID principles in a TDD context.

Rain, well done mate!

How to buy?

'Test-Driven Development with PHP 8' by Rainier Sarabia (2023) can be bought via Amazon. Use my affiliate link if you found the review helpful: https://amzn.to/3CuTl9Y

TDD with PHP8

In Depth Review

What is it about?

'Test-Driven Development with PHP 8' is a three part book that uses a project based approach to teaching Test Driven Development. It uses Symfony, one of the most popular modern php frameworks, and a number of other popular modern technologies for its examples. Part 1 covers Technical Background and Setup, Part 2 discusses Implementing Test-Driven Development, and Part 3 covers how to productionise your appllication via Deployment Automation and Monitoring.

Part 1 - Technical Background and Setup

Part 1 is an introduction to modern agile software delivery, and includes topics such as the set up of a project management tool with source control integration, containers to provide a portable development environment, and an overview of modern PHP, covering PHP8 features, and PSR standards. It provides just enough information to get you up and running with Docker (a containerisation tool), Git (via Bitbucket) and JIRA (a project management tool) without overwhelming you.

If you are just starting out in development, I would recommend supplementing Part 1 with some of the documentation that also exists for these tools, as it will give you a better understanding of how they work and how to troubleshoot issues. If for example, you are developing in a Windows based environment, Windows Subsystem for Linux is a good stand in for a unix based environment.

Additional Resources for Part 1

Part 2 - Implementing Test-Driven Development in a PHP project

Part 2 is where the book becomes more applicable for mid level developers wanting to learn more about TDD, and covers concepts in depth such as assertions, test coverage, annotations, integrated testing, use of Xdebug, testing encapsulated classes and methods indirectly and so on.

It provides a clear overview of how BDD can be used to supliment TDD, and how to use the BDD fraameworks Gerkin and Behat to write tests. I hadn't heard of Mink (A headless webdriver based testing tool for browser testing that acts as a wrapper around popular drivers) before so this secion was also a great intro to a tool that looks much more pleasant than writing Selenium tests (a web driver framework popular for writing browser based tests). For anyone looking for an applicable similiar framework in other languages, check out Playwright, which has multiple language APIs (https://playwright.dev/) or Puppeteer for NodeJS (https://pptr.dev/).

Additional Resources for Part 2

Part 3 - Deployment Automation and Monitoring

Part three focuses on setting up a deployment target and the steps required for a mature and maintainable deployment pipeline. Setting up a CI/CD build pipeline in Bitbucket and deploying to an AWS cloud based environment and the intial AWS environment configuration including some common AWS tools and services are the main topics covered.

It also covers how to instrument your application to monitor performance and provide alerts using NewRelic APM (Application Performance Monitoring) and what sort of golden signals to look out for when monitoring systems. Part 3 is reasonably condensed, and as the nature of system architecture is pretty advanced this is one section I definitely recommend supplementing with technical documentation and further study.

Make sure once you are done you also delete your AWS resources if you don't want to run up a bill.

Additional Resources for Part 3

About The Author

How do I know Rain?

I worked with Rainier at Make It Mine Finance for 6 months where he worked on our PHP team as a senior developer.

He is an absolute gun developer and system architect and I have fond memories at that time of him teaching me about modern orchestration and infrastructure as code tools.

While we went through a downsizing process prior to a business sale and Rainer took the opportunity to move on to greener pastures during the process, he was a great asset to my team and I would hire him again in a heartbeat.

Rain, thanks for asking me to review your book, I have enjoyed reading your anecdotes and having an opportunity for you to share you experience with me again.

Bio from the book

Rainier Sarabia is a Software Engineering Manager, who currently works in Melbourne, Australia for Astute Payroll, a Deel company. He has worked on hundreds of complex software projects, including massive enterprise SaaS products while leading and training senior engineers from all over the world. His favorite programming languages are PHP, C#, Java, and Javascript which he uses for both professional and personal projects. He co-founded his first tech company back in 2014, with over 400,000 users. Outside of working hours, he is an amateur astronomer. He spends most of his time doing astrophotography focusing on deep-sky objects like nebulae and galaxies.