#!/bin/bash
set -e

BASH_XTRACEFD=1
set -x

patch -p1 < debian/patches/DEP-8/Form-drop-test-failing-on-CI.patch
mkdir vendor
phpab   --output vendor/autoload.php \
	--whitelist '*\\tests\\*' \
	--template debian/autoload.php.tests.tpl \
	--blacklist 'symfony\\component\\dependencyinjection\\tests\\fixtures\\container\\projectservicecontainer' \
	src/Symfony

set +x
components=$(find src/Symfony -mindepth 3 -type f -name phpunit.xml.dist -printf '%h\n')
echo "$components" | parallel --gnu --keep-order 'echo -e "\\nRunning {} tests"; phpunit --colors=always --exclude-group network,tty,benchmark,intl-data,functional,composer {} || (echo -e "\\e[41mKO\\e[0m {}" && $(exit 1));' && exit_code=0 || exit_code=$?
set -x

rm -rf ./vendor
patch -Rp1 < debian/patches/DEP-8/Form-drop-test-failing-on-CI.patch

exit $exit_code
