Updated test script [skip ci]

This commit is contained in:
James Cole
2016-03-03 09:35:45 +01:00
parent d4367f73a2
commit 21b473108f

70
pu.sh
View File

@@ -1,5 +1,33 @@
#!/bin/bash
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
# set testing environment
cp .env.testing .env
@@ -10,20 +38,32 @@ cp phpunit.default.xml phpunit.xml
touch storage/upload/at-1.data
touch storage/upload/at-2.data
# delete databses:
if [ "$deleteDatabases" = true ] ; then
echo "Will delete and recreate the databases."
# delete test databases:
if [ -f storage/database/testing.db ]
then
rm storage/database/testing.db
# 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
fi
if [ -f storage/database/testing-copy.db ]
then
rm storage/database/testing-copy.db
# do not delete database:
if [ "$deleteDatabases" = false ] ; then
echo "Will not delete databases."
fi
# test!
if [ -z "$1" ]
if [ "$searchFile" == "" ]
then
echo "Running all tests..."
phpunit
@@ -33,32 +73,30 @@ fi
# test selective..
dirs=("acceptance/Controllers" "acceptance/Controllers/Auth" "acceptance/Controllers/Chart" "unit")
#
if [ ! -z "$1" ]
if [ "$searchFile" != "" ]
then
echo "Will run test for '$searchFile'"
for i in "${dirs[@]}"
do
firstFile="./tests/$i/$1.php"
secondFile="./tests/$i/$1Test.php"
firstFile="./tests/$i/$searchFile.php"
secondFile="./tests/$i/"$searchFile"Test.php"
if [ -f "$firstFile" ]
then
# run it!
echo "Now running $firstFile"
echo "Found file '$firstFile'"
phpunit --verbose $firstFile
result=$?
fi
if [ -f "$secondFile" ]
then
# run it!
echo "Now running $secondFile"
echo "Found file '$secondFile'"
phpunit --verbose $secondFile
result=$?
fi
done
fi
# restore .env file
cp .env.local .env