sudo: false
dist: trusty

language: php

cache:
  directories:
    - "$HOME/.composer/cache/files"

env:
  global:
    - APP_ENV="test"
    - APP_SECRET=a448d1dfcaa563fce56c2fd9981f662b
    - MAILER_URL=null://localhost
    - SULU_ADMIN_EMAIL=
    - PHPCR_TRANSPORT=doctrinedbal

matrix:
  include:
    - php: 7.2
      env:
        - COMPOSER_FLAGS="--prefer-dist --no-interaction --prefer-lowest --prefer-stable"
        - DATABASE_URL=postgres://postgres:postgres@127.0.0.1/sulu_form_test?serverVersion=9.2
        - DATABASE_CHARSET=UTF8
        - DATABASE_COLLATE=
      services:
        - postgresql
    - php: 7.4
      env:
        - COMPOSER_FLAGS="--prefer-dist --no-interaction"
        - DATABASE_URL=mysql://root:@127.0.0.1/sulu_form_test?serverVersion=5.6
        - DATABASE_CHARSET=utf8mb4
        - DATABASE_COLLATE=utf8mb4_unicode_ci
        - CODE_COVERAGE=true
        - LINT=true
        - PECL_INSTALL=imagick
      services:
        - mysql

before_install:
  - phpenv config-add Tests/travis.php.ini
  - | # enable swap
    if [[ $ENABLE_SWAP == 'true' ]]; then
        sudo fallocate -l 4G /swapfile
        sudo chmod 600 /swapfile
        sudo mkswap /swapfile
        sudo swapon /swapfile
        sudo sysctl vm.swappiness=10
    fi
  - |
    if [[ $PECL_INSTALL ]]; then
        printf "\n" | pecl install $PECL_INSTALL
    fi
  - php -m
  - composer self-update

install:
  - travis_retry composer update $COMPOSER_FLAGS
  - composer validate --strict
  - composer info -i
  - ./Tests/Application/bin/adminconsole doctrine:database:create
  - ./Tests/Application/bin/adminconsole doctrine:schema:update --force

script:
  - if [[ LINT == 'true' ]]; then composer lint; fi
  - ./vendor/bin/phpunit

