Skip to content

Instantly share code, notes, and snippets.

@rubenvanassche
Last active March 3, 2024 11:12
Show Gist options
  • Star 25 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save rubenvanassche/4fa2a9ab58454e77ba8a457941ffc0c5 to your computer and use it in GitHub Desktop.
Save rubenvanassche/4fa2a9ab58454e77ba8a457941ffc0c5 to your computer and use it in GitHub Desktop.
A simple Laravel testing workflow for GitHub Actions
name: Tests (PHP)
on: [push]
jobs:
tests:
name: Run tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: Cache composer dependencies
uses: actions/cache@v1
with:
path: vendor
key: composer-${{ hashFiles('composer.lock') }}
- name: Run composer install
run: composer install -n --prefer-dist
env:
APP_ENV: testing
- name: Prepare Laravel Application
run: |
cp .env.example .env
php artisan key:generate
- name: Cache yarn dependencies
uses: actions/cache@v1
with:
path: node_modules
key: yarn-${{ hashFiles('yarn.lock') }}
- name: Run yarn
run: yarn && yarn dev
- name: Run tests
run: ./vendor/bin/phpunit
env:
APP_ENV: testing
- name: Upload artifacts
uses: actions/upload-artifact@master
if: failure()
with:
name: Logs
path: ./storage/logs
@rubenvanassche
Copy link
Author

What happens if you change yarn && yarn dev to yarn install && yarn dev, does it still crash?

@ziming
Copy link

ziming commented Jan 17, 2020

Your yarn cache step is before (yarn && yarn dev) in your .yml file.

So changing it to yarn install && yarn dev didn't make a difference

Putting yarn && yarn dev step before the yarn cache step does make it work.

@ossycodes
Copy link

ossycodes commented Dec 11, 2020

@rubenvanassche Thanks for this. what if I want to import a sql dump file into the just created db before running the tests.

In a scenerio where by my migrations (are not complete) eg I first need to import an already exported sql database first, before running the migrations.

How do I go about this ?

@rubenvanassche
Copy link
Author

Hi @ossycodes,

I would create another step before the launching of the Laravel application where you import the sql file into the database: https://stackoverflow.com/questions/17666249/how-do-i-import-an-sql-file-using-the-command-line-in-mysql

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment