language: php
dist: xenial

cache:
    directories:
        - vendor
        - $HOME/.composer/cache

before_install:
  - phpenv config-rm xdebug.ini || true
  - pecl install pcov

before_script:
  - |
    if [[ -n "$IMAGE" ]]
    then
        bash ./tests/travis/docker-run-mysql-or-mariadb.sh
    fi

install:
  - travis_retry composer -n install --prefer-dist

script:
  - ./vendor/bin/phpunit --configuration tests/travis/$DB.travis.xml --coverage-clover clover.xml

after_success:
  - bash <(curl -s https://codecov.io/bash)

jobs:
  include:

    - stage: Smoke Testing
      php: 7.3
      env: DB=sqlite

    - stage: Test
      php: 7.3
      env: DB=mysql.docker IMAGE=mysql:5.7
    - stage: Test
      php: 7.3
      env: DB=mysql.docker IMAGE=mysql:8.0
    - stage: Test
      php: 7.3
      env: DB=mysqli.docker IMAGE=mysql:5.7
    - stage: Test
      php: 7.3
      env: DB=mysqli.docker IMAGE=mysql:8.0
    - stage: Test
      php: 7.3
      env: DB=mariadb.docker IMAGE=mariadb:10.0
    - stage: Test
      php: 7.3
      env: DB=mariadb.docker IMAGE=mariadb:10.1
    - stage: Test
      php: 7.3
      env: DB=mariadb.docker IMAGE=mariadb:10.2
    - stage: Test
      php: 7.3
      env: DB=mariadb.docker IMAGE=mariadb:10.3
    - stage: Test
      php: 7.3
      env: DB=mariadb.mysqli.docker IMAGE=mariadb:10.0
    - stage: Test
      php: 7.3
      env: DB=mariadb.mysqli.docker IMAGE=mariadb:10.1
    - stage: Test
      php: 7.3
      env: DB=mariadb.mysqli.docker IMAGE=mariadb:10.2
    - stage: Test
      php: 7.3
      env: DB=mariadb.mysqli.docker IMAGE=mariadb:10.3
    - stage: Test
      dist: trusty
      php: 7.3
      env: DB=pgsql POSTGRESQL_VERSION=9.2
      services:
        - postgresql
      addons:
        postgresql: "9.2"
    - stage: Test
      dist: trusty
      php: 7.3
      env: DB=pgsql POSTGRESQL_VERSION=9.3
      services:
        - postgresql
      addons:
        postgresql: "9.3"
    - stage: Test
      php: 7.3
      env: DB=pgsql POSTGRESQL_VERSION=9.4
      addons:
        postgresql: "9.4"
    - stage: Test
      php: 7.3
      env: DB=pgsql POSTGRESQL_VERSION=9.5
      addons:
        postgresql: "9.5"
    - stage: Test
      php: 7.3
      env: DB=pgsql POSTGRESQL_VERSION=9.6
      addons:
        postgresql: "9.6"
    - stage: Test
      php: 7.3
      env: DB=pgsql POSTGRESQL_VERSION=10.0
      sudo: required
      addons:
        postgresql: "10"
      before_script:
        - bash ./tests/travis/install-postgres-10.sh
    - stage: Test
      php: 7.3
      env: DB=pgsql POSTGRESQL_VERSION=11.0
      sudo: required
      before_script:
        - bash ./tests/travis/install-postgres-11.sh
    - stage: Test
      php: 7.3
      env: DB=sqlsrv
      sudo: required
      before_script:
        - bash ./tests/travis/install-sqlsrv-dependencies.sh
        - bash ./tests/travis/install-mssql-sqlsrv.sh
        - bash ./tests/travis/install-mssql.sh
    - stage: Test
      php: 7.3
      env: DB=pdo_sqlsrv
      sudo: required
      before_script:
        - bash ./tests/travis/install-sqlsrv-dependencies.sh
        - bash ./tests/travis/install-mssql-pdo_sqlsrv.sh
        - bash ./tests/travis/install-mssql.sh
    - stage: Test
      php: 7.3
      env: DB=ibm_db2
      sudo: required
      before_script:
        - bash ./tests/travis/install-db2.sh
        - bash ./tests/travis/install-db2-ibm_db2.sh
    - stage: Test
      php: 7.3
      env: DB=sqlite DEPENDENCIES=low
      install:
        - travis_retry composer update --prefer-dist --prefer-lowest
    - stage: Test
      php: 7.4
      env: DB=mysql.docker IMAGE=mysql:8.0
    - stage: Test
      php: 7.4
      env: DB=mysqli-tls.docker IMAGE=mysql:8.0 TLS=yes
    - stage: Test
      php: 7.4
      env: DB=mariadb.docker IMAGE=mariadb:10.3
    - stage: Test
      php: 7.4
      env: DB=mariadb.mysqli.docker IMAGE=mariadb:10.3
    - stage: Test
      php: 7.4
      env: DB=pgsql POSTGRESQL_VERSION=11.0
      sudo: required
      before_script:
        - bash ./tests/travis/install-postgres-11.sh
    - stage: Test
      php: 7.4
      env: DB=sqlite
    - stage: Test
      php: 7.4
      env: DB=sqlsrv MSSQL_COLLATION=Latin1_General_100_CS_AS
      sudo: required
      before_script:
        - bash ./tests/travis/install-sqlsrv-dependencies.sh
        - bash ./tests/travis/install-mssql-sqlsrv.sh
        - bash ./tests/travis/install-mssql.sh
    - stage: Test
      php: 7.4
      env: DB=pdo_sqlsrv MSSQL_COLLATION=Latin1_General_100_CS_AS
      sudo: required
      before_script:
        - bash ./tests/travis/install-sqlsrv-dependencies.sh
        - bash ./tests/travis/install-mssql-pdo_sqlsrv.sh
        - bash ./tests/travis/install-mssql.sh
    - stage: Test
      if: type = cron
      php: 7.2
      env: DB=sqlite DEPENDENCIES=dev
      install:
        - composer config minimum-stability dev
        - travis_retry composer update --prefer-dist

  allow_failures:
    - env: DEPENDENCIES=dev
