-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathtest
executable file
·261 lines (215 loc) · 6.17 KB
/
test
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
#!/usr/bin/env bash
set -o pipefail
PHP_VERSION="${1}"
PHP_MAJOR=$(echo ${PHP_VERSION} | cut -d . -f -2)
CLI="jtreminio/php-cli:${PHP_VERSION}"
FPM="jtreminio/php:${PHP_VERSION}"
APACHE="jtreminio/php-apache:${PHP_VERSION}"
NGINX="jtreminio/php-nginx:${PHP_VERSION}"
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
FAIL='\033[0;31m[FAIL]\033[0m\n'
PASS='\033[0;32m[PASS]\033[0m\n'
if [[ -z "${PHP_VERSION// }" ]]; then
cat << EOF
Usage: test PHP_VERSION
Run tests against all Docker images
Example: test 7.2.25
Runs tests against - jtreminio:php-cli:7.2.25
- jtreminio:php:7.2.25
- jtreminio:php-apache:7.2.25
- jtreminio:php-nginx:7.2.25
EOF
exit 1
fi
###
# Setup network
create_test_network() {
NAME=jtreminio_testing
FOUND=$(docker network ls --filter name=${NAME} | grep -c ${NAME} || true)
if [[ ${FOUND} -eq 0 ]]; then
docker network create --driver bridge ${NAME} > /dev/null 2>&1
fi
}
rm_test_network() {
NAME=jtreminio_testing
FOUND=$(docker network ls --filter name=${NAME} | grep -c ${NAME} || true)
if [[ ${FOUND} -ne 0 ]]; then
docker network rm ${NAME} > /dev/null 2>&1
fi
}
run_fpm_container() {
ENVFLAG=""
if [[ ! -z "${1:-}" ]]; then
ENVFLAG="-e ${1}"
fi
docker container run --rm -d \
--name jtreminio_fpm_test \
--network jtreminio_testing \
-v ${DIR}/testing/index.php:/var/www/index.php \
${ENVFLAG} \
${FPM} \
bash -c '/usr/sbin/php-fpm -F' > /dev/null 2>&1
}
rm_fpm_container() {
NAME=jtreminio_fpm_test
FOUND=$(docker container ls --filter name=${NAME} | grep -c ${NAME} || true)
if [[ ${FOUND} -ne 0 ]]; then
docker container rm -f ${NAME} > /dev/null 2>&1
fi
}
run_fcgi_container() {
SETTING="${1}"
docker container run --rm \
--name jtreminio_test_runner \
--network jtreminio_testing \
jtreminio/test-runner \
/bin/sh -c "SCRIPT_FILENAME=/var/www/index.php \
REQUEST_METHOD=GET \
QUERY_STRING=\"setting=${SETTING}\" \
cgi-fcgi -bind -connect jtreminio_fpm_test:9000"
}
fail_if_0() {
RESULT="${1}"
if [[ ${RESULT} -eq 0 ]]; then
printf " ${FAIL}"
exit 1
else
printf " ${PASS}"
fi
}
fail_if_1() {
RESULT="${1}"
if [[ ${RESULT} -ne 0 ]]; then
printf " ${FAIL}"
exit 1
else
printf " ${PASS}"
fi
}
printf "Testing PHP ${PHP_MAJOR} / ${PHP_VERSION}\n\n"
create_test_network
###
printf "[CLI] Check version correct [${PHP_VERSION}]"
EXPECTS=${PHP_VERSION}
CMD=$(
docker container run --rm \
${CLI} php -v
)
fail_if_0 $(echo "${CMD}" | grep -c "${EXPECTS}")
printf "[FPM] Check version correct [${PHP_VERSION}]"
EXPECTS=${PHP_VERSION}
run_fpm_container
CMD=$(run_fcgi_container version)
rm_fpm_container
fail_if_0 $(echo "${CMD}" | grep -c "${EXPECTS}")
###
printf "[CLI] Check custom INI loaded"
EXPECTS="/etc/php/${PHP_MAJOR}/cli/conf.d/98-env.ini"
CMD=$(
docker container run --rm \
${CLI} php --ini
)
fail_if_0 $(echo "${CMD}" | grep -c "${EXPECTS}")
printf "[FPM] Check custom INI loaded"
EXPECTS="/etc/php/${PHP_MAJOR}/fpm/conf.d/98-env.ini"
run_fpm_container
CMD=$(run_fcgi_container)
rm_fpm_container
fail_if_0 $(echo "${CMD}" | grep -c "${EXPECTS}")
###
printf "[CLI] Check FPM INI not loaded"
EXPECTS="/etc/php/${PHP_MAJOR}/fpm/conf.d/98-env.ini"
CMD=$(
docker container run --rm \
${CLI} php --ini
)
fail_if_1 $(echo "${CMD}" | grep -c "${EXPECTS}")
printf "[FPM] Check CLI INI not loaded"
EXPECTS="/etc/php/${PHP_MAJOR}/cli/conf.d/98-env.ini"
run_fpm_container
CMD=$(run_fcgi_container)
rm_fpm_container
fail_if_1 $(echo "${CMD}" | grep -c "${EXPECTS}")
###
printf "[CLI] Check custom INI loaded"
EXPECTS="/etc/php/${PHP_MAJOR}/cli/conf.d/99-custom.ini"
CMD=$(
docker container run --rm \
${CLI} php --ini
)
fail_if_0 $(echo "${CMD}" | grep -c "${EXPECTS}")
printf "[FPM] Check custom INI loaded"
EXPECTS="/etc/php/${PHP_MAJOR}/fpm/conf.d/99-custom.ini"
run_fpm_container
CMD=$(run_fcgi_container)
rm_fpm_container
fail_if_0 $(echo "${CMD}" | grep -c "${EXPECTS}")
###
printf "[CLI] Check display_errors set to default value [Off]"
EXPECTS="Off"
CMD=$(
docker container run --rm \
${CLI} php -r "echo ini_get('display_errors');"
)
fail_if_0 $(echo "${CMD}" | grep -c "${EXPECTS}")
printf "[FPM] Check display_errors set to default value [Off]"
EXPECTS="Off"
run_fpm_container
CMD=$(run_fcgi_container display_errors)
rm_fpm_container
fail_if_0 $(echo "${CMD}" | grep -c "${EXPECTS}")
###
printf "[CLI] Check display_errors accepts override value [On]"
EXPECTS="On"
CMD=$(
docker container run --rm \
-e PHP.display_errors=On \
${CLI} php -r "echo ini_get('display_errors');"
)
fail_if_0 $(echo "${CMD}" | grep -c "${EXPECTS}")
printf "[FPM] Check display_errors accepts override value [On]"
EXPECTS="On"
run_fpm_container "PHP.display_errors=On"
CMD=$(run_fcgi_container display_errors)
rm_fpm_container
fail_if_0 $(echo "${CMD}" | grep -c "${EXPECTS}")
###
printf "[CLI] Check Xdebug not loaded by default"
EXPECTS="Xdebug"
CMD=$(
docker container run --rm \
${CLI} php -v
)
fail_if_1 $(echo "${CMD}" | grep -c "${EXPECTS}")
printf "[FPM] Check Xdebug not loaded by default"
EXPECTS="Xdebug"
run_fpm_container
CMD=$(run_fcgi_container)
rm_fpm_container
fail_if_1 $(echo "${CMD}" | grep -c "${EXPECTS}")
###
printf "[CLI] Check Xdebug loaded by env var"
EXPECTS="Xdebug"
CMD=$(
docker container run --rm \
-e PHP_INI_SCAN_DIR=:/p/xdebug \
${CLI} php -v
)
fail_if_0 $(echo "${CMD}" | grep -c "${EXPECTS}")
printf "[FPM] Check Xdebug loaded by env var"
EXPECTS="Xdebug"
run_fpm_container "PHP_INI_SCAN_DIR=:/p/xdebug"
CMD=$(run_fcgi_container)
rm_fpm_container
fail_if_0 $(echo "${CMD}" | grep -c "${EXPECTS}")
###
printf "[CLI] Check Xdebug CLI auto-sets PHP_INI_SCAN_DIR"
EXPECTS="/p/xdebug/xdebug.ini"
CMD=$(
docker container run --rm \
-e PHP_INI_SCAN_DIR=:/p/xdebug \
${CLI} php --ini
)
fail_if_0 $(echo "${CMD}" | grep -c "${EXPECTS}")
rm_fpm_container
rm_test_network