<commit_before>#!/bin/bash

DIR=$(dirname `which $0`)

. ${DIR}/../resources/colors.sh
. ${DIR}/../resources/trycatch.sh

cd ${DIR}

for arg in "$@"; do
case $arg in
	-c|--copy-configuration)
		COPYCONFIGURATION=YES
	;;
	-h|--help)
		HELP=YES
	;;
	-f=*|--filter=*)
		FILTER="--filter ${arg#*=}"
		shift
	;;
	-l|--coveralls)
		COVERALLS=YES
	;;
	-q|--code-quality)
		CODEQUALITY=YES
	;;
	-r|--reset-db)
		DATABASE=YES
	;;
	-s|--scrutinizer)
		SCRUTINIZER=YES
	;;
	-t|--travis)
		TRAVIS=YES
	;;
	-u|--composer-update)
		COMPOSERUPDATE=YES
	;;
	-v=*|--coverage=*)
		CODECOVERAGE="${arg#*=}"
		shift
	;;
	-cc|--coverage-clover)
		CODECOVERAGE="xml"
		shift
	;;
	-ch|--coverage-html)
		CODECOVERAGE="html"
		shift
	;;
	-ct|--coverage-tap)
		CODECOVERAGE="txt"
		shift
	;;
	*)
		# unknown option
	;;
esac
shift # past argument or value
done

if [[ "$HELP" == "YES" ]]; then
	echo "Usage: run-tests.sh [OPTION]..."
	echo
	echo "  -c, --copy-configuration    copy last API configuration before tests"
	echo "  -f, --filter=FILTER         use a valid PHPUnit filter"
	echo "  -l, --coveralls             upload code coverage report to Coveralls"
	echo "                                requires -v=xml"
	echo "  -q, --code-quality          generate code quality report"
	echo "  -r, --reset-db              reset database data"
	echo "  -s, --scrutinizer           upload code quality and code coverage reports to Scrutinizer"
	echo "                                requires -q -v=xml"
	echo "  -t, --travis                shortcut for Travis, using: -u -c -v=xml -q -l -s"
	echo "  -u, --composer-update       update Composer dependencies before tests"
	echo "  -v, --coverage=TYPE         generate code coverage report:"
	echo "                                TYPE=html for HTML output"
	echo "                                TYPE=txt for TAP (text) output"
	echo "                                TYPE=xml for Clover (XML) output"
	echo "  -cc, --coverage-clover      equivalent to --code-coverage=xml"
	echo "  -ch, --coverage-html        equivalent to --code-coverage=html"
	echo "  -ct, --coverage-tap         equivalent to --code-coverage=txt"
	echo
	exit 0
fi

if [[ "$TRAVIS" == "YES" ]]; then
	set @=$@"--composer-update --copy-configuration --coverage-clover --code-quality --coveralls --scrutinizer"
	COMPOSERUPDATE=YES
	COPYCONFIGURATION=YES
	CODECOVERAGE=xml
	CODEQUALITY=YES
	COVERALLS=YES
	SCRUTINIZER=YES
fi

try
(
	throwErrors

	if [[ "$DATABASE" == "YES" ]]; then
		echox "${text_cyan}Reset and populate API database"
		sudo -u "postgres" psql --quiet "postgres" -f /vagrant/resources/database/init.sql;
		sudo -u "postgres" psql --quiet "neap" -f /vagrant/resources/database/structure.sql;
		sudo -u "postgres" psql --quiet "neap" -f /vagrant/resources/database/oauth2.sql;
		sudo -u "postgres" psql --quiet "neap" -f /vagrant/resources/database/data.sql;

		echox "${text_cyan}Import fixtures"
		sudo -u "postgres" psql --quiet "neap" -f /vagrant/resources/database/fixtures.sql;
	fi

	if [[ "$COMPOSERUPDATE" == "YES" ]]; then
		echox "${text_cyan}Update composer"
		sudo composer self-update
		composer install --no-interaction --ignore-platform-reqs --prefer-source
	fi

	if [[ "$COPYCONFIGURATION" == "YES" ]]; then
		echox "${text_cyan}Copy latest configuration files"
		cp -v config/autoload/local.php.dist config/autoload/local.php
		cp -v config/autoload/oauth2.local.php.dist config/autoload/oauth2.local.php
	fi

	if [[ "$CODECOVERAGE" == "xml" ]]; then
		echox "${text_cyan}Run phpunit tests with Clover code coverage"
		./vendor/bin/phpunit -c module/phpunit.xml $FILTER --coverage-clover ./build/logs/coverage.xml
	elif [[ "$CODECOVERAGE" == "html" ]]; then
		echox "${text_cyan}Run phpunit tests with HTML code coverage"
		./vendor/bin/phpunit -c module/phpunit.xml $FILTER --coverage-html ./build/logs/coverage<commit_msg>removed sudo call from test runner script<commit_after>#!/bin/bash

DIR=$(dirname `which $0`)

. ${DIR}/../resources/colors.sh
. ${DIR}/../resources/trycatch.sh

cd ${DIR}

for arg in "$@"; do
case $arg in
	-c|--copy-configuration)
		COPYCONFIGURATION=YES
	;;
	-h|--help)
		HELP=YES
	;;
	-f=*|--filter=*)
		FILTER="--filter ${arg#*=}"
		shift
	;;
	-l|--coveralls)
		COVERALLS=YES
	;;
	-q|--code-quality)
		CODEQUALITY=YES
	;;
	-r|--reset-db)
		DATABASE=YES
	;;
	-s|--scrutinizer)
		SCRUTINIZER=YES
	;;
	-t|--travis)
		TRAVIS=YES
	;;
	-u|--composer-update)
		COMPOSERUPDATE=YES
	;;
	-v=*|--coverage=*)
		CODECOVERAGE="${arg#*=}"
		shift
	;;
	-cc|--coverage-clover)
		CODECOVERAGE="xml"
		shift
	;;
	-ch|--coverage-html)
		CODECOVERAGE="html"
		shift
	;;
	-ct|--coverage-tap)
		CODECOVERAGE="txt"
		shift
	;;
	*)
		# unknown option
	;;
