language: php
dist: trusty
sudo: false

php:
  - '5.6'
  - '7.0'
  - '7.1'
  - '7.2'
  - '7.3'
  - nightly

env:
  - CHECK=phpunit

matrix:
  include:
    - env: CHECK=phpcs
      php: '7.3'
    - env: CHECK=phpcs
      php: '7.0'
    - env: CHECK=phpcs
      php: '5.6'
    - env: CHECK=syntax
      php: 'nightly'
    - env: CHECK=syntax
      php: '7.3'
    - env: CHECK=syntax
      php: '7.0'
    - env: CHECK=syntax
      php: '5.6'
  allow_failures:
    - php: nightly

services:
  - mysql
  - postgresql

cache:
  directories:
    - vendor

branches:
  only:
  - master
  - /^v\d/

notifications:
  email: false

# also see: test/setup_vendor.sh
before_script:
  - php -m
  - '[ -z $LOCALE_GEN ] || sudo locale-gen en_US.UTF-8 de_DE.UTF-8 fr_FR.UTF-8'
  - '[ -z $ENABLE_LDAP ] || phpenv config-add test/travis-ldap.ini'
  - test/setup_vendor.sh
  - 'if [ "$CHECK" = phpunit ]; then test/travis_database.sh; fi'

script:
  # also see: modules/test/application/clicommands/PhpCommand.php
  - 'if [ "$CHECK" = phpcs ]; then php vendor/phpcs.phar; fi'
  - 'if [ "$CHECK" = phpunit ]; then php vendor/phpunit.phar -c modules/test/phpunit.xml --verbose; fi'
  - 'if [ "$CHECK" = syntax ]; then php test/check-syntax.php -e "^(\./)?vendor/" -e Icinga/Util/String.php; fi'
