general:
  branches:
    ignore:
      - '3.6'
      - '3.7'
      - '3.8'

machine:
  php:
    version: 5.5.31
  node:
    version: 4.2.0
  services:
    - memcached
    - redis
    - mysql

dependencies:
  cache_directories:
    - elasticsearch-1.6.0 # relative to the build directory
    - node_modules
    - ~/.composer
  pre:
    - yes '' | pecl install imagick
    - pecl install json
    - sudo apt-get install libzmq-dev
    - yes '' | pecl install zmq-beta
    - echo "extension = zmq.so" > /opt/circleci/php/$(phpenv global)/etc/conf.d/zmq.ini
    - echo "date.timezone = UTC" > /opt/circleci/php/$(phpenv global)/etc/conf.d/timezone.ini
    - sed -i 's/^\(session.cache_limiter = \).*/\1""/' /opt/circleci/php/$(phpenv global)/etc/php.ini
  override:
    - composer install --no-progress --no-interaction --optimize-autoloader
  post:
    - npm install
    - if [[ ! -e elasticsearch-1.6.0 ]]; then wget --no-check-certificate https://download.elastic.co/elasticsearch/elasticsearch/elasticsearch-1.6.0.tar.gz && tar -xvf elasticsearch-1.6.0.tar.gz && elasticsearch-1.6.0/bin/plugin install elasticsearch/elasticsearch-analysis-icu/2.6.0; fi
    - elasticsearch-1.6.0/bin/elasticsearch: {background: true}


database:
  override:
    - mysql -u ubuntu -e 'CREATE DATABASE update39_test;CREATE DATABASE ab_test;CREATE DATABASE db_test;SET @@global.sql_mode=STRICT_ALL_TABLES;SET @@global.max_allowed_packet=33554432;SET @@global.wait_timeout=999999;';
  post:
    - "./bin/developer system:uninstall -v"
    - "./bin/setup system:install -v --email=test@phraseanet.com --password=test --db-host=127.0.0.1 --db-user=ubuntu --db-template=fr --db-password= --databox=db_test --appbox=ab_test --server-name=http://127.0.0.1 -y --es-host=localhost --es-port=9200 --es-index=phrasea_test;"
    - "./bin/developer ini:setup-tests-dbs -v"
    - "./bin/console searchengine:index:create -d -v"
    - "./bin/developer phraseanet:regenerate-sqlite -v"
    - "./bin/developer phraseanet:generate-js-fixtures -v"

test:
  override:
    - case $CIRCLE_NODE_INDEX in 0) EXIT=0; php -d memory_limit=-1 bin/phpunit --log-junit $CIRCLE_TEST_REPORTS/phpunit/junit-unit.xml --exclude-group legacy || EXIT=$?; ./node_modules/.bin/gulp test || EXIT=$?; php -d memory_limit=-1 bin/phpunit --log-junit $CIRCLE_TEST_REPORTS/phpunit/junit-legacy-no-web.xml --group legacy --exclude-group web || EXIT=$?; exit $EXIT;; 1) php -d memory_limit=-1 bin/phpunit --log-junit $CIRCLE_TEST_REPORTS/phpunit/junit-legacy-web.xml --group web ;; esac:
        parallel: true
