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:
|
2016-12-25 04:50:42 -06:00
|
|
|
resetTestFlag=''
|
2016-11-19 13:30:30 -06:00
|
|
|
testflag=''
|
|
|
|
coverageflag=''
|
2017-04-27 01:26:58 -05:00
|
|
|
|
2017-04-22 00:05:55 -05:00
|
|
|
featureflag=''
|
2017-03-03 23:54:05 -06:00
|
|
|
featuretestclass=''
|
2017-04-27 01:26:58 -05:00
|
|
|
|
|
|
|
unitflag=''
|
|
|
|
unittestclass=''
|
|
|
|
|
2016-12-09 09:30:33 -06:00
|
|
|
verbalflag=''
|
2016-12-22 12:51:49 -06:00
|
|
|
testsuite=''
|
2017-04-22 00:05:55 -05:00
|
|
|
configfile='phpunit.xml';
|
2016-11-19 09:28:04 -06:00
|
|
|
|
2017-04-27 01:26:58 -05:00
|
|
|
while getopts 'vcrtf:u:s:' flag; do
|
2016-11-19 09:28:04 -06:00
|
|
|
case "${flag}" in
|
2016-11-20 01:30:25 -06:00
|
|
|
r)
|
2016-12-25 04:50:42 -06:00
|
|
|
resetTestFlag='true'
|
2016-11-20 01:30:25 -06:00
|
|
|
;;
|
|
|
|
t)
|
|
|
|
testflag='true'
|
|
|
|
;;
|
|
|
|
c)
|
|
|
|
coverageflag='true'
|
2017-04-22 00:05:55 -05:00
|
|
|
configfile='phpunit.coverage.xml';
|
2016-11-20 01:30:25 -06:00
|
|
|
;;
|
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
|
|
|
;;
|
2017-03-03 23:54:05 -06:00
|
|
|
f)
|
2017-04-22 00:05:55 -05:00
|
|
|
featureflag='true'
|
2017-03-03 23:54:05 -06:00
|
|
|
featuretestclass=./tests/Feature/$OPTARG
|
|
|
|
echo "Will only run Feature test $OPTARG"
|
2016-11-20 01:30:25 -06:00
|
|
|
;;
|
2017-04-27 01:26:58 -05:00
|
|
|
u)
|
|
|
|
unitflag='true'
|
|
|
|
unittestclass=./tests/Unit/$OPTARG
|
|
|
|
echo "Will only run Unit 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
|
|
|
|
|
2017-04-27 01:26:58 -05:00
|
|
|
if [[ $coverageflag == "true" && ($featureflag == "true" || $unitflag == "true") ]]
|
2017-04-22 00:05:55 -05:00
|
|
|
then
|
|
|
|
echo "Use config file specific.xml"
|
|
|
|
configfile='phpunit.coverage.specific.xml'
|
|
|
|
fi
|
2016-11-19 09:28:04 -06:00
|
|
|
|
|
|
|
|
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
|
|
|
|
2016-11-19 09:28:04 -06:00
|
|
|
# reset database (optional)
|
2016-12-25 04:50:42 -06:00
|
|
|
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
|
|
|
|
|
2016-12-25 04:50:42 -06:00
|
|
|
# call test data generation script
|
2017-01-20 01:03:26 -06:00
|
|
|
$(which php) /sites/FF3/test-data/artisan generate:data local sqlite
|
2017-06-07 00:38:58 -05:00
|
|
|
|
|
|
|
# also run upgrade routine:
|
|
|
|
$(which php) /sites/FF3/firefly-iii/artisan firefly:upgrade-database
|
|
|
|
|
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)
|
2016-12-25 04:50:42 -06:00
|
|
|
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
|
|
|
|
|
2017-02-12 09:50:35 -06:00
|
|
|
echo "clear caches and what-not.."
|
|
|
|
php artisan cache:clear
|
|
|
|
php artisan config:clear
|
|
|
|
php artisan route:clear
|
|
|
|
php artisan twig:clean
|
|
|
|
php artisan view:clear
|
|
|
|
|
2016-11-19 08:55:49 -06:00
|
|
|
# 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:"
|
2017-04-22 00:05:55 -05:00
|
|
|
|
2017-04-27 01:26:58 -05:00
|
|
|
echo "phpunit $verbalflag --configuration $configfile $featuretestclass $unittestclass $testsuite"
|
|
|
|
phpunit $verbalflag --configuration $configfile $featuretestclass $unittestclass $testsuite
|
2016-11-19 13:30:30 -06:00
|
|
|
else
|
|
|
|
echo "Must run PHPUnit with coverage"
|
2017-04-27 01:26:58 -05:00
|
|
|
echo "phpunit $verbalflag --configuration $configfile $featuretestclass $unittestclass $testsuite"
|
|
|
|
phpunit $verbalflag --configuration $configfile $featuretestclass $unittestclass $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
|