name: "PHPUnit tests"

on:
  pull_request:
  push:

defaults:
  run:
    shell: bash

jobs:
  phpunit:
    name: "PHPUnit tests"

    runs-on: ${{ matrix.operating-system }}

    strategy:
      matrix:
        php-version:
          - "7.1"
          - "7.2"
          - "7.3"
          - "7.4"
          - "8.0"
          - "8.1"
          - "8.2"
          - "8.3"
          - "8.4"
        operating-system:
          - "ubuntu-latest"
      fail-fast: false

    steps:
      - name: "Checkout"
        uses: "actions/checkout@v3"

      - name: "Install PHP"
        uses: "shivammathur/setup-php@v2"
        with:
          coverage: "pcov"
          php-version: "${{ matrix.php-version }}"
          ini-values: memory_limit=-1
          tools: composer:v2, cs2pr

      - name: "Cache dependencies"
        uses: "actions/cache@v3"
        with:
          path: |
            ~/.composer/cache
            vendor
          key: "php-${{ matrix.php-version }}"
          restore-keys: "php-${{ matrix.php-version }}"

      - name: "Test with lowest dependencies"
        if: "matrix.php-version != '8.4'"
        run: |
          composer update --prefer-lowest --no-interaction --no-progress --no-suggest
          composer update symfony/phpunit-bridge --no-interaction --no-progress --no-suggest
          vendor/bin/simple-phpunit

      - name: "Test with highest dependencies"
        run: |
          composer update --no-interaction --no-progress --no-suggest $([[ "${{ matrix.php-version }}" = "8.4" ]] && echo ' --ignore-platform-req=php+')
          vendor/bin/simple-phpunit
