language: php
sudo: false

php:
  - 5.6
  - 7.0
  - 7.1
  - nightly

os:
  - linux

env:
  - COMPOSER_FLAGS="--prefer-lowest"
  - COMPOSER_FLAGS=""

matrix:
  include:
    - php: 7.0
      env: COVERAGE=yes
    - php: 7.0
      env: EXECUTE_CS_CHECK=yes
    - php: 7.1
      env: COMPARE=yes
  allow_failures:
    - php: nightly

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

before_install:
  - .travis-scripts/cache-browscap.sh
  - if [[ $TRAVIS_PHP_VERSION != nightly && $COVERAGE != yes ]]; then phpenv config-rm xdebug.ini; fi
  - echo 'opcache.enable=1' >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini
  - echo 'opcache.enable_cli=1' >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini
  - travis_retry composer self-update

install:
  - travis_retry composer update --optimize-autoloader --prefer-dist --prefer-stable --no-progress --no-interaction -vv $COMPOSER_FLAGS

script:
  - if [[ $COVERAGE == yes ]]; then php -d browscap=$TRAVIS_BUILD_DIR/resources/browscap.ini vendor/bin/phpunit --exclude-group compare --coverage-text --coverage-clover=coverage.clover; fi
  - if [[ $COVERAGE != yes && $COMPARE != yes ]]; then php -d browscap=$TRAVIS_BUILD_DIR/resources/browscap.ini vendor/bin/phpunit --no-coverage --exclude-group compare; fi
  - if [[ $COMPARE == yes ]]; then php -d browscap=$TRAVIS_BUILD_DIR/resources/browscap.ini vendor/bin/phpunit --no-coverage --group compare; fi
  - if [[ $EXECUTE_CS_CHECK == yes ]]; then php -n -d memory_limit=768M vendor/bin/phpcs; fi
  - if [[ $EXECUTE_CS_CHECK == yes ]]; then php -n -d memory_limit=768M vendor/bin/php-cs-fixer fix --dry-run -vv; fi

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

