Skip to content

Repository files navigation

The Test Pyramid: A Practical Guide to Building a REST API (PHP)

This repository contains all the code for The Engineering Coach YouTube series on the Test Pyramid. This comprehensive guide will walk you through building a complete REST API with a solid testing strategy.

What You'll Learn

  • How to build a complete REST API using Test-Driven Development (TDD).
  • The essential layers of the Test Pyramid in practice.
  • How to write End-to-End, Integration, and Unit Tests.
  • Techniques for handling errors and refactoring for resilience.
  • The principles of Hexagonal Architecture for professional software design.

Videos in the Series

Part 1: End-to-End Testing a REST API

We start our journey at the top of the pyramid, using end-to-end tests to design a /health endpoint and a 404 Not Found handler.

Watch the video here!

Part 1: End-to-End Testing a REST API

Part 2: E2E, Integration & Unit Tests

We continue to build our API by adding a GET /books/{isbn} endpoint, exploring how to use end-to-end, integration, and unit tests together.

Watch the video here!

Part 2: E2E, Integration & Unit Tests

Part 3: Handling Errors

A crucial episode where we learn to handle an unavailable database. We'll refactor our code and use a combination of unit and integration tests to ensure our application is resilient to failure.

Watch the video here!

Part 3: Handling Errors

Part 4: Refactoring for Resilience

This video is an essential guide for anyone who wants to learn how to write robust, fault-tolerant code.

Watch the video here!

Part 4: Refactoring for Resilience

Part 5: Hexagonal Architecture

In the final video, we step away from the code and look at the "big picture." We'll introduce Hexagonal Architecture and show you how it provides a clean, testable structure for your application.

Watch the video here!

Episode 020 End to End Testing

Getting Started

To run the code and follow along with the series, you will need PHP, Docker, and Composer.

Clone the repository:

git clone https://github.com/testingallthethings/020-end-to-end cd 020-end-to-end

Start the Docker containers (for Postgres):

docker-compose up -d

Install the dependencies:

composer install

Run the database migrations:

php migrations.php

Run the tests:

./vendor/bin/phpunit

About The Engineering Coach

The Engineering Coach is a YouTube channel dedicated to helping software engineers and engineering managers improve their skills and craft. We provide practical advice and tutorials on topics that matter in the real world of software development.

Let's Connect

For more software engineering tutorials and coaching, subscribe to The Engineering Coach on YouTube. You can also connect with me on Bluesky or Mastodon.

Releases

Packages

Used by

Contributors

Languages