name: Tests

on:
  push:
    branches:
      - 2.x
  pull_request:

jobs:
  test:
    runs-on: ${{ matrix.os }}
    strategy:
      fail-fast: false
      matrix:
        os: [ubuntu-latest]
        php: [8.1, 8.0, 7.4, 7.3, 7.2, 7.1]
        laravel: [9.*, 8.*, 7.*, 6.*, 5.8.*]
        dbal: [^2.12, ^3.0]
        include:
          - laravel: 9.*
            testbench: 7.*
          - laravel: 8.*
            testbench: 6.*
          - laravel: 7.*
            testbench: 5.*
          - laravel: 6.*
            testbench: 4.*
          - laravel: 5.8.*
            testbench: 3.8.*
        exclude:
          - laravel: 9.*
            php: 7.4
          - laravel: 9.*
            php: 7.3
          - laravel: 9.*
            php: 7.2
          - laravel: 9.*
            php: 7.1
          - laravel: 8.*
            php: 8.1
          - laravel: 8.*
            php: 7.2
          - laravel : 8.*
            php : 7.1
          - laravel: 7.*
            php: 8.1
          - laravel: 7.*
            php: 8.0
          - laravel : 7.*
            php : 7.1
          - laravel: 6.*
            php: 8.1
          - laravel: 6.*
            php: 8.0
          - laravel : 6.*
            php : 7.1
          - laravel: 5.8.*
            php: 8.1
          - laravel: 5.8.*
            php: 8.0
          - dbal: ^3.0
            laravel: 5.8.*
          - dbal: ^3.0
            laravel: 6.*
          - dbal: ^3.0
            laravel: 7.*
          - dbal: ^2.12
            laravel: 8.*
          - dbal: ^2.12
            laravel: 9.*


    name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.os }}

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

      - name: Setup PHP
        uses: shivammathur/setup-php@v2
        with:
          php-version: ${{ matrix.php }}
          extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick, fileinfo
          coverage: none
        env:
          COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }}

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

      - name: Get Composer Cache Directory
        id: composer-cache
        run: |
          echo "::set-output name=dir::$(composer config cache-files-dir)"
      - uses: actions/cache@v2
        with:
          path: ${{ steps.composer-cache.outputs.dir }}
          key: ${{ matrix.os }}-${{ matrix.laravel }}-${{ matrix.php }}-composer-${{ hashFiles('**/composer.lock') }}
          restore-keys: |
            ${{ matrix.os }}-${{ matrix.laravel }}-${{ matrix.php }}-composer-

      - name: Install dependencies
        run: |
          composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" "doctrine/dbal:${{ matrix.dbal }}" --no-interaction --no-update -vvv
          composer install --prefer-dist --no-interaction -vvv

      - name: Execute tests
        run: vendor/bin/phpunit
