Run Laravel test suite on GitHub Actions with laravel-docker
This article has been published a while ago.
If this is a technical article some information might be out of date. If something is terribly broken, let me know and I will update the article accordingly.
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.
- We specify that the workflow should run on a Linux machine by setting
runs-on: ubuntu-latest
. - We tell Actions, to run the
phpunit
-job insidelaravel-docker
Docker Image. - The steps are pretty standard, but here's the quick summary
- Clone the projects code from GitHub
- Install composer-dependencies
- Prepare the Laravel Application by creating the
.env
and setting the application key - Run your testsuite with
phpunit