Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 45 additions & 1 deletion .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ on:
branches: [main, develop]
paths:
- 'backend/**'
- '.github/workflows/unit-tests.yml'
pull_request:
paths:
- 'backend/**'
- '.github/workflows/unit-tests.yml'

jobs:
run-tests:
Expand All @@ -17,6 +19,31 @@ jobs:
matrix:
php-versions: ['8.2', '8.3', '8.4']

services:
postgres:
image: postgres:15
env:
POSTGRES_DB: hievents_test
POSTGRES_USER: hievents
POSTGRES_PASSWORD: hievents
ports:
- 5432:5432
options: >-
--health-cmd "pg_isready -U hievents -d hievents_test"
--health-interval 10s
--health-timeout 5s
--health-retries 5

# Job-level env. .env.testing supplies the rest, but the DB host on a CI
# runner is 127.0.0.1 (service container exposes its port on the runner),
# not the docker network alias used locally — override here.
env:
DB_HOST: 127.0.0.1
DB_PORT: 5432
DB_DATABASE: hievents_test
DB_USERNAME: hievents
DB_PASSWORD: hievents

steps:
- name: Checkout code
uses: actions/checkout@v3
Expand All @@ -25,7 +52,7 @@ jobs:
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-versions }}
extensions: mbstring, xml, ctype, iconv, intl, pdo, pdo_mysql, tokenizer
extensions: mbstring, xml, ctype, iconv, intl, pdo, pdo_mysql, pdo_pgsql, pgsql, tokenizer
ini-values: post_max_size=256M, upload_max_filesize=256M
coverage: none

Expand All @@ -47,5 +74,22 @@ jobs:
- name: Install dependencies
run: cd backend && composer install --prefer-dist --no-progress --no-interaction

- name: Stage .env for testing
# Laravel auto-loads .env.testing when APP_ENV=testing, but artisan
# commands run outside that flow read .env directly. Copy .env.testing
# to .env so both paths see the same config.
run: cp backend/.env.testing backend/.env

- name: Wait for Postgres
run: |
for i in {1..30}; do
if pg_isready -h 127.0.0.1 -p 5432 -U hievents -d hievents_test; then
exit 0
fi
sleep 1
done
echo "Postgres did not become ready in time" >&2
exit 1

- name: Run PHPUnit Tests
run: cd backend && ./vendor/bin/phpunit tests/Unit --no-coverage
2 changes: 2 additions & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ cd docker/development
- **DON'T** use `RefreshDatabase` - use `DatabaseTransactions` instead
- Unit tests extend Laravel's TestCase, not PHPUnit's TestCase
- Use Mockery for mocking
- Tests run against a dedicated `hievents_test` database, configured via `backend/.env.testing` and enforced by `phpunit.xml`. The local docker-compose creates this database automatically via `docker/development/pgsql-init/`. If your existing pgsql volume predates this script, create the DB once with: `docker compose -f docker-compose.dev.yml exec pgsql psql -U username -d backend -c 'CREATE DATABASE hievents_test OWNER username;'`
- Database name **must end in `_test`**. Enforced globally by a `final` guard in `tests/TestCase.php::guardAgainstNonTestDatabase()` which runs on every test that boots Laravel — no per-test opt-in needed and no way to bypass.

### Frontend

Expand Down
43 changes: 43 additions & 0 deletions backend/.env.testing
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Auto-loaded by Laravel when APP_ENV=testing (i.e. whenever PHPUnit runs).
# Safe to commit — contains only test-only credentials and fixed test secrets.
# Real secrets must NEVER be added here.

APP_NAME=Hi.Events
APP_ENV=testing
# Static, test-only AES-256 key. Do not reuse outside tests.
APP_KEY=base64:rasMRv+Gm0oDMcBq+j9MvRgR3a6JYPTZjpRD4rGG2wA=
APP_DEBUG=true
APP_URL=http://localhost
APP_FRONTEND_URL=http://localhost
APP_LOG_QUERIES=false
APP_SAAS_MODE_ENABLED=false

LOG_CHANNEL=stderr
LOG_LEVEL=debug

# Database — must end in _test (BaseRepositoryTest enforces this).
# CI exports overrides via the workflow; locally these defaults match the
# docker-compose pgsql service.
DB_CONNECTION=pgsql
DB_HOST=pgsql
DB_PORT=5432
DB_DATABASE=hievents_test
DB_USERNAME=username
DB_PASSWORD=password

# Stateless drivers — keep tests hermetic, no external dependencies.
BROADCAST_DRIVER=log
CACHE_DRIVER=array
FILESYSTEM_PUBLIC_DISK=local
FILESYSTEM_PRIVATE_DISK=local
QUEUE_CONNECTION=sync
SESSION_DRIVER=array
SESSION_LIFETIME=120
MAIL_MAILER=array

# Fixed test JWT secret — do not reuse outside tests.
JWT_SECRET=test-jwt-secret-not-for-production-use-only-in-tests-aaaaaaaaaa
JWT_ALGO=HS256

BCRYPT_ROUNDS=4
TELESCOPE_ENABLED=false
Loading
Loading