name: PHP Tests

on:
    push:
    schedule:
        - cron: '0 0 * * *'

permissions:
  contents: read # to fetch code (actions/checkout)

jobs:
    test:
        runs-on: ubuntu-latest
        
        strategy:
            # if one job fails, abort the next ones too, because they'll probably fail - best to save the minutes
            fail-fast: false  # to change to: true
          
            # run all combinations of the following, to make sure they're working together
            matrix:
                # os: [ubuntu-latest, macos-latest, windows-latest]
                php: [7.3, 7.4, 8.0, 8.1, 8.2]
                dbal: [^2.5, ^3.0]
                laravel: [8.*, 9.*, 10.*]
                phpunit: [8.*, 9.*]
                dependency-version: [stable] # to add: lowest
                exclude:
                    - laravel: 9.*
                      php: 7.3
                    - laravel: 9.*
                      php: 7.4
                    - laravel: 9.*
                      phpunit: 8.*
                    - laravel: 10.*
                      php: 7.3
                    - laravel: 10.*
                      php: 7.4
                    - laravel: 10.*
                      php: 8.0
                    - laravel: 10.*
                      phpunit: 8.*
                    - laravel: 10.*
                      dbal: ^2.5
        

        name: PHP ${{ matrix.php }}, Laravel ${{ matrix.laravel }}, PHPUnit ${{ matrix.phpunit }}, DBAL ${{ matrix.dbal }} --prefer-${{ matrix.dependency-version }}
        
        steps:
            -   name: Checkout code
                uses: actions/checkout@v3

            -   name: Install SQLite 3
                run: |
                    sudo apt-get update
                    sudo apt-get install sqlite3
            -   name: Setup PHP
                uses: shivammathur/setup-php@v2
                with:
                    php-version: ${{ matrix.php }}
                    extensions: curl, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, iconv
                    coverage: none
            -   name: Cache dependencies
                uses: actions/cache@v3
                with:
                    path: ~/.composer/cache/files
                    key: dependencies-${{ matrix.dependency-version }}-laravel-${{ matrix.laravel }}-php-${{ matrix.php }}-phpunit-${{ matrix.phpunit }}-composer-${{ hashFiles('composer.json') }}
            -   name: Install dependencies
                run: |
                    composer require "laravel/framework:${{ matrix.laravel }}" "phpunit/phpunit:${{ matrix.phpunit }}" "doctrine/dbal:${{ matrix.dbal }}" --no-interaction --no-update
                    composer update --prefer-${{ matrix.dependency-version }} --prefer-dist --no-interaction
            -   name: Execute tests
                run: composer test
