# Ensure that PHP is installed in Travis' build environment. Travis provides several versions of
# PHP like 5.6, 7.0, 7.1, 7.2, 7.3, 7.4, etc., each of them including XDebug and PHPUnit.
language: php

# Travis can cache content between builds. This speeds up the build process and saves resources.
cache:
  yarn: true
  directories:
    # Cache composer packages so "composer install" is faster.
    - $HOME/.composer/cache/files
    # Cache the directory where Symfony stores its slightly modified version of PHPUnit.
    - ./bin/.phpunit
    # Cache the Symfony binary's directory so that it does not have to be reinstalled.
    - $HOME/.symfony

env:
  global:
    # Symfony's PHPUnit bridge provides a modified version of PHPUnit. The modified PHPUnit is
    # written to a directory that can be configured by the SYMFONY_PHPUNIT_DIR env var, or in
    # the same directory as the simple-phpunit if it is not provided. It's also possible to set
    # this env var in the phpunit.xml.dist file.
    - SYMFONY_PHPUNIT_DIR=./bin/.phpunit
    - SYMFONY_DEPRECATIONS_HELPER=9
    - ACTION="install"
    # Add the Symfony binary's path to PATH.
    - PATH="$HOME/.symfony/bin:$PATH"

# Defines all jobs which Travis will run in parallel. For each PHP version we support we will run one job.
jobs:
  # With fast finishing enabled, Travis CI will mark your build as finished as soon as one of two
  # conditions are met: The only remaining jobs are allowed to fail, or a job has already failed. In
  # these cases, the status of the build can already be determined, so there’s no need to wait around
  # until the other jobs finish.
  fast_finish: true
  include:
    # Run tests with the dependencies from composer.lock
    - php: 7.2
    - php: 7.3
    - php: 7.4

    # Run tests against dev (currently 5.1.x-dev)
    - php: 7.3
      env: STABILITY=dev ACTION=update

    # Run tests against dev-master (currently 5.2.x-dev)
    - php: 7.3
      env: STABILITY=dev SYMFONY=5.* ACTION=update

before_install:
  - phpenv config-rm xdebug.ini || true
  # Change minimum-stability to allow upcoming versions (dev | alpha | beta | RC)
  - '[[ -z $STABILITY ]] || composer config minimum-stability "$STABILITY"'
  # Change extra.symfony.require used by symfony flex
  - '[[ -z $SYMFONY ]] || composer config extra.symfony.require "$SYMFONY"'
  # If it is available update the Symfony binary, if not install it.
  - if symfony self:version; then symfony self:update --yes ; else wget https://get.symfony.com/cli/installer -O - | bash ; fi

install:
  - php -r "echo ini_get('memory_limit').PHP_EOL;"
  # Install or update Composer packages including dev dependencies listed in require-dev.
  - COMPOSER_MEMORY_LIMIT=-1 composer $ACTION
  - ./bin/phpunit install

script:
  # There's no need to load data fixtures before running tests because the project
  # repository already includes a test database with all the fixtures needed to run the tests.
  - ./bin/phpunit
  # This checks that the source code follows the Symfony Code Syntax rules.
  - '[[ $TRAVIS_PHP_VERSION != "7.4" ]] || ./vendor/bin/php-cs-fixer fix --diff --dry-run -v'
  # This checks that the YAML config files contain no syntax errors.
  - ./bin/console lint:yaml config --parse-tags
  # This checks that the Twig template files contain no syntax errors.
  - ./bin/console lint:twig templates --env=prod
  # This checks that the XLIFF translations contain no syntax errors.
  - ./bin/console lint:xliff translations
  # This checks that arguments injected into services match type declarations.
  - ./bin/console lint:container
  # This checks that the application doesn't use dependencies with known security vulnerabilities.
  - symfony check:security
  # This checks that Doctrine's mapping configurations are valid.
  - ./bin/console doctrine:schema:validate --skip-sync -vvv --no-interaction
  # Fail CI if the repo is in a dirty state after building assets (only for current release ie install).
  #-  if [[ "$ACTION" == "install" ]]; then yarn install && yarn encore production && git add --all && git diff --staged --exit-code; fi
  - composer validate --strict
