Run Laravel test suite on GitHub Actions with laravel-docker

• 1 min read

laravel-docker by Loris Leiva is a Docker Image which contains all the necessary services and PHP extensions to run Laravel. A perfect environment to run your Larvel test suite in!

As I'm using GitHub Actions more and more in my daily workflow (pun intended), this post is covering how you can use the Docker Image in Actions.

First create a new workflow file under .github/workflows/test.yml. Add the following code in your workflow file.

name: tests

on: push

jobs:
    phpunit:
        runs-on: ubuntu-latest

        container:
            # Need older releases? Switch out the tag (7.3) to 7.2 or 7.1
            image: lorisleiva/laravel-docker:7.3

        steps:
            - uses: actions/checkout@v1
              with:
                  fetch-depth: 1

            - name: Composer dependencies
              run: composer install --no-ansi --no-interaction --no-scripts --no-suggest --no-progress --prefer-dist

            - name: Prepare Laravel Application
              run: |
                  cp .env.example .env
                  php artisan key:generate

            - name: Run Testsuite
              run: vendor/bin/phpunit tests/

The workflow file is straightforward and easy to understand.

  1. We specify that the workflow should run on a Linux machine by setting runs-on: ubuntu-latest.
  2. We tell Actions, to run the phpunit-job inside laravel-docker Docker Image.
  3. The steps are pretty standard, but here's the quick summary
    1. Clone the projects code from GitHub
    2. Install composer-dependencies
    3. Prepare the Laravel Application by creating the .env and setting the application key
    4. Run your testsuite with phpunit