name: Unit Tests

on: [push, pull_request]

env:
  SYMFONY_DEPRECATIONS_HELPER: weak

jobs:
  unit-test:
    name: Unit ( PHP ${{ matrix.php }} )
    runs-on: ubuntu-latest

    strategy:
      fail-fast: false
      matrix:
        include:
          - php: 7.2
          - php: 7.3
          - php: 7.4
          - php: 8.0

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

      - name: Setup PHP
        uses: shivammathur/setup-php@v2
        with:
          php-version: ${{ matrix.php }}
          extensions: intl, opcache, mysql, pdo_mysql, :xdebug

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

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

      - name: Install PHP 8 dependencies
        if: startsWith(matrix.php, '8')
        run: |
            composer req --dev --no-update payum/payum:dev-master
            composer rem --dev --no-update league/uri-schemes

      - name: Install dependencies
        run: composer update

      - name: Run unit tests
        run: bin/phpunit

  lowest:
    name: Unit ( PHP ${{ matrix.php }} + Lowest )
    runs-on: ubuntu-latest

    strategy:
      fail-fast: false
      matrix:
        include:
          - php: 7.2

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

      - name: Setup PHP
        uses: shivammathur/setup-php@v2
        with:
          php-version: ${{ matrix.php }}
          extensions: intl, opcache, mysql, pdo_mysql, :xdebug

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

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

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

      - name: Run unit tests
        run: bin/phpunit
