name: Tests

on:
  pull_request:
    branches:
      - "1.0-develop"

jobs:
  tests:
    name: Tests
    runs-on: ubuntu-24.04
    permissions:
      contents: read
    strategy:
      fail-fast: false
      matrix:
        php:
          - 8.2
          - 8.3
        database:
          - mariadb:10
          - mariadb:11
          - mysql:8
          - mysql:9
    services:
      database:
        image: ${{ matrix.database }}
        env:
          MYSQL_ALLOW_EMPTY_PASSWORD: yes
          MYSQL_DATABASE: testing
        ports:
          - 3306
    steps:
      - uses: actions/checkout@v4
      - id: composer-cache
        run: |
          echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
      - uses: actions/cache@v4
        with:
          path: ${{ steps.composer-cache.outputs.dir }}
          key: ${{ runner.os }}-composer-${{ matrix.php }}-${{ hashFiles('**/composer.lock') }}
          restore-keys: |
            ${{ runner.os }}-composer-${{ matrix.php }}-
      - uses: shivammathur/setup-php@v2
        with:
          php-version: ${{ matrix.php }}
          extensions: bcmath, cli, curl, gd, mbstring, mysql, openssl, pdo, tokenizer, xml, zip
          tools: composer:v2
          coverage: none
      - run: cp .env.ci .env
      - run: composer install --no-interaction --no-progress --no-suggest --prefer-dist
      - run: vendor/bin/php-cs-fixer fix --dry-run --diff
      - run: vendor/bin/phpunit --bootstrap vendor/autoload.php tests/Unit
        env:
          DB_HOST: UNIT_NO_DB
      - run: vendor/bin/phpunit tests/Integration
        env:
          DB_PORT: ${{ job.services.database.ports[3306] }}
          DB_USERNAME: root
