name: PHPUnit

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

jobs:
  test:
    runs-on: ubuntu-latest

    services:
      mysql:
        image: mysql:8.4
        env:
          MYSQL_DATABASE: nat_as_test
          MYSQL_USER: nat_as_test
          MYSQL_PASSWORD: test-password
          MYSQL_ROOT_PASSWORD: root-password
        ports:
          - 3306:3306
        options: >-
          --health-cmd="mysqladmin ping -h 127.0.0.1 -uroot -proot-password"
          --health-interval=5s
          --health-timeout=5s
          --health-retries=20

    steps:
      - uses: actions/checkout@v4

      - name: Set up PHP
        uses: shivammathur/setup-php@v2
        with:
          php-version: '8.2'
          extensions: json, openssl, pdo, pdo_mysql, pdo_sqlite, zip
          coverage: pcov
          tools: composer:v2

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

      - name: Run tests with coverage floor
        run: php tests/check-coverage.php 40

      - name: Run MySQL schema smoke test
        env:
          QDB_MYSQL_HOST: 127.0.0.1
          QDB_MYSQL_PORT: 3306
          QDB_MYSQL_DATABASE: nat_as_test
          QDB_MYSQL_USER: nat_as_test
          QDB_MYSQL_PASSWORD: test-password
        run: php tests/mysql_smoke.php