esac
shift # past argument or value
done

if [[ "$HELP" == "YES" ]]; then
	echo "Usage: run-tests.sh [OPTION]..."
	echo
	echo "  -c, --copy-configuration    copy last API configuration before tests"
	echo "  -f, --filter=FILTER         use a valid PHPUnit filter"
	echo "  -l, --coveralls             upload code coverage report to Coveralls"
	echo "                                requires -v=xml"
	echo "  -q, --code-quality          generate code quality report"
	echo "  -r, --reset-db              reset database data"
	echo "  -s, --scrutinizer           upload code quality and code coverage reports to Scrutinizer"
	echo "                                requires -q -v=xml"
	echo "  -t, --travis                shortcut for Travis, using: -u -c -v=xml -q -l -s"
	echo "  -u, --composer-update       update Composer dependencies before tests"
	echo "  -v, --coverage=TYPE         generate code coverage report:"
	echo "                                TYPE=html for HTML output"
	echo "                                TYPE=txt for TAP (text) output"
	echo "                                TYPE=xml for Clover (XML) output"
	echo "  -cc, --coverage-clover      equivalent to --code-coverage=xml"
	echo "  -ch, --coverage-html        equivalent to --code-coverage=html"
	echo "  -ct, --coverage-tap         equivalent to --code-coverage=txt"
	echo
	exit 0
fi

if [[ "$TRAVIS" == "YES" ]]; then
	set @=$@"--composer-update --copy-configuration --coverage-clover --code-quality --coveralls --scrutinizer"
	COMPOSERUPDATE=YES
	COPYCONFIGURATION=YES
	CODECOVERAGE=xml
	CODEQUALITY=YES
	COVERALLS=YES
	SCRUTINIZER=YES
fi

try
(
	throwErrors

	if [[ "$DATABASE" == "YES" ]]; then
		echox "${text_cyan}Reset and populate API database"
		psql --quiet "postgres" -U postgres -f resources/database/init.sql
		psql --quiet "neap" -U postgres -f resources/database/structure.sql
		psql --quiet "neap" -U postgres -f resources/database/oauth2.sql
		psql --quiet "neap" -U postgres -f resources/database/data.sql

		echox "${text_cyan}Import fixtures"
		psql --quiet "neap" -U postgres -f resources/database/fixtures.sql
	fi

	if [[ "$COMPOSERUPDATE" == "YES" ]]; then
		echox "${text_cyan}Update composer"
		composer self-update
		composer install --no-interaction --ignore-platform-reqs --prefer-source
	fi

	if [[ "$COPYCONFIGURATION" == "YES" ]]; then
		echox "${text_cyan}Copy latest configuration files"
		cp -v config/autoload/local.php.dist config/autoload/local.php
		cp -v config/autoload/oauth2.local.php.dist config/autoload/oauth2.local.php
	fi

	if [[ "$CODECOVERAGE" == "xml" ]]; then
		echox "${text_cyan}Run phpunit tests with Clover code coverage"
		./vendor/bin/phpunit -c module/phpunit.xml $FILTER --coverage-clover ./build/logs/coverage.xml
	elif [[ "$CODECOVERAGE" == "html" ]]; then
		echox "${text_cyan}Run phpunit tests with HTML code coverage"
		./vendor/bin/phpunit -c module/phpunit.xml $FILTER --coverage-html ./build/logs/coverage
{'fraction_non_alphanumeric': 0.15395702306079664, 'fraction_numerical': 0.001310272536687631, 'mean_word_length': 2.61239943208708, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 22}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5238724', 'n_tokens_mistral': 2925, 'n_tokens_neox': 2742, 'n_words': 667}