firefly-iii/test.sh

110 lines
2.5 KiB
Bash
Raw Normal View History

2016-11-19 08:55:49 -06:00
#!/bin/bash
2016-11-19 09:13:57 -06:00
DATABASE=./storage/database/database.sqlite
DATABASECOPY=./storage/database/databasecopy.sqlite
ORIGINALENV=./.env
BACKUPENV=./.env.current
TESTINGENV=./.env.testing
2016-11-19 09:28:04 -06:00
# do something with flags:
resetTestFlag=''
2016-11-19 13:30:30 -06:00
testflag=''
coverageflag=''
2016-11-20 01:30:25 -06:00
acceptancetestclass=''
2016-12-09 09:30:33 -06:00
verbalflag=''
2016-12-22 12:51:49 -06:00
testsuite=''
2016-11-19 09:28:04 -06:00
2016-12-22 12:51:49 -06:00
while getopts 'vcrta:s:' flag; do
2016-11-19 09:28:04 -06:00
case "${flag}" in
2016-11-20 01:30:25 -06:00
r)
resetTestFlag='true'
2016-11-20 01:30:25 -06:00
;;
t)
testflag='true'
;;
c)
coverageflag='true'
;;
2016-12-09 09:30:33 -06:00
v)
2016-12-22 12:51:49 -06:00
verbalflag=' -v --debug'
echo "Will be verbal about it"
2016-12-09 09:30:33 -06:00
;;
2016-11-20 01:30:25 -06:00
a)
acceptancetestclass=./tests/acceptance/$OPTARG
echo "Will only run acceptance test $OPTARG"
;;
2016-12-22 12:51:49 -06:00
s)
testsuite="--testsuite $OPTARG"
echo "Will only run test suite '$OPTARG'"
;;
2016-11-19 09:28:04 -06:00
*) error "Unexpected option ${flag}" ;;
esac
done
2016-11-19 09:13:57 -06:00
# backup current config (if it exists):
if [ -f $ORIGINALENV ]; then
mv $ORIGINALENV $BACKUPENV
fi
2016-11-19 08:55:49 -06:00
# enable testing config
2016-11-19 09:13:57 -06:00
cp $TESTINGENV $ORIGINALENV
2016-11-19 08:55:49 -06:00
# clear cache:
php artisan cache:clear
2016-11-19 09:28:04 -06:00
# reset database (optional)
if [[ $resetTestFlag == "true" ]]
2016-11-19 09:13:57 -06:00
then
2016-11-19 08:55:49 -06:00
echo "Must reset database"
# touch files to make sure they exist.
touch $DATABASE
touch $DATABASECOPY
# truncate original database file
truncate $DATABASE --size 0
# run migration
php artisan migrate:refresh --seed
# call test data generation script
2017-01-20 01:03:26 -06:00
$(which php) /sites/FF3/test-data/artisan generate:data local sqlite
2016-11-19 08:55:49 -06:00
# copy new database over backup (resets backup)
cp $DATABASE $DATABASECOPY
fi
2016-11-19 09:28:04 -06:00
# do not reset database (optional)
if [[ $resetTestFlag == "" ]]
2016-11-19 09:28:04 -06:00
then
echo "Will not reset database"
fi
2016-12-27 08:46:52 -06:00
echo "Copy test database over original"
2016-11-19 08:55:49 -06:00
# take database from copy:
cp $DATABASECOPY $DATABASE
# run PHPUnit
2016-11-19 13:30:30 -06:00
if [[ $testflag == "" ]]
2016-11-19 09:13:57 -06:00
then
2016-11-19 09:07:02 -06:00
echo "Must not run PHPUnit"
else
2016-11-19 09:28:04 -06:00
echo "Must run PHPUnit"
2016-11-19 13:30:30 -06:00
if [[ $coverageflag == "" ]]
then
2016-12-22 12:51:49 -06:00
echo "Must run PHPUnit without coverage:"
echo "phpunit --stop-on-error $verbalflag $acceptancetestclass $testsuite"
phpunit --stop-on-error $verbalflag $acceptancetestclass $testsuite
2016-11-19 13:30:30 -06:00
else
echo "Must run PHPUnit with coverage"
2016-12-22 12:51:49 -06:00
echo "phpunit --stop-on-error $verbalflag --configuration phpunit.coverage.xml $acceptancetestclass $testsuite"
phpunit --stop-on-error $verbalflag --configuration phpunit.coverage.xml $acceptancetestclass $testsuite
2016-11-19 13:30:30 -06:00
fi
2016-11-19 09:07:02 -06:00
fi
2016-11-19 08:55:49 -06:00
# restore current config:
2016-11-19 09:13:57 -06:00
if [ -f $BACKUPENV ]; then
mv $BACKUPENV $ORIGINALENV
fi