forked from firefly-iii/firefly-iii
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.sh
executable file
·110 lines (92 loc) · 2.46 KB
/
test.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
107
108
109
110
#!/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=''
acceptancetestclass=''
verbalflag=''
testsuite=''
while getopts 'vcrta: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"
;;
a)
acceptancetestclass=./tests/acceptance/$OPTARG
echo "Will only run acceptance 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
# clear cache:
php artisan cache:clear
# 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
# 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 $acceptancetestclass $testsuite"
phpunit --stop-on-error $verbalflag $acceptancetestclass $testsuite
else
echo "Must run PHPUnit with coverage"
echo "phpunit --stop-on-error $verbalflag --configuration phpunit.coverage.xml $acceptancetestclass $testsuite"
phpunit --stop-on-error $verbalflag --configuration phpunit.coverage.xml $acceptancetestclass $testsuite
fi
fi
# restore current config:
if [ -f $BACKUPENV ]; then
mv $BACKUPENV $ORIGINALENV
fi