language: php

dist: xenial

services:
  - docker

php:
  - 7.0
  - 7.1
  - 7.2
  - 7.3
  - 7.4

matrix:
  fast_finish: true
  include:
    - php: 5.4
      dist: trusty
    - php: 5.5
      dist: trusty
    - php: 5.6
      dist: trusty

env:
  global:
    - DISPLAY=:99.0

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

before_install:
  # Install symfony/error-handler on compatible PHP versions to avoid a deprecation warning of the old DebugClassLoader and ErrorHandler classes
  - if [[ "$TRAVIS_PHP_VERSION" != 5.* && "$TRAVIS_PHP_VERSION" != 7.0 ]]; then composer require --no-update --dev symfony/error-handler "^4.4 || ^5.0"; fi;

install:
  - composer install -n --prefer-dist

before_script:
  - mkdir ./logs
  - docker run -p 4444:4444 --network=host -v /dev/shm:/dev/shm --shm-size 2g -e JAVA_OPTS="-Dselenium.LOGGER.level=WARNING" selenium/standalone-firefox:2.53.1 &> ./logs/selenium.log &
  - ./vendor/bin/mink-test-server &> ./logs/mink-test-server.log &
  - until $(echo | nc localhost 4444); do sleep 1; echo Waiting for Selenium server on port 4444...; done; echo "Selenium server started"
  - until $(echo | nc localhost 8002); do sleep 1; echo waiting for PHP server on port 8002...; done; echo "PHP server started"

script:
  - ./vendor/bin/phpunit -v --coverage-clover=coverage.clover

after_script:
  - wget https://scrutinizer-ci.com/ocular.phar
  - php ocular.phar code-coverage:upload --format=php-clover coverage.clover

after_failure:
  - cat ./logs/selenium.log
  - cat ./logs/mink-test-server.log
