language: php

php:
  - 5.5
  - 5.6
  - 7.0

dist: trusty

env:
  matrix:
    - DB=mysql db_dsn='mysql://root@0.0.0.0/cakephp_test'
    - DB=pgsql db_dsn='postgres://postgres@127.0.0.1/cakephp_test'
    - DB=sqlite db_dsn='sqlite:///:memory:'
  global:
    - DEFAULT=1
    - MINIMUMS=0

matrix:
  fast_finish: true

  include:
    - php: 7.0
      env: MINIMUMS=1 DEFAULT=1 DB=mysql db_dsn='mysql://travis@0.0.0.0/cakephp_test'

    - php: 7.0
      env: PHPCS=1 DEFAULT=0

before_install:
  - phpenv config-rm xdebug.ini

  - if [ -n "$GH_TOKEN" ]; then composer config github-oauth.github.com ${GH_TOKEN}; fi;

  - if [ $DB = 'mysql' ]; then sudo apt-get -y install mysql-server; fi
  - if [ $DB = 'mysql' ]; then mysql -u root -e 'CREATE DATABASE cakephp_test;'; fi

  - if [ $DB = 'pgsql' ]; then psql -c 'CREATE DATABASE cakephp_test;' -U postgres; fi

  - phpenv rehash
  - set +H

before_script:
  - sh -c "if [ '$MINIMUMS' = '0' ]; then composer update --prefer-dist --no-interaction; fi"
  - sh -c "if [ '$MINIMUMS' = '1' ]; then composer update --prefer-dist --no-interaction --prefer-lowest; fi"

script:
  - if [[ $DEFAULT = 1 && $TRAVIS_PHP_VERSION = 7.* ]]; then export CODECOVERAGE=1 ; phpdbg -qrr vendor/bin/phpunit --coverage-clover=clover.xml; fi
  - if [[ $DEFAULT = 1 && $TRAVIS_PHP_VERSION != 7.* ]]; then vendor/bin/phpunit; fi

  - if [ $PHPCS = 1 ]; then vendor/bin/phpcs -p --extensions=php --standard=vendor/cakephp/cakephp-codesniffer/CakePHP ./src ./tests; fi

after_success:
  - if [[ $DEFAULT = 1 && $TRAVIS_PHP_VERSION = 7.* ]]; then bash <(curl -s https://codecov.io/bash); fi

notifications:
  email: false
