sudo: false
dist: trusty
language: php

php:
  - 5.4
  - 5.5
  - 5.6
  - 7.0
  - 7.1
  - 7.2

before_script:
  - composer self-update
  - composer update --prefer-source

  # Install suggested cache/array-adapter on supported versions of PHP
  - composer require --dev cache/array-adapter || true
  
  # Set memory limit to 2 MB
  - echo "memory_limit=2048M" >> ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/travis.ini
  
  # Disable X-debug on all but PHP 5.6
  - if [ "$TRAVIS_PHP_VERSION" != "5.6" ]; then phpenv config-rm xdebug.ini; fi
  
script:
  - vendor/bin/phpcs --standard=PSR1,PSR2 -n src

  # Run tests (all except PHP 5.6)
  - if [ "$TRAVIS_PHP_VERSION" != "5.6" ]; then php bin/runner.php --show check; fi
  - if [ "$TRAVIS_PHP_VERSION" != "5.6" ]; then vendor/bin/phpunit; fi

  # Run tests with coverage enabled (only PHP 5.6)
  - if [ "$TRAVIS_PHP_VERSION" = "5.6" ]; then php bin/runner.php --coverage --show check; fi
  - if [ "$TRAVIS_PHP_VERSION" = "5.6" ]; then vendor/bin/phpunit --coverage-clover phpunit.xml; fi

after_script:
  # Upload coverage to Coveralls.io
  - if [ "$TRAVIS_PHP_VERSION" = "5.6" ]; then travis_retry php vendor/bin/coveralls -v; fi
