language: php

env:
  global:
    - COVERAGE=no
    - RELEASE=stable

matrix:
  include:
    - php: 7.1
    - php: 7.1
      env: RELEASE=lowest
    - php: 7.2
    - php: 7.3
      env: COVERAGE=yes

cache:
  directories:
    - $HOME/.composer/cache

before_install:
  - COMPOSER_FLAGS=$([ $RELEASE == "lowest" ] && echo "--prefer-lowest" || echo "")
  - PHPUNIT_FLAGS=$([ $COVERAGE == "yes" ] && echo "--coverage-clover=coverage.xml" || echo "")

install:
  - travis_retry composer update --no-interaction --no-suggest --prefer-dist --prefer-stable $COMPOSER_FLAGS

script:
  - vendor/bin/phpunit $PHPUNIT_FLAGS

after_script:
  - |
    if [ $COVERAGE == "yes" ]; then
      travis_retry wget https://scrutinizer-ci.com/ocular.phar
      travis_retry php ocular.phar code-coverage:upload --format=php-clover coverage.xml
    fi