name: CI

on:
    push:
    pull_request:

jobs:
    php-cs-fixer:
        runs-on: ubuntu-latest
        name: Coding Standards
        steps:
            - name: Checkout
              uses: actions/checkout@v4

            - name: Setup PHP
              uses: shivammathur/setup-php@v2
              with:
                  php-version: '8.3'
                  tools: php-cs-fixer, cs2pr

            - name: PHP Coding Standards Fixer
              run: php-cs-fixer fix --dry-run --format checkstyle | cs2pr

    phpstan:
        runs-on: ubuntu-latest
        name: Static Analysis
        steps:
            -   name: Checkout
                uses: actions/checkout@v4

            - name: Setup PHP
              uses: shivammathur/setup-php@v2
              with:
                  php-version: '8.3'
                  tools: phpstan,flex
                  extensions: zip

            - name: Get composer cache directory
              id: composercache
              run: echo "::set-output name=dir::$(composer config cache-files-dir)"

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

            - name: Install dependencies
              run: composer install --prefer-dist
              env:
                SYMFONY_REQUIRE: 7.0.*

            - name: Install PHPUnit dependencies
              run: vendor/bin/simple-phpunit --version

            - name: PHPStan
              run: phpstan analyse --no-progress

    phpunit:
        runs-on: ubuntu-latest
        strategy:
            matrix:
                php-versions: ['8.0', '8.1', '8.2', '8.3']
            fail-fast: false
        name: PHP ${{ matrix.php-versions }} Test on ubuntu-latest
        steps:
            - name: Checkout
              uses: actions/checkout@v4

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

            - name: Get composer cache directory
              id: composercache
              run: echo "::set-output name=dir::$(composer config cache-files-dir)"

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

            - name: Install dependencies
              run: composer install --prefer-dist

            - name: Run tests
              run: vendor/bin/simple-phpunit

    phpunit-dev:
        runs-on: ubuntu-latest
        strategy:
            matrix:
                php-versions: ['8.0', '8.1', '8.2', '8.3']
            fail-fast: false
        name: PHP ${{ matrix.php-versions }} Test dev dependencies on ubuntu-latest
        steps:
            - name: Checkout
              uses: actions/checkout@v4

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

            - name: Get composer cache directory
              id: composercache
              run: echo "::set-output name=dir::$(composer config cache-files-dir)"

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

            - name: Allow dev dependencies
              run: composer config minimum-stability dev

            - name: Install dependencies
              run: composer install --prefer-dist

            - name: Run tests
              run: vendor/bin/simple-phpunit

    phpunit-lowest:
        runs-on: ubuntu-latest
        name: PHP 8.3 (lowest) Test on ubuntu-latest
        steps:
            - name: Checkout
              uses: actions/checkout@v4

            - name: Setup PHP
              uses: shivammathur/setup-php@v2
              with:
                  php-version: '8.3'
                  extensions: zip

            - name: Get composer cache directory
              id: composercache
              run: echo "::set-output name=dir::$(composer config cache-files-dir)"

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

            - name: Install dependencies
              run: composer update --prefer-dist --prefer-lowest

            - name: Run tests
              env:
                  SYMFONY_DEPRECATIONS_HELPER: max[total]=9223372036854775807 # PHP_INT_MAX
              run: vendor/bin/simple-phpunit

    phpunit-windows:
        runs-on: windows-latest
        name: PHP 8.3 Test on windows-latest
        env:
            PANTHER_FIREFOX_BINARY: 'C:\Program Files\Mozilla Firefox\firefox.exe'
            SKIP_FIREFOX: 1
        steps:
            - name: Checkout
              uses: actions/checkout@v4

            - name: Setup PHP
              uses: shivammathur/setup-php@v2
              with:
                  php-version: '8.3'
                  extensions: zip

            - name: Get composer cache directory
              id: composercache
              run: echo "::set-output name=dir::$(composer config cache-files-dir)"

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

            - name: Install dependencies
              run: composer install --prefer-dist

            - name: Run tests
              run: vendor/bin/simple-phpunit

    phpunit-macos:
        runs-on: macos-latest
        name: PHP 8.3 Test on macos-latest
        steps:
            - name: Checkout
              uses: actions/checkout@v4

            - name: Setup PHP
              uses: shivammathur/setup-php@v2
              with:
                  php-version: '8.3'
                  extensions: zip

            - name: Get composer cache directory
              id: composercache
              run: echo "::set-output name=dir::$(composer config cache-files-dir)"

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

            - name: Install dependencies
              run: composer install --prefer-dist

            - name: Run tests
              run: vendor/bin/simple-phpunit

    phpunit-10:
      runs-on: ubuntu-latest
      strategy:
        matrix:
          php-versions: [ '8.1', '8.2', '8.3' ]
        fail-fast: false
      name: PHP ${{ matrix.php-versions }} (phpunit 10) Test on ubuntu-latest
      steps:
        - name: Checkout
          uses: actions/checkout@v4

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

        - name: Get composer cache directory
          id: composercache
          run: echo "::set-output name=dir::$(composer config cache-files-dir)"

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

        - name: Install dependencies
          run: composer install --prefer-dist

        - name: Remove phpunit-bridge dependency (not yet phpunit 10 compliant)
          run: composer remove --dev symfony/phpunit-bridge

        - name: Install latest phpunit 10
          run: composer require --dev --prefer-dist phpunit/phpunit:^10.0

        - name: Run tests
          run: vendor/bin/phpunit --configuration phpunit.xml.dist.10
