-
Notifications
You must be signed in to change notification settings - Fork 49
Expand file tree
/
Copy pathrunTests.sh
More file actions
executable file
·292 lines (265 loc) · 9.29 KB
/
Copy pathrunTests.sh
File metadata and controls
executable file
·292 lines (265 loc) · 9.29 KB
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
#!/usr/bin/env bash
#
# TYPO3 core test runner based on docker and docker compose.
#
# Function to write a .env file in Build/testing-docker/local
# This is read by docker compose and vars defined here are
# used in Build/testing-docker/local/docker compose.yml
setUpDockerComposeDotEnv() {
# Delete possibly existing local .env file if exists
[ -e .env ] && rm .env
# Set up a new .env file for docker compose
echo "COMPOSE_PROJECT_NAME=local" >> .env
# To prevent access rights of files created by the testing, the docker image later
# runs with the same user that is currently executing the script. docker compose can't
# use $UID directly itself since it is a shell variable and not an env variable, so
# we have to set it explicitly here.
echo "HOST_UID=`id -u`" >> .env
# Your local home directory for composer and npm caching
echo "HOST_HOME=${HOME}" >> .env
# Your local user
echo "ROOT_DIR"=${ROOT_DIR} >> .env
echo "HOST_USER=${USER}" >> .env
echo "TEST_FILE=${TEST_FILE}" >> .env
echo "PHP_XDEBUG_ON=${PHP_XDEBUG_ON}" >> .env
echo "PHP_XDEBUG_PORT=${PHP_XDEBUG_PORT}" >> .env
echo "PHP_VERSION=${PHP_VERSION}" >> .env
echo "DOCKER_PHP_IMAGE=${DOCKER_PHP_IMAGE}" >> .env
echo "EXTRA_TEST_OPTIONS=${EXTRA_TEST_OPTIONS}" >> .env
echo "SCRIPT_VERBOSE=${SCRIPT_VERBOSE}" >> .env
}
# Load help text into $HELP
read -r -d '' HELP <<EOF
aus_driver_amazon_s3 test runner. Execute unit test suite and some other details.
Also used by github actions for test execution.
Usage: $0 [options] [file]
No arguments: Run all unit tests with PHP 7.2
Options:
-s <...>
Specifies which test suite to run
- composerInstall: "composer install"
- composerInstallMax: "composer update", with no platform.php config.
- composerInstallMin: "composer update --prefer-lowest", with platform.php set to PHP version x.x.0.
- composerValidate: "composer validate"
- grumphp: "GrumPHP run"
- lint: PHP linting
- unit (default): PHP unit tests
- functional: functional tests
-d <mariadb|mssql|postgres|sqlite>
Only with -s functional
Specifies on which DBMS tests are performed
- mariadb (default): use mariadb
- mssql: use mssql microsoft sql server
- postgres: use postgres
- sqlite: use sqlite
-p <7.2|7.3|7.4|8.0|8.4>
Specifies the PHP minor version to be used
- 7.2: use PHP 7.2
- 7.3: use PHP 7.3
- 7.4: use PHP 7.4
- 8.0: use PHP 8.0
- 8.4: use PHP 8.4
-e "<phpunit options>"
Only with -s functional|unit
Additional options to send to phpunit tests.
For phpunit, options starting with "--" must be added after options starting with "-".
Example -e "-v --filter canRetrieveValueWithGP" to enable verbose output AND filter tests
named "canRetrieveValueWithGP"
-x
Only with -s unit
Send information to host instance for test or system under test break points. This is especially
useful if a local PhpStorm instance is listening on default xdebug port 9003. A different port
can be selected with -y
-y <port>
Send xdebug information to a different port than default 9003 if an IDE like PhpStorm
is not listening on default port.
-u
Update existing typo3gmbh/phpXY:latest docker images. Maintenance call to docker pull latest
versions of the main php images. The images are updated once in a while and only the youngest
ones are supported by core testing. Use this if weird test errors occur. Also removes obsolete
image versions of typo3gmbh/phpXY.
-v
Enable verbose script output. Shows variables and docker commands.
-h
Show this help.
Examples:
# Run unit tests using PHP 7.2
./Build/Scripts/runTests.sh
# Run unit tests using PHP 7.3
./Build/Scripts/runTests.sh -p 7.3
EOF
# Test if docker compose exists, else exit out with error
if ! (docker compose) 2> /dev/null 1> /dev/null; then
echo "This script relies on docker and docker compose. Please install" >&2
exit 1
fi
# Go to the directory this script is located, so everything else is relative
# to this dir, no matter from where this script is called.
THIS_SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )"
cd "$THIS_SCRIPT_DIR" || exit 1
# Go to directory that contains the local docker compose.yml file
cd ../testing-docker || exit 1
# Option defaults
ROOT_DIR=`readlink -f ${PWD}/../../`
TEST_SUITE="unit"
DBMS="mariadb"
PHP_VERSION="8.0"
PHP_XDEBUG_ON=0
PHP_XDEBUG_PORT=9003
EXTRA_TEST_OPTIONS=""
SCRIPT_VERBOSE=0
# Option parsing
# Reset in case getopts has been used previously in the shell
OPTIND=1
# Array for invalid options
INVALID_OPTIONS=();
# Simple option parsing based on getopts (! not getopt)
while getopts ":s:d:p:e:xy:huv" OPT; do
case ${OPT} in
s)
TEST_SUITE=${OPTARG}
;;
d)
DBMS=${OPTARG}
;;
p)
PHP_VERSION=${OPTARG}
;;
e)
EXTRA_TEST_OPTIONS=${OPTARG}
;;
x)
PHP_XDEBUG_ON=1
;;
y)
PHP_XDEBUG_PORT=${OPTARG}
;;
h)
echo "${HELP}"
exit 0
;;
u)
TEST_SUITE=update
;;
v)
SCRIPT_VERBOSE=1
;;
\?)
INVALID_OPTIONS+=(${OPTARG})
;;
:)
INVALID_OPTIONS+=(${OPTARG})
;;
esac
done
# Exit on invalid options
if [ ${#INVALID_OPTIONS[@]} -ne 0 ]; then
echo "Invalid option(s):" >&2
for I in "${INVALID_OPTIONS[@]}"; do
echo "-"${I} >&2
done
echo >&2
echo "${HELP}" >&2
exit 1
fi
# Move "7.2" to "php72", the latter is the docker container name
DOCKER_PHP_IMAGE=`echo "php${PHP_VERSION}" | sed -e 's/\.//'`
# Set $1 to first mass argument, this is the optional test file or test directory to execute
shift $((OPTIND - 1))
if [ -n "${1}" ]; then
TEST_FILE="Web/typo3conf/ext/aus_driver_amazon_s3/${1}"
fi
if [ ${SCRIPT_VERBOSE} -eq 1 ]; then
set -x
fi
# Suite execution
case ${TEST_SUITE} in
composerInstall)
setUpDockerComposeDotEnv
docker compose run composer_install
SUITE_EXIT_CODE=$?
docker compose down
;;
composerInstallMax)
setUpDockerComposeDotEnv
docker compose run composer_install_max
SUITE_EXIT_CODE=$?
docker compose down
;;
composerInstallMin)
setUpDockerComposeDotEnv
docker compose run composer_install_min
SUITE_EXIT_CODE=$?
docker compose down
;;
composerValidate)
setUpDockerComposeDotEnv
docker compose run composer_validate
SUITE_EXIT_CODE=$?
docker compose down
;;
functional)
setUpDockerComposeDotEnv
case ${DBMS} in
mariadb)
docker compose run functional_mariadb10
SUITE_EXIT_CODE=$?
;;
mssql)
docker compose run functional_mssql2019latest
SUITE_EXIT_CODE=$?
;;
postgres)
docker compose run functional_postgres10
SUITE_EXIT_CODE=$?
;;
sqlite)
# sqlite has a tmpfs as .Build/Web/typo3temp/var/tests/functional-sqlite-dbs/
# Since docker is executed as root (yay!), the path to this dir is owned by
# root if docker creates it. Thank you, docker. We create the path beforehand
# to avoid permission issues.
mkdir -p ${ROOT_DIR}/.Build/Web/typo3temp/var/tests/functional-sqlite-dbs/
rm -rf ${ROOT_DIR}/.Build/minio-data || true
cp -a ${ROOT_DIR}/Build/testing-docker/minio-data ${ROOT_DIR}/.Build/minio-data
docker compose run --rm functional_sqlite
SUITE_EXIT_CODE=$?
;;
*)
echo "Invalid -d option argument ${DBMS}" >&2
echo >&2
echo "${HELP}" >&2
exit 1
esac
docker compose down
;;
grumphp)
setUpDockerComposeDotEnv
docker compose run grumphp
SUITE_EXIT_CODE=$?
docker compose down
;;
lint)
setUpDockerComposeDotEnv
docker compose run lint
SUITE_EXIT_CODE=$?
docker compose down
;;
unit)
setUpDockerComposeDotEnv
docker compose run unit
SUITE_EXIT_CODE=$?
docker compose down
;;
update)
# pull ghcr.io/typo3/core-testing-php-*:latest versions of those ones that exist locally
docker images ghcr.io/typo3/core-testing-php-*:latest --format "{{.Repository}}:latest" | xargs -I {} docker pull {}
# remove "dangling" ghcr.io/typo3/core-testing-php-* images (those tagged as <none>)
docker images ghcr.io/typo3/core-testing-php-* --filter "dangling=true" --format "{{.ID}}" | xargs -I {} docker rmi {}
;;
*)
echo "Invalid -s option argument ${TEST_SUITE}" >&2
echo >&2
echo "${HELP}" >&2
exit 1
esac
exit $SUITE_EXIT_CODE