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: ['8.1', '8.2', '8.3']
                laravel: [^10.0, ^11.0]
                dbal: [^3.0]
                phpunit: [10.*]
                dependency-version: [stable] # to add: lowest 
                exclude:
                    -   laravel: "^11.0"
                        php: "8.1"
                        dbal: "^3.0"


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

            -   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@v4
                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 }}" --no-interaction --no-update
                    composer update --prefer-${{ matrix.dependency-version }} --prefer-dist --no-interaction
            -   name: "Install dbal"
                if: ${{ matrix.laravel }} == 10
                run: composer require "doctrine/dbal:${{ matrix.dbal }}" --no-interaction --no-update
            -   name: "Update dependencies"
                run: composer update --prefer-${{ matrix.dependency-version }} --prefer-dist --no-interaction
            -   name: Execute tests
                run: composer test
