#!/bin/bash
DBNAME=$1
DBUSER=$2
DBPASS=$3
DBHOST=$4

source ./update.sh
cp config.ini.default config.ini
sed -i "s/sgbd.config.host = localhost/sgbd.config.host = $DBHOST/g" config.ini
sed -i "s/sgbd.config.username =/sgbd.config.username = $DBUSER/g" config.ini
sed -i "s/sgbd.config.password =/sgbd.config.password = $DBPASS/g" config.ini
sed -i "s/sgbd.config.dbname =/sgbd.config.dbname = $DBNAME/g" config.ini
touch local.php

php --version

php scripts/upgrade_db.php

cd cosmogramme
cp config.ref.php config.php
sed -i "s/integration_server=localhost/integration_server=$DBHOST/g" config.php
sed -i "s/integration_user=root/integration_user=$DBUSER/g" config.php
sed -i "s/integration_pwd=root/integration_pwd=$DBPASS/g" config.php
sed -i "s/integration_base=opac3/integration_base=$DBNAME/g" config.php
cd ..

phpunit -c tests/phpunit.xml --list-suites && phpunit -c tests/phpunit.xml --exclude-group no-ci \
    && phpunit -c tests/phpunit_db.xml --list-suites && phpunit -c tests/phpunit_db.xml --exclude-group no-ci \
    && phpunit -c tests/phpunit_js.xml --list-suites && phpunit -c tests/phpunit_js.xml --exclude-group no-ci \
    && cd cosmogramme/tests && phpunit --list-suites && phpunit --exclude-group no-ci \
    && cd ../cosmozend/tests && phpunit --list-suites && phpunit --exclude-group no-ci
