language: php

matrix:
  fast_finish: true

  include:
    - php: 7
      env: UNIT_TESTS=yes FUNCTIONAL_TESTS=yes ACCEPTANCE_TESTS=yes PHP_LINT=yes XLF_CHECK=yes SUBMODULE_TEST=yes

sudo: false

addons:
  apt:
    packages:
      - parallel

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

env:
  global:
    secure: NGVAI0ayw2h9pB2bi2u9AkfV1OKa2LCrGXNtxAvQhFxKW28qmeOUehFuacxpvCI5fA8Ae7oVo2Ba0vcpb5a3uJry1lMpxcn9Ic+voB7SwlCuL6Rx/vntPkYUH+58cC3t40yHKArCUE9KCJA6znNCaZ7MyG6dWHgry0cvAjVOQzE=

services:
  - memcached
  - redis-server

notifications:
  irc:
    channels:
      - "irc.freenode.net#typo3-cms"
    on_success: change
    on_failure: always
    use_notice: true
  slack:
    rooms:
      secure: nHWVTPyG3CQWIcYA1LASS11dD0/NBcmrAyr3xxQW0XYtH47ZUKRlEtxrVLuL7ptciNwMbfZgsiRQ1QGWDerHUlBkg0iwRxpUZgeylzWaiXsHFVAp2IBfEX54KrWeYm9gewIBDDtnp+sLgpXGgmpIs2bAGkZe5129UsUExoWh0+g=
    on_success: change
    on_failure: always
  webhooks:
    urls:
      - http://www.t3bot.de/hooks/travis/index.php
    on_success: always
    on_failure: always
    on_start: never

before_script:
  - phpenv config-rm xdebug.ini
  - if [ "$GITHUB_COMPOSER_AUTH" ]; then composer config -g github-oauth.github.com $GITHUB_COMPOSER_AUTH; fi
  - composer install

script:
  - >
    if [[ "$UNIT_TESTS" == "yes" ]]; then
      echo;
      echo "Running unit tests";
      ./bin/phpunit -c typo3/sysext/core/Build/UnitTests.xml
    fi
  - >
    if [[ "$FUNCTIONAL_TESTS" == "yes" ]]; then
        echo;
        export typo3DatabaseName="typo3";
        export typo3DatabaseHost="localhost";
        export typo3DatabaseUsername="root";
        export typo3DatabasePassword="";
        find . -wholename '*typo3/sysext/*/Tests/Functional/*Test.php' | parallel --gnu 'echo; echo "Running functional test suite {}"; ./bin/phpunit -c typo3/sysext/core/Build/FunctionalTests.xml {}'
    fi
  - >
    if [[ "$ACCEPTANCE_TESTS" == "yes" ]]; then
        export _JAVA_OPTIONS="-Xms1024m -Xmx1024m";
        ./bin/selenium-server-standalone >/dev/null 2>&1 &
        php -S 0.0.0.0:8000 >/dev/null 2>&1 &
        sleep 5;
        export typo3DatabaseName="typo3";
        export typo3DatabaseHost="localhost";
        export typo3DatabaseUsername="root";
        export typo3DatabasePassword="";
        ./bin/codecept run acceptance -c typo3/sysext/core/Build/AcceptanceTests.yml typo3/sysext/core/Tests/Acceptance --debug
    fi
  - >
    if [[ "$PHP_LINT" == "yes" ]]; then
        echo;
        echo "Running php lint";
        find typo3/ -name \*.php -not -path "vendor/*" | parallel --gnu php -d display_errors=stderr -l {} > /dev/null \;
    fi
  - >
    if [[ "$XLF_CHECK" == "yes" ]]; then
        echo;
        echo "Running XLF checker";
        ./typo3/sysext/core/Build/Scripts/xlfcheck.sh
    fi
  - >
      if [[ "$SUBMODULE_TEST" == "yes" ]]; then
          echo;
          echo "Running git submodule check";
          /bin/bash -c "
              if [[ `git submodule status 2>&1 | wc -l` -ne 0 ]]; then
                  echo \"Found a submodule definition in repository\";
                  exit 99;
              fi
          "
      fi