name: run-tests
on:
    push:
    workflow_dispatch:
    pull_request:

jobs:
    test:
        runs-on: ubuntu-latest
        strategy:
            fail-fast: false
            matrix:
                php: ['7.3', '7.4', '8.0', '8.1', '8.2', '8.3']
                stability: [prefer-lowest, prefer-stable]
        name: P${{ matrix.php }} - ${{ matrix.stability }}
        steps:
            - name: Checkout code
              uses: actions/checkout@v4

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

            - name: Setup problem matchers
              run: |
                  echo "::add-matcher::${{ runner.tool_cache }}/php.json"
                  echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"

            - name: Install dependencies
              run: composer update --${{ matrix.stability }} --prefer-dist --no-interaction

            - name: Execute tests
              run: vendor/bin/phpunit --coverage-text --coverage-clover=coverage.clover
