language: php
dist: trusty

php:
  - 5.6
  - 7.1
  - 7.2
  - 7.3

env:
  - GOOGLE_CLOUD_STORAGE="1.0.*"
  - GOOGLE_CLOUD_STORAGE="1.1.*"
  - GOOGLE_CLOUD_STORAGE="1.2.*"
  - GOOGLE_CLOUD_STORAGE="1.3.*"
  - GOOGLE_CLOUD_STORAGE="1.4.*"
  - GOOGLE_CLOUD_STORAGE="1.5.*"
  - RELEASE_TAG=1 # dev-master
  - RELEASE_TAG=2 # latest-stable
  - RELEASE_TAG=3 # previous-stable

matrix:
  fast_finish: true
  allow_failures:
    - env: RELEASE_TAG=1

before_install:
  - bash -c 'if [[ "${TRAVIS_PHP_VERSION}" == "hhvm" ]]; then rm phpunit.xml; mv phpunit.hhvm.xml phpunit.xml; fi;'

install:
  - if [[ -z "$GOOGLE_CLOUD_STORAGE"  ]]; then GOOGLE_CLOUD_STORAGE=$(travis_retry composer show google/cloud-storage -a | grep versions | cut -d "," -f ${RELEASE_TAG} |  sed -e "s/^versions ://" | xargs); fi;
  - travis_retry composer require --no-interaction --no-suggest "google/cloud-storage:${GOOGLE_CLOUD_STORAGE}"
  - travis_retry composer install --no-interaction --no-suggest

script:
  - export GOOGLE_CLOUD_STORAGE=$GOOGLE_CLOUD_STORAGE
  - bin/phpunit

after_script:
  - wget https://scrutinizer-ci.com/ocular.phar
  - bash -c 'if [[ "${TRAVIS_PHP_VERSION}" != "hhvm" ]; then php ocular.phar code-coverage:upload --format=php-clover coverage.xml; fi;'
