mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2024-11-25 18:30:55 -06:00
114 lines
2.5 KiB
Bash
Executable File
114 lines
2.5 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
DATABASE=./storage/database/database.sqlite
|
|
DATABASECOPY=./storage/database/databasecopy.sqlite
|
|
ORIGINALENV=./.env
|
|
BACKUPENV=./.env.current
|
|
TESTINGENV=./.env.testing
|
|
|
|
# do something with flags:
|
|
resetTestFlag=''
|
|
testflag=''
|
|
coverageflag=''
|
|
featuretestclass=''
|
|
verbalflag=''
|
|
testsuite=''
|
|
|
|
while getopts 'vcrtf:s:' flag; do
|
|
case "${flag}" in
|
|
r)
|
|
resetTestFlag='true'
|
|
;;
|
|
t)
|
|
testflag='true'
|
|
;;
|
|
c)
|
|
coverageflag='true'
|
|
;;
|
|
v)
|
|
verbalflag=' -v --debug'
|
|
echo "Will be verbal about it"
|
|
;;
|
|
f)
|
|
featuretestclass=./tests/Feature/$OPTARG
|
|
echo "Will only run Feature test $OPTARG"
|
|
;;
|
|
s)
|
|
testsuite="--testsuite $OPTARG"
|
|
echo "Will only run test suite '$OPTARG'"
|
|
;;
|
|
*) error "Unexpected option ${flag}" ;;
|
|
esac
|
|
done
|
|
|
|
|
|
|
|
# backup current config (if it exists):
|
|
if [ -f $ORIGINALENV ]; then
|
|
mv $ORIGINALENV $BACKUPENV
|
|
fi
|
|
|
|
# enable testing config
|
|
cp $TESTINGENV $ORIGINALENV
|
|
|
|
# reset database (optional)
|
|
if [[ $resetTestFlag == "true" ]]
|
|
then
|
|
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
|
|
$(which php) /sites/FF3/test-data/artisan generate:data local sqlite
|
|
# copy new database over backup (resets backup)
|
|
cp $DATABASE $DATABASECOPY
|
|
fi
|
|
|
|
# do not reset database (optional)
|
|
if [[ $resetTestFlag == "" ]]
|
|
then
|
|
echo "Will not reset database"
|
|
fi
|
|
|
|
echo "Copy test database over original"
|
|
# take database from copy:
|
|
cp $DATABASECOPY $DATABASE
|
|
|
|
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
|
|
|
|
# run PHPUnit
|
|
if [[ $testflag == "" ]]
|
|
then
|
|
echo "Must not run PHPUnit"
|
|
else
|
|
echo "Must run PHPUnit"
|
|
|
|
if [[ $coverageflag == "" ]]
|
|
then
|
|
echo "Must run PHPUnit without coverage:"
|
|
echo "phpunit --stop-on-error $verbalflag $featuretestclass $testsuite"
|
|
phpunit --stop-on-error $verbalflag $featuretestclass $testsuite
|
|
else
|
|
echo "Must run PHPUnit with coverage"
|
|
echo "phpunit --stop-on-error $verbalflag --configuration phpunit.coverage.xml $featuretestclass $testsuite"
|
|
phpunit --stop-on-error $verbalflag --configuration phpunit.coverage.xml $featuretestclass $testsuite
|
|
fi
|
|
fi
|
|
|
|
# restore current config:
|
|
if [ -f $BACKUPENV ]; then
|
|
mv $BACKUPENV $ORIGINALENV
|
|
fi |