name: Tests

on:
  push:
    paths:
      - '.github/workflows/run-tests.yml'
      - 'composer.json'
      - 'phpunit.xml'
      - 'src/**'
      - 'tests/**'
  pull_request:
    paths:
      - '.github/workflows/run-tests.yml'
      - 'composer.json'
      - 'phpunit.xml'
      - 'src/**'
      - 'tests/**'
  schedule:
    - cron: '0 0 * * *'

jobs:
  php-tests:
    runs-on: ubuntu-22.04
    timeout-minutes: 15
    env:
      COMPOSER_NO_INTERACTION: 1

    strategy:
      fail-fast: false
      matrix:
        php: [
          8.4,
          8.3,
          8.2,
          8.1,
          8.0,
          7.4,
          7.3,
          7.2,
        ]
        laravel: [
          ^12,
          ^11,
          ^10,
          ^9,
          ^8,
          ^7,
          ^6,
          ^5.4.36,
        ]
        exclude:
          - php: 8.4
            laravel: ^7
          - php: 8.4
            laravel: ^6
          - php: 8.4
            laravel: ^5.4.36
          - php: 8.3
            laravel: ^7
          - php: 8.3
            laravel: ^6
          - php: 8.3
            laravel: ^5.4.36
          - php: 8.2
            laravel: ^7
          - php: 8.2
            laravel: ^6
          - php: 8.2
            laravel: ^5.4.36
          - php: 8.1
            laravel: ^12
          - php: 8.1
            laravel: ^11
          - php: 8.1
            laravel: ^7
          - php: 8.1
            laravel: ^6
          - php: 8.1
            laravel: ^5.4.36
          - php: 8.0
            laravel: ^12
          - php: 8.0
            laravel: ^11
          - php: 8.0
            laravel: ^10
          - php: 8.0
            laravel: ^5.4.36
          - php: 7.4
            laravel: ^12
          - php: 7.4
            laravel: ^11
          - php: 7.4
            laravel: ^10
          - php: 7.4
            laravel: ^9
          - php: 7.3
            laravel: ^12
          - php: 7.3
            laravel: ^11
          - php: 7.3
            laravel: ^10
          - php: 7.3
            laravel: ^9
          - php: 7.2
            laravel: ^12
          - php: 7.2
            laravel: ^11
          - php: 7.2
            laravel: ^10
          - php: 7.2
            laravel: ^9
          - php: 7.2
            laravel: ^8

    name: P${{ matrix.php }} L${{ matrix.laravel }}

    steps:
      - name: Checkout code
        uses: actions/checkout@v4

      - name: Setup PHP
        uses: shivammathur/setup-php@v2
        with:
          php-version: ${{ matrix.php }}
          coverage: none
          extensions: pdo_sqlite, fileinfo

      - run: composer require laravel/framework:${{ matrix.laravel }} --no-update

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

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

      - name: Install dependencies
        run: composer update --prefer-dist --no-plugins

      - name: phpunit
        run: vendor/bin/phpunit
