os: linux
dist: xenial
language: php

jobs:
  fast_finish: true
  include:
    #############################################
    # Builds using the default test script.
    #############################################
    - php: 5.4
      dist: trusty
    - php: 5.5
      dist: trusty
    - php: 5.6
    - php: 7.0
    - php: 7.1
    - php: 7.2
    - php: 7.3
    - php: 7.4
    # Nightly is PHP 8.0 since Feb 2019.
    - php: nightly
      addons:
        apt:
          packages:
            - libonig-dev

    #############################################
    # Builds which don't use the default test script.
    #############################################
    # Builds running the basic tests with different PHP ini settings.
    - php: 5.5
      name: "PHP: 5.5 | Unit tests with custom PHP ini"
      dist: trusty
      before_script:
      - phpenv config-add php5-testingConfig.ini
      script:
      - php bin/phpcs --config-set php_path php
      - vendor/bin/phpunit tests/AllTests.php
    - php: 7.0
      name: "PHP: 7.4 | Unit tests with custom PHP ini"
      before_script:
      - phpenv config-add php7-testingConfig.ini
      script:
      - php bin/phpcs --config-set php_path php
      - vendor/bin/phpunit tests/AllTests.php

    # Build running just the PEAR package file and XML file validation and code style check.
    - php: 7.4
      name: "PHP: 7.4 | Pear + XML validate"
      addons:
        apt:
          packages:
            - libxml2-utils
      before_install:
      - export XMLLINT_INDENT="    "
      - phpenv config-rm xdebug.ini || echo 'No xdebug config.'
      install:
      - curl -O https://www.w3.org/2012/04/XMLSchema.xsd
      script:
      # Validate the Pear Package file contents.
      - php scripts/validate-pear-package.php
      # Validate the xml ruleset files.
      # @link http://xmlsoft.org/xmllint.html
      - xmllint --noout --schema phpcs.xsd ./src/Standards/*/ruleset.xml
      - xmllint --noout --schema ./XMLSchema.xsd ./phpcs.xsd
      # Check the code-style consistency of the xml files.
      - diff -B ./phpcs.xml.dist <(xmllint --format "./phpcs.xml.dist")
      - diff -B ./src/Standards/Generic/ruleset.xml <(xmllint --format "./src/Standards/Generic/ruleset.xml")
      - diff -B ./src/Standards/MySource/ruleset.xml <(xmllint --format "./src/Standards/MySource/ruleset.xml")
      - diff -B ./src/Standards/PEAR/ruleset.xml <(xmllint --format "./src/Standards/PEAR/ruleset.xml")
      - diff -B ./src/Standards/PSR1/ruleset.xml <(xmllint --format "./src/Standards/PSR1/ruleset.xml")
      - diff -B ./src/Standards/PSR2/ruleset.xml <(xmllint --format "./src/Standards/PSR2/ruleset.xml")
      - diff -B ./src/Standards/PSR12/ruleset.xml <(xmllint --format "./src/Standards/PSR12/ruleset.xml")
      - diff -B ./src/Standards/Squiz/ruleset.xml <(xmllint --format "./src/Standards/Squiz/ruleset.xml")
      - diff -B ./src/Standards/Zend/ruleset.xml <(xmllint --format "./src/Standards/Zend/ruleset.xml")

    # Build running just and only PHPStan.
    - php: 7.4
      name: "PHP: 7.4 | PHPStan"
      env: PHPSTAN=1
      addons:
        apt:
          packages:
            - libonig-dev
      before_install:
      - phpenv config-rm xdebug.ini || echo 'No xdebug config.'
      script:
      - composer require --dev phpstan/phpstan
      - php vendor/bin/phpstan analyse --configuration=phpstan.neon

  allow_failures:
    - php: 7.4
      env: PHPSTAN=1
    - php: nightly

before_install:
  # Speed up build time by disabling Xdebug when its not needed.
  - phpenv config-rm xdebug.ini || echo 'No xdebug config.'
  # PHPUnit 8.x is not (yet) supported, so prevent issues with Travis images using it.
  - |
    if [[ $TRAVIS_PHP_VERSION != "nightly" ]]; then
      travis_retry composer install
    elif [[ $TRAVIS_PHP_VERSION == "nightly" ]]; then
      // Allow installing "incompatible" PHPUnit version on PHP 8/nightly.
      travis_retry composer install --ignore-platform-reqs
    fi

script:
  - php bin/phpcs --config-set php_path php
  - vendor/bin/phpunit tests/AllTests.php
  - php bin/phpcs --no-cache --parallel=1
  - pear package-validate package.xml
  - composer validate --no-check-all --strict
  - php scripts/build-phar.php
  - php phpcs.phar
