name: phpunit

on: [push, pull_request]

jobs:
  test:
    runs-on: ubuntu-22.04
    strategy:
      matrix:
        php: [7.2, 7.3, 7.4, 8.0, 8.1, 8.2, 8.3, 8.4]
    steps:
      - name: Checkout code
        uses: https://code.forgejo.org/actions/checkout@v4

      - name: Cache dependencies
        uses: https://code.forgejo.org/actions/cache@v4
        with:
          path: ~/.composer/cache/files
          key: dependencies-php-${{ matrix.php }}-composer-${{ hashFiles('composer.json') }}
          restore-keys: |
            dependencies-php-${{ matrix.php }}-composer-
            dependencies-php-

      - name: Setup PHP
        uses: https://github.com/shivammathur/setup-php@v2
        with:
          php-version: ${{ matrix.php }}
          extensions: mbstring
          coverage: none

      - name: Install dependencies
        run: composer install --prefer-dist --no-interaction --no-suggest
        env:
          COMPOSER_AUTH: '{"github-oauth": {"github.com": "${{ secrets.GH_TOKEN }}"}}'

      - name: Execute tests
        run: vendor/bin/phpunit