language: php

matrix:
  allow_failures:
    - php: hhvm-3.24
    - php: nightly
    - php: 8.0snapshot
  fast_finish: true
  include:
    - php: 5.5
      dist: trusty
      env: COMPOSER_OPTS=""
    - php: 5.5
      dist: trusty
      env: COMPOSER_OPTS="--prefer-lowest"
    - php: 5.6
      dist: trusty
      env: COMPOSER_OPTS=""
    - php: 5.6
      dist: trusty
      env: COMPOSER_OPTS="--prefer-lowest"
    - php: 7.0
      dist: trusty
      env: COMPOSER_OPTS=""
    - php: 7.0
      dist: trusty
      env: COMPOSER_OPTS="--prefer-lowest"
    - php: 7.1
      dist: trusty
      env: COMPOSER_OPTS=""
    - php: 7.1
      dist: trusty
      env: COMPOSER_OPTS="--prefer-lowest"
    - php: 7.2
      dist: trusty
      env: COMPOSER_OPTS=""
    - php: 7.2
      dist: trusty
      env: COMPOSER_OPTS="--prefer-lowest"
    - php: 7.3
      dist: trusty
      env: COMPOSER_OPTS=""
    - php: 7.3
      dist: trusty
      env: COMPOSER_OPTS="--prefer-lowest"
    - php: 7.4
      dist: trusty
      env: COMPOSER_OPTS=""
    - php: 7.4
      dist: trusty
      env: COMPOSER_OPTS="--prefer-lowest"
    - php: 8.0snapshot
      dist: xenial
      env: COMPOSER_OPTS=""
    - php: 8.0snapshot
      dist: xenial
      env: COMPOSER_OPTS="--prefer-lowest"
    - php: hhvm-3.24
      dist: trusty
      env: COMPOSER_OPTS=""
    - php: hhvm-3.24
      dist: trusty
      env: COMPOSER_OPTS="--prefer-lowest"
    - php: nightly
      dist: trusty
      env: COMPOSER_OPTS=""
    - php: nightly
      dist: trusty
      env: COMPOSER_OPTS="--prefer-lowest"

sudo: false

before_install:
  - echo "memory_limit=4G" >> ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/travis.ini
  - if [ -n "$GH_TOKEN" ]; then composer config github-oauth.github.com ${GH_TOKEN}; fi;

install:
  # Setup environment variables for testing
  - export AWS_ACCESS_KEY_ID=foo
  - export AWS_SECRET_ACCESS_KEY=bar
  - export AWS_CSM_ENABLED=false

  # Build job specific tweaks
  - >
    if [ $(phpenv version-name) == "5.5" ]; then
      rm ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/xdebug.ini
    fi

  - >
    if [ $(phpenv version-name) != "hhvm-3.24" ] && [ $(phpenv version-name) != "nightly" ]; then
      echo "xdebug.overload_var_dump = 0" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini
    fi

  - >
    phpunit5_versions=("7.2" "7.3" "7.4" "8.0" "8.0snapshot");
    if [[ " ${phpunit5_versions[@]} " =~ " $(phpenv version-name) " ]] && [ -z $COMPOSER_OPTS ]; then
      composer require --dev --ignore-platform-reqs phpunit/phpunit "^5.7.11"
    fi

  # Resolve dependencies
  - composer --version
  - travis_retry composer update $COMPOSER_OPTS --no-interaction --prefer-source
  - composer show guzzlehttp/guzzle

script:
  # Unit tests
  - travis_wait 60 make test

  # Static analysis
  - >
    test_versions=("7.1" "7.2" "7.3" "7.4");
    if [[ " ${test_versions[@]} " =~ " $(phpenv version-name) " ]] && [ -z $COMPOSER_OPTS ]; then
      composer require --dev nette/neon "^3.0"
      composer require --dev phpstan/phpstan "0.12.45"
      vendor/bin/phpstan analyse src
    fi

  # Package generation
  - if [ -z "$COMPOSER_OPTS" ]; then make package; fi

after_success:
  # Code coverage report
  - >
    if [ $(phpenv version-name) == "7.1" ]; then
      bash <(curl -s https://codecov.io/bash)
    fi
