version: '2.3'
services:
  composer_install:
    image: typo3/core-testing-${DOCKER_PHP_IMAGE}:latest
    user: ${HOST_UID}
    volumes:
      - ${ROOT_DIR}:${ROOT_DIR}
    working_dir: ${ROOT_DIR}
    command: >
      /bin/sh -c "
        if [ ${SCRIPT_VERBOSE} -eq 1 ]; then
          set -x
        fi
        composer install;
      "

  composer_validate:
    image: typo3/core-testing-${DOCKER_PHP_IMAGE}:latest
    user: ${HOST_UID}
    volumes:
      - ${ROOT_DIR}:${ROOT_DIR}
    working_dir: ${ROOT_DIR}
    command: >
      /bin/sh -c "
        if [ ${SCRIPT_VERBOSE} -eq 1 ]; then
          set -x
        fi
        composer validate;
      "

  lint:
    image: typo3/core-testing-${DOCKER_PHP_IMAGE}:latest
    user: ${HOST_UID}
    volumes:
      - ${ROOT_DIR}:${ROOT_DIR}
    working_dir: ${ROOT_DIR}
    command: >
      /bin/sh -c "
        if [ ${SCRIPT_VERBOSE} -eq 1 ]; then
          set -x
        fi
        php -v | grep '^PHP';
        find . -name \\*.php ! -path "./.Build/\\*" -print0 | xargs -0 -n1 -P4 php -n -c /etc/php/cli-no-xdebug/php.ini -l >/dev/null
      "

  cgl:
    image: typo3/core-testing-${DOCKER_PHP_IMAGE}:latest
    user: "${HOST_UID}"
    volumes:
      - ${ROOT_DIR}:${ROOT_DIR}
    working_dir: ${ROOT_DIR}
    command: >
      /bin/sh -c "
        if [ ${SCRIPT_VERBOSE} -eq 1 ]; then
          set -x
        fi
        php -dxdebug.mode=off .Build/vendor/friendsofphp/php-cs-fixer/php-cs-fixer fix -v ${CGLCHECK_DRY_RUN} \
          --config=Build/php-cs-fixer.php --using-cache=no
      "

  unit:
    image: typo3/core-testing-${DOCKER_PHP_IMAGE}:latest
    user: ${HOST_UID}
    volumes:
      - ${ROOT_DIR}:${ROOT_DIR}
    working_dir: ${ROOT_DIR}/.Build
    command: >
      /bin/sh -c "
        if [ ${SCRIPT_VERBOSE} -eq 1 ]; then
          set -x
        fi
        php -v | grep '^PHP'
        if [ ${PHP_XDEBUG_ON} -eq 0 ]; then
          php -n -c /etc/php/cli-no-xdebug/php.ini \
            vendor/phpunit/phpunit/phpunit -c ../Build/phpunit/UnitTests.xml ${EXTRA_TEST_OPTIONS} ${TEST_FILE};
        else
          DOCKER_HOST=`route -n | awk '/^0.0.0.0/ { print $$2 }'`
          XDEBUG_CONFIG=\"remote_port=${PHP_XDEBUG_PORT} remote_enable=1 remote_host=$${DOCKER_HOST}\" \
            vendor/phpunit/phpunit/phpunit -c ../Build/phpunit/UnitTests.xml ${EXTRA_TEST_OPTIONS} ${TEST_FILE};
        fi
      "

  unitDeprecated:
    image: typo3/core-testing-${DOCKER_PHP_IMAGE}:latest
    user: "${HOST_UID}"
    volumes:
      - ${ROOT_DIR}:${ROOT_DIR}
    working_dir: ${ROOT_DIR}/.Build
    command: >
      /bin/sh -c "
        if [ ${SCRIPT_VERBOSE} -eq 1 ]; then
          set -x
        fi
        php -v | grep '^PHP'
        if [ ${PHP_XDEBUG_ON} -eq 0 ]; then
          XDEBUG_MODE=\"off\" \
          vendor/phpunit/phpunit/phpunit -c ../Build/phpunit/UnitTestsDeprecated.xml ${EXTRA_TEST_OPTIONS} ${TEST_FILE};
        else
          DOCKER_HOST=`route -n | awk '/^0.0.0.0/ { print $$2 }'`
          XDEBUG_MODE=\"debug,develop\" \
          XDEBUG_TRIGGER=\"foo\" \
          XDEBUG_CONFIG=\"client_port=${PHP_XDEBUG_PORT} client_host=$${DOCKER_HOST}\" \
          vendor/phpunit/phpunit/phpunit -c ../Build/phpunit/UnitTestsDeprecated.xml ${EXTRA_TEST_OPTIONS} ${TEST_FILE};
        fi
      "

  phpstan:
    image: typo3/core-testing-${DOCKER_PHP_IMAGE}:latest
    user: "${HOST_UID}"
    volumes:
      - ${ROOT_DIR}:${ROOT_DIR}
    working_dir: ${ROOT_DIR}
    command: >
      /bin/sh -c "
        if [ ${SCRIPT_VERBOSE} -eq 1 ]; then
          set -x
        fi
        mkdir -p .cache
        .Build/bin/phpstan analyse -c Build/phpstan/phpstan.neon --no-progress --no-interaction --memory-limit 4G ${TEST_FILE}
      "

  phpstan_generate_baseline:
    image: typo3/core-testing-${DOCKER_PHP_IMAGE}:latest
    user: "${HOST_UID}"
    volumes:
      - ${ROOT_DIR}:${ROOT_DIR}
    working_dir: ${ROOT_DIR}
    command: >
      /bin/sh -c "
        if [ ${SCRIPT_VERBOSE} -eq 1 ]; then
          set -x
        fi
        mkdir -p .cache
        .Build/bin/phpstan analyse -c Build/phpstan/phpstan.neon --no-progress --no-interaction --memory-limit 4G --generate-baseline=Build/phpstan/phpstan-baseline.neon
      "
