name: Tests
on: [push]
jobs:
  run-tests:
    runs-on: ubuntu-latest
    name: PHP ${{ matrix.php }} - Laravel ${{ matrix.laravel }}
    strategy:
      fail-fast: true
      matrix:
        include:
          # PHP 7.4 supports Laravel 6 & 8
          - php: 7.4
            laravel: 6.*
            testbench: 4.*
            phpunit: 8.*
          - php: 7.4
            laravel: 8.*
            testbench: 6.*
            phpunit: 9.*

          # PHP 8.1 supports Laravel 8 & 9
          - php: 8.1
            laravel: 8.*
            testbench: 6.*
            phpunit: 9.*
          - php: 8.1
            laravel: 9.*
            testbench: 7.*
            phpunit: 9.*

          # PHP 8.3 supports Laravel 8, 9, and 12
          - php: 8.3
            laravel: 8.*
            testbench: 6.*
            phpunit: 9.*
          - php: 8.3
            laravel: 9.*
            testbench: 7.*
            phpunit: 9.*
          - php: 8.3
            laravel: 12.*
            testbench: 10.x
            phpunit: 11.*

    steps:
      - name: Check out repository code
        uses: actions/checkout@v4

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

      - name: Install dependencies
        run: |
          composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" "phpunit/phpunit:${{ matrix.phpunit }}" --no-interaction --no-update
          composer update --prefer-stable --prefer-dist --no-interaction

      - name: Cache dependencies
        uses: actions/cache@v3
        with:
          path: ~/.composer/cache/files
          key: dependencies-laravel-${{ matrix.laravel }}-php-${{ matrix.php }}-composer-${{ hashFiles('composer.json', 'composer.lock') }}
          restore-keys: |
            dependencies-laravel-${{ matrix.laravel }}-php-${{ matrix.php }}-

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