os: linux
dist: focal
language: php

php:
  - 7.4
  - nightly

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

before_install:
  - mv ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/xdebug.ini{,.disabled} || echo "xdebug not available"
  - composer self-update

install: travis_retry composer install

script:
  - ./vendor/bin/phpunit

jobs:
  allow_failures:
    - php: nightly

  include:
    - stage: Metrics and quality
      env: COVERAGE
      before_script:
        - mv ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/xdebug.ini{.disabled,}
        - if [[ ! $(php -m | grep -si xdebug) ]]; then echo "xdebug required for coverage"; exit 1; fi
      script:
        - ./vendor/bin/phpunit --coverage-clover ./clover.xml
      after_script:
        - wget https://scrutinizer-ci.com/ocular.phar
        - php ocular.phar code-coverage:upload --format=php-clover ./clover.xml

    - stage: Metrics and quality
      env: CODE_STANDARD
      script:
      - ./vendor/bin/phpcs

    - stage: Metrics and quality
      env: MUTATION
      before_script:
        - mv ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/xdebug.ini{.disabled,}
        - if [[ ! $(php -m | grep -si xdebug) ]]; then echo "xdebug required for coverage"; exit 1; fi
      script:
        - ./vendor/bin/phpunit --coverage-xml=build/coverage-xml --log-junit=build/junit.xml
        - ./vendor/bin/infection -s --threads=$(nproc) --coverage=build

    - stage: Metrics and quality
      env: STATIC_ANALYSIS
      script:
        - ./vendor/bin/phpstan analyse
