How to run Docker PHP integration tests

July 24, 2019 | Last updated: July 25, 2019


How to run Docker PHP integration tests

In this guide we will show you how to run integration tests on a Docker container with a running PHP application.

Actions used in this guide:

Use case

Here we have a simple calculator application written in PHP: To calculate the value of the Fibonacci sequence, it uses a legacy app whose code is stored in the legacy directory.

In order to run Docker PHP integration tests, the legacy app must be available for the parent application. For that, we'll use a Docker container with Apache serving the legacy app. The tests will be run with PHPUnit and are defined in the tests directory.

1. PHP application in Docker

The legacy directory ( contains two files. One is index.php with the source code of the legacy app. The second one is the dockerfile required to build the Docker image:

FROM php:apache
COPY . /var/www/html

The FROM section defines the official PHP image with a preinstalled Apache server. The second line means that the index.php file will be added to the /var/www/html folder during the image building process.

If you have no experience with Docker, check out this excellent guide that will walk you through the basics.

2. Test pipeline configuration

Begin with forking the repository with the application from GitHub. Next, add a new project in Buddy and select the repo from the list:

Adding new projectAdding new project

Add a new pipeline and set the Trigger mode to automatic so that the tests will be run on every push:

Pipeline configurationPipeline configuration

The first step is building a Docker image that will be used to launch the container with our legacy app. Add the corresponding action and select the dockerfile and the context in which the image will be built:

Build Docker image configurationBuild Docker image configuration

You can define the registry to which the image will be pushed in the Options tab. This is not necessary, however, as it won't be used anywhere besides Buddy.

With the Docker build step configured, it's time to automate the tests. Select the PHP action and define the commands that will download the dependencies and trigger the tests:

Build Docker image configurationBuild Docker image configuration

Now we need to attach a custom service that will run the Docker container with the application from the previously built image:

Adding custom serviceAdding custom service

Select the image built in the previous action as the template and enter the hostname required to run the tests:

Custom service configurationCustom service configuration

3. Hostname setup

The last thing to do is to set the URL to the legacy app. To do that, paste the hostname from the custom service to the config file of your application.

You can also store the location of the legacy app as an environment variable. To do that, switch to the Variables tab and add a new variable, e.g. LEGACY_URL, with the value of the hostname:

Custom service configurationCustom service configuration


With everything properly configured, Buddy will automatically Dockerize and test your PHP application with the latest changes from the repository. You can extend the pipeline however you like – for example, by adding a notification action at the bottom that will notify your team in case the tests have failed:

Custom service configurationCustom service configuration

See also

Alexander Kus

Alexander Kus

Customer Success Manager

A story-teller and conversation-lover, Alexander decided to invest his skills to help his friends at Buddy transform the cold language of patch notes into exciting narratives. Also: an avid gamer, hip-hop DJ, Liverpool FC fan, absentminded husband, and the father of two.

With Buddy even the most complicated CI/CD workflows take minutes to create

Sign up for Buddy CI/CD

Start a free trial