---
image: registry.gitlab.com/chill-projet/chill-app/php-base-image:7.4

# Select what we should cache between builds
cache:
  paths:
    - vendor/
    - .composer

before_script:
  # add extensions to postgres
  - PGPASSWORD=$POSTGRES_PASSWORD psql -U $POSTGRES_USER -h db -c "CREATE EXTENSION IF NOT EXISTS unaccent; CREATE EXTENSION IF NOT EXISTS pg_trgm;"
  # Install and run Composer
  - mkdir -p $COMPOSER_HOME
  - curl -sS https://getcomposer.org/installer | php
  # hack composer.json and composer.lock to download from chill bundle repository
  - |
    sed -i 's/\"url\": \"vendor\/chill-project\/chill-bundles\"/\"url\": \"https:\/\/gitlab.com\/Chill-Projet\/chill-bundles.git"/' composer.json
  - |
    sed -i 's/\"url\": \"vendor\/chill-project\/chill-bundles\"/\"url\": \"https:\/\/gitlab.com\/Chill-Projet\/chill-bundles.git"/' composer.lock
  # now install
  - php -d memory_limit=2G composer.phar update --no-scripts # do not clear cache to spare memory
  - php -d memory_limit=2G bin/console cache:clear
  - php bin/console doctrine:migrations:migrate -n
  - php -d memory_limit=2G bin/console doctrine:fixtures:load -n --env=test
  - php -d memory_limit=2G bin/console cache:clear --env=test
  - echo "before_script finished"

# Bring in any services we need http://docs.gitlab.com/ee/ci/docker/using_docker_images.html#what-is-a-service
# See http://docs.gitlab.com/ee/ci/services/README.html for examples.
services:
  - name: postgis/postgis:12-3.1-alpine
    alias: db
  - name: redis
    alias: redis

# Set any variables we need
variables:
  # Configure postgres environment variables (https://hub.docker.com/r/_/postgres/)
  POSTGRES_USER: postgres
  POSTGRES_PASSWORD: postgres
  # fetch the chill-app using git submodules
  GIT_SUBMODULE_STRATEGY: recursive
  REDIS_HOST: redis
  REDIS_PORT: 6379
  REDIS_URL: redis://redis:6379
  # cache some composer data
  COMPOSER_HOME: .composer
  APP_ENV: test
  APP_SECRET: ThisIsNotSecret
  ADMIN_PASSWORD: admin
  DATABASE_URL: "postgresql://postgres:postgres@db:5432/postgres?serverVersion=12&charset=utf8"
  MAILER_DSN: "null://null"
  SAML_BASE_URL: http://localhost/
  SAML_ENTITY_ID: http://localhost/
  SAML_IDP_X509_CERT: 12345


# Run our tests
test:
  script:
    - php -d memory_limit=3G bin/phpunit --colors=never --testsuite VendeeBundle