name: "CI"

on:
  pull_request:
  push:
    branches:
      - "master"

env:
  fail-fast: true

jobs:
  phpunit:
    name: "PHPUnit (PHP ${{ matrix.php }})"
    runs-on: "ubuntu-20.04"

    strategy:
      matrix:
        php:
          - "7.2"
          - "7.3"
          - "7.4"
          - "8.0"

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

      - name: "Install PHP"
        uses: "shivammathur/setup-php@v2"
        with:
          php-version: "${{ matrix.php }}"
          coverage: "none"
          tools: composer:v1
        env:
          COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }}

      - name: "Install dependencies with Composer"
        uses: "ramsey/composer-install@v1"

      - name: "Install dev tools"
        run: "make install-dev-tools"

      - name: "Run PHPUnit"
        run: "make run-phpunit"

  phpunit-lower-php:
    name: "PHPUnit (PHP ${{ matrix.php }})"
    runs-on: "ubuntu-20.04"

    strategy:
      matrix:
        php:
          - "7.1"

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

      - name: "Install PHP"
        uses: "shivammathur/setup-php@v2"
        with:
          php-version: "${{ matrix.php }}"
          coverage: "none"
          tools: composer:v1
        env:
          COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }}

      - name: "Install dependencies with Composer"
        uses: "ramsey/composer-install@v1"

      - name: "Install dev tools"
        run: "make install-dev-tools"

      - name: "Run PHPUnit"
        run: "make run-phpunit"

  phpunit-coverage:
    name: "PHPUnit coverage (PHP ${{ matrix.php }})"
    runs-on: "ubuntu-20.04"

    strategy:
      matrix:
        php:
          - "7.4"

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

      - name: "Install PHP with PCOV"
        uses: "shivammathur/setup-php@v2"
        with:
          php-version: "${{ matrix.php }}"
          coverage: "xdebug"
          tools: composer:v1
        env:
          COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }}

      - name: "Install dependencies with Composer"
        uses: "ramsey/composer-install@v1"

      - name: "Install dev tools"
        run: "make install-dev-tools"

      - name: "Run PHPUnit"
        run: make run-phpunit ARGS="-v --coverage-clover coverage/clover.xml"

  phpunit-composerv2:
    name: "PHPUnit Composer v2 (PHP ${{ matrix.php }})"
    runs-on: "ubuntu-20.04"

    strategy:
      matrix:
        php:
          - "7.4"

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

      - name: "Install PHP"
        uses: "shivammathur/setup-php@v2"
        with:
          php-version: "${{ matrix.php }}"
          coverage: "none"
          tools: composer:v2
        env:
          COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }}

      - name: "Install dependencies with Composer"
        uses: "ramsey/composer-install@v1"

      - name: "Install dev tools"
        run: "make install-dev-tools"

      - name: "Run PHPUnit"
        run: "make run-phpunit"

  alt-autoload:
    name: "Tests alternative autoloader (PHP ${{ matrix.php }})"
    runs-on: "ubuntu-20.04"

    strategy:
      matrix:
        php:
          - "7.1"
          - "7.2"
          - "7.3"
          - "7.4"
          - "8.0"

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

      - name: "Install PHP"
        uses: "shivammathur/setup-php@v2"
        with:
          php-version: "${{ matrix.php }}"
          coverage: "none"

      - name: "Test alt-autoload"
        run: "php tests/AltAutoloadTest.php"

  phpunit-lowest:
    name: "PHPUnit lowest deps (PHP ${{ matrix.php }})"
    runs-on: "ubuntu-20.04"

    strategy:
      matrix:
        php:
          - "7.3"

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

      - name: "Install PHP"
        uses: "shivammathur/setup-php@v2"
        with:
          php-version: "${{ matrix.php }}"
          coverage: "none"
          tools: composer:v1
        env:
          COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }}

      - name: "Install dependencies with Composer"
        uses: "ramsey/composer-install@v1"
        with:
          dependency-versions: "lowest"

      - name: "Install dev tools"
        run: "make install-dev-tools"

      - name: "Run PHPUnit"
        run: "make run-phpunit"
