name: CI

on:
  push:
    branches: [master, main]
  pull_request:

jobs:
  test:
    runs-on: ubuntu-latest
    container:
      image: php:8.4-cli

    services:
      postgres:
        image: postgres:16
        env:
          POSTGRES_USER: app
          POSTGRES_PASSWORD: app
          POSTGRES_DB: app_test
        options: >-
          --health-cmd pg_isready
          --health-interval 10s
          --health-timeout 5s
          --health-retries 5

    steps:
      - uses: actions/checkout@v4

      - name: Install system dependencies
        run: |
          apt-get update -q && apt-get install -yq git unzip libpq-dev libmagickwand-dev \
            && docker-php-ext-install pdo pdo_pgsql \
            && pecl install imagick && docker-php-ext-enable imagick

      - name: Install Composer
        run: |
          curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer

      - name: Install dependencies
        run: composer install --no-interaction --prefer-dist

      - name: Run tests
        env:
          DATABASE_URL: postgresql://app:app@postgres:5432/app_test?serverVersion=16
        run: php bin/phpunit
