Skip to content

Feature Tests

Feature Tests #88

Workflow file for this run

name: Feature Tests
on:
push:
branches:
- master
pull_request:
workflow_dispatch:
jobs:
laravel-tests:
runs-on: ubuntu-latest
# --------------------------------------------------------------
# Spin up a MySQL 8.0 container for testing
# --------------------------------------------------------------
services:
mysql:
image: mysql:8.0
env:
MYSQL_ROOT_PASSWORD: password
MYSQL_DATABASE: testing
ports:
- 3306:3306
options: >-
--health-cmd="mysqladmin ping -h 127.0.0.1"
--health-interval=10s
--health-timeout=5s
--health-retries=5
# --------------------------------------------------------------
# Define every environment variable manually
# --------------------------------------------------------------
env:
# Application settings
APP_NAME: "Computer Science Resources"
APP_ENV: testing
APP_KEY: base64:7aYe15aBsSh6a2ScVwj1JfYjQKUmz9Z5X/GSe64joHA=
APP_DEBUG: 'true'
APP_TIMEZONE: UTC
APP_URL: http://localhost
# Database settings (pointing to MySQL on localhost)
DB_CONNECTION: mysql
DB_HOST: 127.0.0.1
DB_PORT: 3306
DB_DATABASE: testing
DB_USERNAME: root
DB_PASSWORD: password
steps:
- name: Checkout code
uses: actions/checkout@v4
# --------------------------------------------------------------
# Set up PHP 8.3 + required extensions + Composer
# --------------------------------------------------------------
- name: Set up PHP & Composer
uses: shivammathur/setup-php@v2
with:
php-version: 8.3
extensions: mbstring, pdo, mysql, bcmath, tokenizer
tools: composer
- name: Install Composer dependencies
run: composer install --no-interaction --prefer-dist
# --------------------------------------------------------------
# Generate a new application key (uses APP_KEY from `env:` above)
# --------------------------------------------------------------
- name: Generate app key
run: php artisan key:generate --ansi
# --------------------------------------------------------------
# Node Setup
# --------------------------------------------------------------
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: 20
- name: Install NPM dependencies
run: npm ci
- name: Build assets
run: npm run build
- name: Cache node modules
uses: actions/cache@v3
with:
path: node_modules
key: ${{ runner.os }}-node-${{ hashFiles('package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
# --------------------------------------------------------------
# Wait until MySQL is ready to accept connections
# --------------------------------------------------------------
- name: Wait for MySQL to be ready
run: |
echo "Waiting for MySQL to be ready..."
until mysqladmin ping -h 127.0.0.1 -P 3306 --silent; do
sleep 3
done
# --------------------------------------------------------------
# Run migrations (uses the `DB_` variables defined at the top)
# --------------------------------------------------------------
- name: Run database migrations
run: php artisan migrate --force
# --------------------------------------------------------------
# Run all tests (feature + unit)
# --------------------------------------------------------------
- name: Run feature & unit tests
run: php artisan test