language: php
sudo: false

php:
  - 5.5
  - 5.6
  - 7.0

env:
  - DRUPAL_CORE=8.2.x
  - DRUPAL_CORE=8.3.x

mysql:
  database: og_menu
  username: root
  encoding: utf8

before_script:
  # Remove Xdebug as we don't need it and it causes "PHP Fatal error: Maximum
  # function nesting level of '256' reached."
  # We also don't care if that file exists or not on PHP 7.
  - phpenv config-rm xdebug.ini || true

  # Remember the current directory for later use in the Drupal installation.
  - TESTDIR=$(pwd)

  # Navigate out of module directory to prevent blown stack by recursive module
  # lookup.
  - cd ..

  # Create database.
  - mysql -e 'create database og_menu'

  # Export database variable for kernel tests.
  - export SIMPLETEST_DB=mysql://root:@127.0.0.1/og_menu

  # Download Drupal 8 core.
  - travis_retry git clone --branch $DRUPAL_CORE --depth 1 https://git.drupal.org/project/drupal.git
  - cd drupal

  # Install Composer dependencies.
  - composer self-update && composer install

  # Download OG.
  - travis_retry git clone --branch 8.x-1.x --depth 1 https://github.com/gizra/og.git modules/og

  # Reference OG in the Drupal site.
  - ln -s $TESTDIR modules/og_menu

  # Start a web server on port 8888 in the background.
  - nohup php -S localhost:8888 > /dev/null 2>&1 &

  # Wait until the web server is responding.
  - until curl -s localhost:8888; do true; done > /dev/null

  # Export web server URL for browser tests.
  - export SIMPLETEST_BASE_URL=http://localhost:8888

script:
  # Run the PHPUnit tests which also include the kernel tests.
  - ./vendor/phpunit/phpunit/phpunit -c ./core/phpunit.xml.dist ./modules/og_menu
