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: ubuntu-latest

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

    steps:
      - 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

