2016-01-16 02:15:24 -06:00
|
|
|
#!/bin/bash
|
|
|
|
|
2016-03-03 02:35:45 -06:00
|
|
|
searchFile=""
|
|
|
|
deleteDatabases=false
|
|
|
|
|
|
|
|
while getopts ":nhf:" opt; do
|
|
|
|
case $opt in
|
|
|
|
n)
|
|
|
|
# echo "-n was triggered: new database!" >&2
|
|
|
|
deleteDatabases=true
|
|
|
|
;;
|
|
|
|
f)
|
|
|
|
#echo "-f was triggered: file! $OPTARG" >&2
|
|
|
|
searchFile=$OPTARG
|
|
|
|
;;
|
|
|
|
h)
|
|
|
|
echo "n: new database" >&2
|
|
|
|
echo "f: which file to run" >&2
|
|
|
|
;;
|
|
|
|
:)
|
|
|
|
echo "Option -$OPTARG requires an argument." >&2
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
\?)
|
|
|
|
echo "Invalid option: -$OPTARG" >&2
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
2016-01-16 02:15:24 -06:00
|
|
|
# set testing environment
|
|
|
|
cp .env.testing .env
|
|
|
|
|
2016-01-19 11:09:53 -06:00
|
|
|
# set default phpunit.
|
|
|
|
cp phpunit.default.xml phpunit.xml
|
|
|
|
|
2016-01-20 03:47:29 -06:00
|
|
|
# "create" default attachment:
|
|
|
|
touch storage/upload/at-1.data
|
|
|
|
touch storage/upload/at-2.data
|
|
|
|
|
2016-03-03 02:35:45 -06:00
|
|
|
# delete databses:
|
|
|
|
if [ "$deleteDatabases" = true ] ; then
|
|
|
|
echo "Will delete and recreate the databases."
|
2016-01-20 03:47:29 -06:00
|
|
|
|
2016-03-03 02:35:45 -06:00
|
|
|
# delete test database:
|
|
|
|
if [ -f storage/database/testing.db ]
|
|
|
|
then
|
|
|
|
echo "Deleted testing.db"
|
|
|
|
rm storage/database/testing.db
|
|
|
|
fi
|
|
|
|
|
|
|
|
# delete test database copy:
|
|
|
|
if [ -f storage/database/testing-copy.db ]
|
|
|
|
then
|
|
|
|
echo "Delete testing-copy.db"
|
|
|
|
rm storage/database/testing-copy.db
|
|
|
|
fi
|
2016-01-16 02:15:24 -06:00
|
|
|
fi
|
|
|
|
|
2016-03-03 02:35:45 -06:00
|
|
|
# do not delete database:
|
|
|
|
if [ "$deleteDatabases" = false ] ; then
|
|
|
|
echo "Will not delete databases."
|
2016-01-19 09:55:02 -06:00
|
|
|
fi
|
|
|
|
|
|
|
|
# test!
|
2016-03-03 02:35:45 -06:00
|
|
|
if [ "$searchFile" == "" ]
|
2016-01-22 15:39:51 -06:00
|
|
|
then
|
|
|
|
echo "Running all tests..."
|
|
|
|
phpunit
|
2016-01-24 08:55:48 -06:00
|
|
|
result=$?
|
2016-01-22 15:39:51 -06:00
|
|
|
fi
|
|
|
|
|
|
|
|
# test selective..
|
|
|
|
dirs=("acceptance/Controllers" "acceptance/Controllers/Auth" "acceptance/Controllers/Chart" "unit")
|
|
|
|
#
|
2016-03-03 02:35:45 -06:00
|
|
|
if [ "$searchFile" != "" ]
|
2016-01-22 15:39:51 -06:00
|
|
|
then
|
2016-03-03 02:35:45 -06:00
|
|
|
echo "Will run test for '$searchFile'"
|
2016-01-22 15:39:51 -06:00
|
|
|
for i in "${dirs[@]}"
|
|
|
|
do
|
2016-03-03 02:35:45 -06:00
|
|
|
firstFile="./tests/$i/$searchFile.php"
|
|
|
|
secondFile="./tests/$i/"$searchFile"Test.php"
|
2016-01-22 15:39:51 -06:00
|
|
|
if [ -f "$firstFile" ]
|
|
|
|
then
|
|
|
|
# run it!
|
2016-03-03 02:35:45 -06:00
|
|
|
echo "Found file '$firstFile'"
|
2016-01-22 15:39:51 -06:00
|
|
|
phpunit --verbose $firstFile
|
2016-01-24 08:55:48 -06:00
|
|
|
result=$?
|
2016-01-22 15:39:51 -06:00
|
|
|
fi
|
|
|
|
if [ -f "$secondFile" ]
|
|
|
|
then
|
|
|
|
# run it!
|
2016-03-03 02:35:45 -06:00
|
|
|
echo "Found file '$secondFile'"
|
2016-01-22 15:39:51 -06:00
|
|
|
phpunit --verbose $secondFile
|
2016-01-24 08:55:48 -06:00
|
|
|
result=$?
|
2016-01-22 15:39:51 -06:00
|
|
|
fi
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
|
2016-01-16 02:15:24 -06:00
|
|
|
# restore .env file
|
|
|
|
cp .env.local .env
|
2016-01-24 08:55:48 -06:00
|
|
|
|
|
|
|
exit ${result}
|