language: php

dist: xenial

notifications:
  email: false

php:
  - "7.1"
  - "7.2"
  - "7.3"
  - "7.4"

matrix:
  fast_finish: true

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

# Numeric values of error reporting levels:
# 32767: E_ALL
# 30711: E_ALL & ~E_NOTICE & ~E_STRICT
# 24575: E_ALL & ~E_DEPRECATED
# 24567: E_ALL & ~E_DEPRECATED & ~E_NOTICE
# 22527: E_ALL & ~E_DEPRECATED & ~E_STRICT
# 22519: E_ALL & ~E_DEPRECATED & ~E_NOTICE & ~E_STRICT
#
# Keep TRAVIS_ERROR_LEVEL in sync with the value in vendor/oxid-esales/testing-library/base.php
#
env: TRAVIS_ERROR_LEVEL=32767 OX_BASE_PATH="$TRAVIS_BUILD_DIR/source/"

services: mysql

before_install:
  - echo 'Europe/Berlin' | sudo tee /etc/timezone
  - sudo dpkg-reconfigure --frontend noninteractive tzdata
  - sudo apt-get update
  - composer self-update 1.10.16

before_script:
  # remove xdebug
  - phpenv config-rm xdebug.ini
  # apache setup (https://docs.travis-ci.com/user/languages/php/#apache--php)
  - sudo apt-get install apache2 libapache2-mod-fastcgi
  # enable php-fpm
  - sudo cp ~/.phpenv/versions/$(phpenv version-name)/etc/php-fpm.conf.default ~/.phpenv/versions/$(phpenv version-name)/etc/php-fpm.conf
  - if [[ $(phpenv version-name) = 7.* ]]; then sudo cp ~/.phpenv/versions/$(phpenv version-name)/etc/php-fpm.d/www.conf.default ~/.phpenv/versions/$(phpenv version-name)/etc/php-fpm.d/www.conf; fi;
  - sudo a2enmod rewrite actions fastcgi alias
  - echo "cgi.fix_pathinfo = 1" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini
  - sudo sed -i -e "s,www-data,travis,g" /etc/apache2/envvars
  - sudo chown -R travis:travis /var/lib/apache2/fastcgi
  - ~/.phpenv/versions/$(phpenv version-name)/sbin/php-fpm
  # configure apache virtual hosts
  - sudo cp .travis.sites_conf /etc/apache2/sites-available/000-default.conf
  - sudo sed -e "s?%TRAVIS_BUILD_DIR%?$(pwd)/source?g" --in-place /etc/apache2/sites-available/000-default.conf
  - sudo service apache2 restart

  # database setup
  - sudo sed -e 's|utf8_unicode_ci|latin1_general_ci|g; s|utf8|latin1|g' --in-place /etc/mysql/my.cnf
  - sudo service mysql restart

  # replace configuration values in config.inc.php
  - cp source/config.inc.php.dist source/config.inc.php
  - sed -i 's|<dbHost>|localhost|; s|<dbName>|oxideshop|; s|<dbUser>|root|; s|<dbPwd>||; s|<sShopURL>|http://localhost|; s|<sShopDir>|'$TRAVIS_BUILD_DIR'/source|; s|<sCompileDir>|'$TRAVIS_BUILD_DIR'/source/tmp|; s|$this->iDebug = 0|$this->iDebug = 1|' source/config.inc.php
  - sed -i "s|\$this->edition = ''|\$this->edition = 'CE'|" source/config.inc.php

  # set permissions to log directory
  - chmod -R 777 "${TRAVIS_BUILD_DIR}/source/log"

  # composer initiation
  - COMPOSER_MEMORY_LIMIT=-1 SHOP_PATH='source' SHOP_TESTS_PATH='tests' MODULES_PATH='' composer install

script:
  - php vendor/bin/phpcs
  - php vendor/bin/runtests
