stages:
  - test

variables:
  APP_ENV: ci
  SSH_PRIVATE_KEY: $SSH_PRIVATE_KEY

before_script:
  - apt-get -yqq update
  - apt-get -yqq install zip unzip git openssh-client

  # Run ssh-agent and add private key
  - eval $(ssh-agent -s)
  - mkdir -p ~/.ssh
  - chmod 700 ~/.ssh
  - echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config
  - ssh-add <(echo "$SSH_PRIVATE_KEY")
  - git config --global user.email "exploitation@opentalent.fr"
  - git config --global user.name "git"

  # install composer
  - curl -sS https://composer.github.io/installer.sig > installer.sig
  - php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
  - php -r "if (hash_file('SHA384', 'composer-setup.php') === file_get_contents('installer.sig')) { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
  - php composer-setup.php
  - php -r "unlink('composer-setup.php'); unlink('installer.sig');"

cache:
  paths:
    - ./vendor

unit:
  stage: test

  script:
    - php composer.phar --no-interaction --quiet install
    - php bin/phpunit --configuration phpunit.xml.dist --colors=never --no-interaction

  artifacts:
    paths:
      - ./coverage/
    when: always
    reports:
      junit: ./coverage/junit-report.xml

  coverage: '/^\s*Lines:\s*\d+.\d+\%/'

