on:
  push:
  pull_request:
  schedule:
  - cron: '0 0 * * *'

jobs:
  php-tests:
    runs-on: ubuntu-latest

    strategy:
      matrix:
        php: [7.4, 7.3, 7.2]
        laravel: [7.*]
        testbench: [5.*]
        dependency-version: [prefer-lowest, prefer-stable]
        include:
          - laravel: 7.*
            testbench: 5.*
            php: 7.4
            dependency-version: prefer-stable
          - laravel: 6.*
            testbench: 4.*
            php: 7.3
            dependency-version: prefer-stable
          - laravel: 5.8.*
            testbench: 3.8.*
            php: 7.3
            dependency-version: prefer-stable
          - laravel: 5.7.*
            testbench: 3.7.*
            php: 7.2
            dependency-version: prefer-stable
          - laravel: 5.6.*
            testbench: 3.6.*
            php: 7.1
            dependency-version: prefer-stable
        exclude:
          - laravel: 5.7.*
            php: 7.4
          - laravel: 5.6.*
            php: 7.4
          - laravel: 5.5.*
            php: 7.4

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

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

    - 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

    - name: Install dependencies
      run: |
        composer remove phpro/grumphp --no-interaction --no-update --dev
        composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" "orchestra/testbench-dusk:${{ matrix.testbench }}" --no-interaction --no-update
        composer update --${{ matrix.dependency-version }} --prefer-dist --no-interaction --no-suggest

    - name: Update Dusk Chromedriver
      run: vendor/bin/dusk-updater detect --auto-update

    - name: Execute Unit Tests
      run: vendor/bin/phpunit

    - name: Upload Failed Screenshots
      uses: actions/upload-artifact@v2-preview
      if: failure()
      with:
        name: screenshots
        path: tests/Browser/screenshots/*

    - name: Check PSR-12 Codestyle
      run: vendor/bin/phpcs --standard=psr12 src/
