language: php

sudo: required

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

services:
  - mongodb
  - docker

env:
  - MONGO_URI="mongodb://127.0.0.1:27017"
    MONGO_DBNAME="gridfs_test"
    SFTP_HOST=localhost
    SFTP_PORT=2222
    SFTP_USER=gaufrette
    SFTP_PASSWORD=gaufrette
    SFTP_BASE_DIR=gaufrette
    FTP_HOST=localhost
    FTP_PORT=21
    FTP_USER=gaufrette
    FTP_PASSWORD=gaufrette
    FTP_BASE_DIR=/gaufrette/

matrix:
  include:
    - php: '5.6'
    - php: '7.0'
    - php: '7.1'
    - php: '7.2'

before_install:
  - echo "extension = mongodb.so" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini;
  - phpenv config-rm xdebug.ini || echo "xdebug not available"
  - docker run -p ${SFTP_PORT}:22 -d atmoz/sftp:alpine ${SFTP_USER}:${SFTP_PASSWORD}:::${SFTP_BASE_DIR}
  - docker run -d --name ftpd_server -p ${FTP_PORT}:21 -p 30000-30009:30000-30009 -e "PUBLICHOST=${FTP_HOST}" stilliard/pure-ftpd
  - docker exec -it ftpd_server sh -c "(echo ${FTP_PASSWORD}; echo ${FTP_PASSWORD}) | pure-pw useradd ${FTP_USER} -f /etc/pure-ftpd/passwd/pureftpd.passwd -m -u ftpuser -d /home/ftpusers/${FTP_USER}"
  - if [[ ${TRAVIS_PHP_VERSION} = 5.* ]]; then sudo apt-get -qq update && sudo apt-get install -y libssh2-1-dev; fi
  - if [[ ${TRAVIS_PHP_VERSION} = 5.* ]]; then yes | pecl install -f ssh2 && composer require herzult/php-ssh --no-update --no-scripts; fi

install:
  - composer update --prefer-dist --no-progress --no-suggest --ansi

script:
  - php vendor/bin/phpspec run -fpretty --verbose
  - php vendor/bin/phpunit --verbose
