name: CI

on:
  push:
  pull_request:

defaults:
  run:
    shell: bash

jobs:

  tests:
    name: Tests (PHP ${{ matrix.php }})
    runs-on: ubuntu-20.04
    strategy:
      matrix:
        php: [ '7.2', '7.3', '7.4', '8.0' ]
        symfony_deprecations_helper: [ '' ]
        include:
          - php: 8.1
            # Guzzle 6 triggers deprecations.
            symfony_deprecations_helper: 'max[direct]=0'
      fail-fast: false
    env:
      MATRIX_PHP: ${{ matrix.php }}

    steps:
      - name: Checkout
        uses: actions/checkout@v2
        with:
          fetch-depth: 2

      - name: Setup PHP
        uses: shivammathur/setup-php@v2
        with:
          coverage: "xdebug"
          php-version: "${{ matrix.php }}"
          tools: composer
          # PHP 7.1 development web server segfaults if timezone not set.
          ini-values: date.timezone=Europe/Paris, error_reporting=-1, display_errors=On

      - name: Install dependencies
        run: |
          composer update --no-interaction --prefer-dist

      - name: Setup Mink test server
        run: |
          mkdir ./logs
          ./vendor/bin/mink-test-server &> ./logs/mink-test-server.log &

      - name: Wait for browser & PHP to start
        run: |
          while ! nc -z localhost 8002 </dev/null; do echo Waiting for PHP server to start...; sleep 1; done

      - name: Run tests
        run: |
          export SYMFONY_DEPRECATIONS_HELPER="${{ matrix.symfony_deprecations_helper }}"
          vendor/bin/phpunit -v --coverage-clover=coverage.clover

      - name: Upload code coverage
        uses: codecov/codecov-action@v2
        with:
          files: coverage.clover
