name: CI

on:
  push:
    branches:
      - master
  pull_request: ~

jobs:
  check_composer:
    name: Check composer.json
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - uses: shivammathur/setup-php@v2
        with:
          coverage: none
          php-version: '8.0'
      - run: composer validate --strict --no-check-lock

  tests:
    runs-on: ${{ matrix.operating-system }}

    strategy:
      fail-fast: false
      matrix:
        php: [ '5.5', '5.6', '7.0', '7.1', '7.2', '7.3', '7.4', '8.0', '8.1', '8.2' ]
        operating-system: [ ubuntu-latest ]
        composer_flags: [ '' ]
        include:
          - php: '5.5'
            composer_flags: '--prefer-lowest'
            operating-system: ubuntu-latest
          - php: '7.0'
            composer_flags: '--prefer-lowest'
            operating-system: ubuntu-latest
          - php: '8.1'
            operating-system: windows-latest

    steps:
      - name: Prepare git # see https://github.com/actions/checkout/issues/226#issue-606867805
        run: git config --global core.autocrlf false && git config --global core.eol lf
      - uses: actions/checkout@v2
      - uses: shivammathur/setup-php@v2
        with:
          php-version: "${{ matrix.php }}"
      - name: Install dependencies
        run: composer update --ansi --no-progress --prefer-dist --no-interaction ${{ matrix.composer_flags }}
      - name: Run tests
        run: vendor/bin/phpunit -v --colors=always --coverage-clover=coverage.clover
      - name: Upload code coverage
        continue-on-error: true
        run: wget https://scrutinizer-ci.com/ocular.phar && php ocular.phar code-coverage:upload --format=php-clover coverage.clover

