name: Test

on:
  push:
    branches:
      - master
  pull_request:
    branches:
      - master

jobs:
  run:
    runs-on: ${{ matrix.os }}
    continue-on-error: ${{ matrix.experimental }}
    strategy:
      max-parallel: 1
      matrix:
        os: [ubuntu-latest]
        php: [8.1, 8.2, 8.3, 8.4, 8.5]
        experimental: [false]

    name: Testing PHP ${{ matrix.php }} on ${{ matrix.os }}
    steps:
      - name: Checkout
        uses: actions/checkout@v4

      - name: Setup PHP
        uses: shivammathur/setup-php@v2
        with:
          php-version: ${{ matrix.php }}
          coverage: xdebug

      - name: Get composer cache directory
        id: composer-cache
        run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT

      - name: Cache composer dependencies
        uses: actions/cache@v3
        with:
          path: ${{ steps.composer-cache.outputs.dir }}
          key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}
          restore-keys: ${{ runner.os }}-composer

      - name: Install Composer dependencies
        run: composer install --no-progress --no-suggest --prefer-dist --optimize-autoloader
        continue-on-error: ${{ matrix.experimental }}

      - name: Run PHPUnit tests
        run: vendor/bin/phpunit
        continue-on-error: ${{ matrix.experimental }}
