forked from GoteoFoundation/goteo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run-tests.sh
executable file
·106 lines (91 loc) · 2.74 KB
/
run-tests.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#!/bin/bash
CURR=$(dirname $(readlink -f $0))
cd $CURR
ARGS=()
for var in "$@"; do
if [ "$SET_CONFIG" == "1" ]; then
CONFIG="$var"
SET_CONFIG=
continue
fi
if [ "$var" == '--help' ] || [ "$var" == '-h' ]; then
echo "Wrap script for running tests"
echo "Usage"
echo -e "$0 [options|phpunit options]"
echo "Options"
echo -e "\t--reset-database (-r)\t Drops and reinstalls the database before testing"
echo -e "\t--test-config (-t) file.yml\t Specifies a settings.yml file to be used for testing"
echo "The rest of options will be passed to phpunit"
exit
# Remove --reset argument
elif [ "$var" == '--reset-database' ] || [ "$var" == '-r' ]; then
RESET_DATABASE=1
elif [ "$var" == '--test-config' ] || [ "$var" == '-t' ]; then
SET_CONFIG=1
continue
else
ARGS+=("$var")
fi
done
if [ ! -e "$CONFIG" ]; then
echo "Custom [$CONFIG] file not found"
CONFIG="config/test-settings.yml"
fi
if [ "${CONFIG:0:1}" != "/" ]; then
CONFIG=$CURR/$CONFIG;
fi
if [ "${CONFIG:0:1}" != "." ]; then
CONFIG=$(dirname $(readlink -f $CONFIG))/$(basename $CONFIG)
fi
echo "Using [$CONFIG] file for testing"
export GOTEO_TEST_CONFIG_FILE=$CONFIG;
export GOTEO_CONFIG_FILE=$CONFIG;
if [ "$RESET_DATABASE" != "" ]; then
echo "Wiping database:"
DB=$(cat $CONFIG | grep 'db:' -A8)
#remove spaces
DB=${DB// /}
#find database
DATABASE=$(echo "$DB" | grep 'database:')
DATABASE=${DATABASE/database:/}
DATABASE=${DATABASE%\#*}
HOST=$(echo "$DB" | grep 'host:')
HOST=${HOST/host:/}
HOST=${HOST%\#*}
PORT=$(echo "$DB" | grep 'port:')
PORT=${PORT/port:/}
PORT=${PORT%\#*}
USER=$(echo "$DB" | grep 'username:')
USER=${USER/username:/}
USER=${USER%\#*}
PASS=$(echo "$DB" | grep 'password:')
PASS=${PASS/password:/}
PASS=${PASS%\#*}
echo $DATABASE $HOST:$PORT $USER $PASS
if [[ $DATABASE != *"test"* ]]; then
echo "[$DATABASE] should contain the work 'test' to reset schema from here"
exit 2
fi
mysql -h $HOST -P $PORT -u$USER -p$PASS $DATABASE < $CURR/tests/sql_wipe.sql
if [ "$?" != '0' ]; then
echo "Error removing tables!"
exit 2
fi
# check if password is empty
if [ -z "$DATABASE" ]; then
DATABASE=$HOST
HOST=$PASS
PASS=''
else
PASS="-p$PASS"
fi
GOTEO_CONFIG_FILE=$CONFIG ./bin/console migrate install
if [ "$?" != '0' ]; then
echo "Error installing tables & migrating schema!"
exit 2
fi
echo "Done, now exiting. Run without the -r modifier to run tests"
exit
fi
echo executing ./vendor/bin/phpunit "${ARGS[@]}"
./vendor/bin/phpunit "${ARGS[@]}"