#!/usr/bin/env bash
# Lancia la suite Kernel dei moduli custom.
#
# SIMPLETEST_DB non e' scritto in phpunit-kernel.xml: le credenziali vivono nel settings.php
# locale, che non e' versionato. Qui si leggono da li' e si passano come variabile d'ambiente,
# cosi' nessuna password finisce in git.
#
# Uso: scripts/run-kernel-tests.sh [argomenti aggiuntivi per phpunit]
set -euo pipefail

cd "$(dirname "$0")/.."

SETTINGS="web/sites/default/settings.php"
if [[ ! -f "$SETTINGS" ]]; then
	echo "settings.php non trovato: $SETTINGS" >&2
	exit 1
fi

if [[ -z "${SIMPLETEST_DB:-}" ]]; then
	SIMPLETEST_DB="$(php scripts/simpletest-db-url.php "$SETTINGS")"
fi

export SIMPLETEST_DB
exec vendor/bin/phpunit -c phpunit-kernel.xml --testsuite custom-kernel "$@"
