services:
  - postgres:9.4

variables:
  POSTGRES_DB: "MaarchCourrier"
  POSTGRES_USER: maarch
  POSTGRES_PASSWORD: ""

stages:
  - test

before_script:
  - apt-get update > /dev/null
  - mkdir -p /usr/share/man/man1
  - mkdir -p /usr/share/man/man7
  #- apt-get install apt-utils -yqq > /dev/null
  #- apt-get install cron -yqq > /dev/null
  - apt-get install tar -yqq > /dev/null
  #- apt-get install wkhtmltopdf -yqq > /dev/null
  #- apt-get install wget -yqq > /dev/null
  #- wget https://downloads.wkhtmltopdf.org/0.12/0.12.4/wkhtmltox-0.12.4_linux-generic-amd64.tar.xz
  #- tar xvf wkhtmltox-0.12.4_linux-generic-amd64.tar.xz
  #- mv wkhtmltox/bin/wkhtmlto* /usr/bin
  #- chmod +x /usr/bin/wkhtmlto*
  #- apt-get install libreoffice -yqq > /dev/null
  #- apt-get install xpdf-utils -yqq > /dev/null
  #- apt-get install imagemagick -yqq > /dev/null
  #- apt-get install npm -yqq > /dev/null 
  - apt-get install git -yqq > /dev/null
  - bash ci/docker_install_php.sh > /dev/null
  - bash ci/docker_install_database.sh > /dev/null

job_php-7.1:
  image: php:7.1-apache
  stage: test
  script:
    - mkdir -p /opt/maarch/docservers/indexes/{letterbox_coll,attachments_coll,version_attachments_coll}
    - mkdir -p /opt/maarch/docservers/{ai,manual,manual_attachments,templates}
    - mkdir -p /opt/maarch/docservers/{convert_attachments,convert_attachments_version,convert_mlb}
    - mkdir -p /opt/maarch/docservers/{fulltext_attachments,fulltext_attachments_version,fulltext_mlb}
    - mkdir -p /opt/maarch/docservers/{thumbnails_attachments,thumbnails_attachments_version,thumbnails_mlb}
    - mkdir -p /var/www/html/
    - cp -R /builds/maarch/MaarchCourrier/ /var/www/html/
    - cd /var/www/html/MaarchCourrier
    - mkdir -p /var/www/html/MaarchCourrier
    #- curl -sL https://deb.nodesource.com/setup_7.x | bash - 
    #- apt-get install -yqq nodejs 
    #- npm install npm@latest -g 
    #- npm set registry https://registry.npmjs.org/ 
    #- npm install
    - sed 's/<databaseserver>.*<\/databaseserver>/<databaseserver>postgres<\/databaseserver>/;s/<databasepassword>.*<\/databasepassword>/<databasepassword><\/databasepassword>/;s/<databasename>.*<\/databasename>/<databasename>MaarchCourrier<\/databasename>/;s/<databaseuser>.*<\/databaseuser>/<databaseuser>maarch<\/databaseuser>/' apps/maarch_entreprise/xml/config.xml.default > apps/maarch_entreprise/xml/config.xml
    - curl --location -s --output /usr/local/bin/phpunit https://phar.phpunit.de/phpunit-7.phar
    - chmod +x /usr/local/bin/phpunit
    #- cd App/MaarchRM
    - phpunit --coverage-text --colors=never -c phpunit.xml
  only:
    - develop

job_php-7.0:
  image: php:7.0-apache
  stage: test
  script:
    - mkdir -p /opt/maarch/docservers/indexes/{letterbox_coll,attachments_coll,version_attachments_coll}
    - mkdir -p /opt/maarch/docservers/{ai,manual,manual_attachments,templates}
    - mkdir -p /opt/maarch/docservers/{convert_attachments,convert_attachments_version,convert_mlb}
    - mkdir -p /opt/maarch/docservers/{fulltext_attachments,fulltext_attachments_version,fulltext_mlb}
    - mkdir -p /opt/maarch/docservers/{thumbnails_attachments,thumbnails_attachments_version,thumbnails_mlb}
    - mkdir -p /var/www/html/
    - cp -R /builds/maarch/MaarchCourrier/ /var/www/html/
    - cd /var/www/html/MaarchCourrier
    - mkdir -p /var/www/html/MaarchCourrier
    #- curl -sL https://deb.nodesource.com/setup_7.x | bash - 
    #- apt-get install -yqq nodejs 
    #- npm install npm@latest -g 
    #- npm set registry https://registry.npmjs.org/ 
    #- npm install
    - sed 's/<databaseserver>.*<\/databaseserver>/<databaseserver>postgres<\/databaseserver>/;s/<databasepassword>.*<\/databasepassword>/<databasepassword><\/databasepassword>/;s/<databasename>.*<\/databasename>/<databasename>MaarchCourrier<\/databasename>/;s/<databaseuser>.*<\/databaseuser>/<databaseuser>maarch<\/databaseuser>/' apps/maarch_entreprise/xml/config.xml.default > apps/maarch_entreprise/xml/config.xml
    - curl --location -s --output /usr/local/bin/phpunit https://phar.phpunit.de/phpunit-6.phar
    - chmod +x /usr/local/bin/phpunit
    #- cd App/MaarchRM
    - phpunit --coverage-text --colors=never -c phpunit.xml
  only:
    - develop


