This is my github workflow for setting up testing with Laravel using a MYSQL database. The more details can be found in the following article.
Last active
April 30, 2024 10:52
-
-
Save garethredfern/e348f54621e01791e3a1eceb65d6792e to your computer and use it in GitHub Desktop.
Github workflow for Laravel CI testing using a MYSQL database.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
APP_ENV=ci | |
APP_KEY= | |
SESSION_DRIVER=array | |
CACHE_DRIVER=array | |
QUEUE_DRIVER=sync | |
MAIL_DRIVER=log |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Laravel CI | |
on: | |
push: | |
branches: [ master ] | |
pull_request: | |
branches: [ master ] | |
jobs: | |
laravel-tests: | |
runs-on: ubuntu-latest | |
services: | |
mysql: | |
image: mysql:5.7 | |
env: | |
MYSQL_DATABASE: test_db | |
MYSQL_USER: user | |
MYSQL_PASSWORD: secret | |
MYSQL_ROOT_PASSWORD: secretroot | |
ports: | |
- 3306 | |
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3 | |
steps: | |
- uses: actions/checkout@v2 | |
- name: Verify MySQL connection | |
run: | | |
mysql --version | |
sudo apt-get install -y mysql-client | |
mysql --host 127.0.0.1 --port ${{ job.services.mysql.ports['3306'] }} -uuser -psecret -e "SHOW DATABASES" | |
- name: Copy .env | |
run: php -r "file_exists('.env') || copy('.env.github', '.env');" | |
- name: Install Dependencies | |
run: composer install -q --no-ansi --no-interaction --no-scripts --no-suggest --no-progress --prefer-dist | |
- name: Generate key | |
run: php artisan key:generate | |
- name: Directory Permissions | |
run: chmod -R 777 storage bootstrap/cache | |
- name: Execute tests (Unit and Feature tests) via PHPUnit | |
env: | |
MYSQL_DATABASE: test_db | |
DB_USERNAME: user | |
DB_PASSWORD: secret | |
DB_PORT: ${{ job.services.mysql.ports[3306] }} | |
run: vendor/bin/phpunit |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Is the key on line 49,
DB_DATABASE
instead ?