name: CI

on:
  push:
    branches: [ master ]
  pull_request:
    branches: [ master ]

jobs:
  phpunit:
    name: Tests
    strategy:
      fail-fast: false
      matrix:
        os: [ubuntu-latest]
        php:
          - "7.1"
          - "7.2"
          - "7.3"
          - "7.4"
          - "8.0"
          - "8.1"
        dependencies:
          - "lowest"
          - "highest"
        symfony-yaml: ['^3.4', '^4', '^5', '^6']
        include:
          - os: "windows-latest"
            php: "8.0"
            dependencies: "highest"
            symfony-yaml: '5.4.2'
          - os: "macos-latest"
            php: "8.0"
            dependencies: "highest"
            symfony-yaml: '^5'
        exclude:
          # symfony/yaml v5 does not run on PHP 7.1
          - php: '7.1'
            symfony-yaml: '^5'
          # symfony/yaml v6 does not run on PHP 7.*
          - php: '7.1'
            symfony-yaml: '^6'
          - php: '7.2'
            symfony-yaml: '^6'
          - php: '7.3'
            symfony-yaml: '^6'
          - php: '7.4'
            symfony-yaml: '^6'
          # symfony/yaml v3.4 is not compatible with PHP 8.0 but has no upper-bound, so it installs on it
          - php: '8.0'
            symfony-yaml: '^3.4'
          - php: '8.1'
            symfony-yaml: '^3.4'

    runs-on: ${{ matrix.os }}

    steps:
      - uses: actions/checkout@v2

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

      - name: Require specific symfony/yaml version
        run: "composer require symfony/yaml:'${{ matrix.symfony-yaml }}' --no-interaction --ansi --no-install"

      - name: Require newer phpunit/phpunit version
        run: "composer require phpunit/phpunit '^9.5' --dev --no-interaction --ansi --no-install"
        if: matrix.php == '8.1'

      - name: "Install dependencies with Composer"
        uses: "ramsey/composer-install@v2"
        with:
          dependency-versions: "${{ matrix.dependencies }}"

      - name: Validate test data
        run: make lint

      - name: PHPUnit tests
        run: make test

      - name: Code coverage
        run: make coverage
