language: php

php:
  - 5.4
  # - 5.5

services:
  - mysql

before_script:
  # Repositories.
  - sudo add-apt-repository ppa:ondrej/php5-oldstable
  - sudo apt-get update

  # Permissions.
  # @todo, Commit upstream to containers.
  - CURRENT_USER=$(whoami)
  - sudo chown -R ${CURRENT_USER}:${CURRENT_USER} $(pwd)

  # Directory stucture.
  - mkdir build

  # Apache.
  - sudo apt-get install -y sudo apache2 libapache2-mod-php5 php5-gd php5-mcrypt php5-curl php5-xdebug php5-mysql
  - sudo a2enmod rewrite headers
  - sudo sed -e "s/www-data/travis/g" --in-place /etc/apache2/envvars

  # Additional PHP config
  - echo -e "apc.enable_cli = 1\napc.shm_size = 128M\napc.num_files_hint = 7000" > apc.ini
  - if [ `expr "$(phpenv global)" "<" "5.5"` -eq 1 ]; then phpenv config-add apc.ini; fi
  - phpenv config-add core/misc/travis-ci/php.ini
  - phpenv config-rm xdebug.ini
  - sudo cp -f core/misc/travis-ci/php.ini /etc/php5/apache2/php.ini
  - sudo cp -f core/misc/travis-ci/php.ini /etc/php5/cli/php.ini

  # vHost.
  - sudo cp -f core/misc/travis-ci/vhost.conf /etc/apache2/sites-enabled/000-default
  - sudo sed -e "s?%BUILD_DIR%?$(pwd)?g" --in-place /etc/apache2/sites-enabled/000-default

  # Kick Apache!
  - sudo service apache2 restart

  # Mysql.
  - mysql -uroot -proot -hmysql -e 'SET GLOBAL wait_timeout = 5400;'
  - mysql -uroot -proot -hmysql -e 'SET GLOBAL innodb_fast_shutdown=0;'
  - mysql -uroot -proot -hmysql -e 'CREATE DATABASE drupal;'
  - mysql -uroot -proot -hmysql -e 'GRANT ALL PRIVILEGES ON drupal.* TO "drupal"@"%" IDENTIFIED BY "drupal";'
  - mysql -uroot -proot -hmysql -e 'FLUSH PRIVILEGES;'

script:
  - php core/scripts/run-tests.sh --keep-results --color --concurrency 4 --php `which php` --url http://localhost/ --sqlite build/test.sqlite --dburl mysql://drupal:drupal@mysql/drupal --all
