-
Notifications
You must be signed in to change notification settings - Fork 15
/
dev.sh
executable file
·353 lines (314 loc) · 11.4 KB
/
dev.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
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
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
#!/bin/bash
RED='\033[0;31m'
GREEN='\033[0;32m'
NC='\033[0m' # No Color
# PHP version.
PHPVER="8-2"
# Extra parameters passed to all docker command lines.
EXTRA_DOCKER_ENV=""
# Parse arguments.
while getopts ":xp:l" opt; do
case "${opt}" in
x)
EXTRA_DOCKER_ENV="${EXTRA_DOCKER_ENV} -e XDEBUG_TRIGGER=1"
;;
l)
LOWEST=1
;;
p)
p=${OPTARG}
case "${OPTARG}" in
"8.1")
PHPVER="8-1"
;;
"8.3")
PHPVER="8-3"
;;
*)
PHPVER="8-2"
;;
esac
;;
*)
usage
;;
esac
done
shift $((OPTIND-1))
# phpunit container variant to use.
PHPUNIT_CONTAINER="phpunit-${PHPVER}"
section_title() {
printf "${RED}\n-------------------------------- ${NC}"
printf "${RED}$1${NC}"
printf "${RED} --------------------------------\n${NC}"
}
# Run docker compose for project
do_docker_compose() {
docker compose -p db_tools_bundle_test "$@"
}
# Build docker containers
do_build() {
section_title "Rebuilding containers"
do_docker_compose build;
}
# Start docker containers
do_up() {
section_title "Up containers"
do_docker_compose up -d --force-recreate --remove-orphans
}
# Stop docker containers
do_down() {
section_title "Down containers"
do_docker_compose down
}
# Clean all containers, images and volumes
do_clean() {
section_title "Cleanup containers and images"
do_docker_compose down --rmi all --volumes --remove-orphans
}
do_composer_update() {
echo 'composer update'
if [[ -z "${LOWEST}" ]]; then
do_docker_compose exec $PHPUNIT_CONTAINER composer update
else
do_docker_compose exec $PHPUNIT_CONTAINER composer update --prefer-lowest
fi
}
# Launch composer checks (for Static analysis & Code style fixer)
do_checks() {
section_title "Composer checks"
do_composer_update
echo 'composer checks'
do_docker_compose exec $PHPUNIT_CONTAINER composer checks
}
# Launch PHPUnit tests without any database vendor
do_unittest() {
section_title "PHPUnit unit tests"
do_docker_compose exec $PHPUNIT_CONTAINER vendor/bin/phpunit
}
do_ps() {
do_docker_compose ps
}
do_test_mysql57() {
section_title "Running tests with MySQL 5.7"
do_docker_compose exec $EXTRA_DOCKER_ENV \
-e DBAL_DRIVER=pdo_mysql \
-e DBAL_DBNAME=test_db \
-e DBAL_HOST=mysql57 \
-e DBAL_PASSWORD=password \
-e DBAL_PORT=3306 \
-e DBAL_ROOT_PASSWORD=password \
-e DBAL_ROOT_USER="root" \
-e DBAL_USER=root \
-e DATABASE_URL=mysql://root:password@mysql57:3306/test_db?serverVersion=5.7 \
$PHPUNIT_CONTAINER vendor/bin/phpunit "$@"
}
do_test_mysql80() {
section_title "Running tests with MySQL 8.0"
do_docker_compose exec $EXTRA_DOCKER_ENV \
-e DBAL_DRIVER=mysqli \
-e DBAL_DBNAME=test_db \
-e DBAL_HOST=mysql80 \
-e DBAL_PASSWORD=password \
-e DBAL_PORT=3306 \
-e DBAL_ROOT_PASSWORD=password \
-e DBAL_ROOT_USER=root \
-e DBAL_USER=root \
-e DATABASE_URL=mysql://root:password@mysql80:3306/test_db?serverVersion=8 \
"$PHPUNIT_CONTAINER" vendor/bin/phpunit "$@"
}
do_test_mysql83() {
section_title "Running tests with MySQL 8.3"
do_docker_compose exec $EXTRA_DOCKER_ENV \
-e DBAL_DRIVER=pdo_mysql \
-e DBAL_DBNAME=test_db \
-e DBAL_HOST=mysql83 \
-e DBAL_PASSWORD=password \
-e DBAL_PORT=3306 \
-e DBAL_ROOT_PASSWORD=password \
-e DBAL_ROOT_USER=root \
-e DBAL_USER=root \
-e DATABASE_URL=mysql://root:password@mysql83:3306/test_db?serverVersion=8 \
$PHPUNIT_CONTAINER vendor/bin/phpunit "$@"
}
do_test_mariadb11() {
section_title "Running tests with MariaDB 11"
do_docker_compose exec $EXTRA_DOCKER_ENV \
-e DBAL_DRIVER=pdo_mysql \
-e DBAL_DBNAME=test_db \
-e DBAL_HOST=mariadb11 \
-e DBAL_PASSWORD=password \
-e DBAL_PORT=3306 \
-e DBAL_ROOT_PASSWORD="password" \
-e DBAL_ROOT_USER="root" \
-e DBAL_USER=root \
-e DATABASE_URL=mysql://root:password@mariadb11:3306/test_db?serverVersion=mariadb-11.1.3 \
$PHPUNIT_CONTAINER vendor/bin/phpunit "$@"
}
do_test_mysql() {
do_test_mysql57 "$@"
do_test_mysql80 "$@"
do_test_mysql83 "$@"
do_test_mariadb11 "$@"
}
do_test_postgresql10() {
section_title "Running tests with PostgreSQL 10"
do_docker_compose exec $EXTRA_DOCKER_ENV \
-e DBAL_DRIVER=pdo_pgsql \
-e DBAL_DBNAME=test_db \
-e DBAL_HOST=postgresql10 \
-e DBAL_PASSWORD=password \
-e DBAL_PORT=5432 \
-e DBAL_ROOT_PASSWORD=password \
-e DBAL_ROOT_USER=postgres \
-e DBAL_USER=postgres \
-e DATABASE_URL="postgresql://postgres:password@postgresql10:5432/test_db?serverVersion=10&charset=utf8" \
$PHPUNIT_CONTAINER vendor/bin/phpunit "$@"
}
do_test_postgresql16() {
section_title "Running tests with PostgreSQL 16"
do_docker_compose exec $EXTRA_DOCKER_ENV \
-e DBAL_DRIVER=pdo_pgsql \
-e DBAL_DBNAME=test_db \
-e DBAL_HOST=postgresql16 \
-e DBAL_PASSWORD=password \
-e DBAL_PORT=5432 \
-e DBAL_ROOT_PASSWORD=password \
-e DBAL_ROOT_USER=postgres \
-e DBAL_USER=postgres \
-e DATABASE_URL="postgresql://postgres:password@postgresql16:5432/test_db?serverVersion=16&charset=utf8" \
$PHPUNIT_CONTAINER vendor/bin/phpunit "$@"
}
do_test_postgresql() {
do_test_postgresql10 "$@"
do_test_postgresql16 "$@"
}
do_test_sqlsrv2019() {
section_title "Running tests with SQL Server 2019"
do_docker_compose exec $EXTRA_DOCKER_ENV \
-e DBAL_DRIVER=pdo_sqlsrv \
-e DBAL_DBNAME=test_db \
-e DBAL_HOST=sqlsrv2019 \
-e DBAL_PASSWORD=P@ssword123 \
-e DBAL_PORT=1433 \
-e DBAL_ROOT_PASSWORD=P@ssword123 \
-e DBAL_ROOT_USER=sa \
-e DBAL_USER=sa \
-e DATABASE_URL="pdo-sqlsrv://sa:P%40ssword123@sqlsrv2019:1433/test_db?serverVersion=2019&charset=utf8&driverOptions[TrustServerCertificate]=true" \
$PHPUNIT_CONTAINER vendor/bin/phpunit "$@"
}
do_test_sqlsrv2022() {
section_title "Running tests with SQL Server 2022"
do_docker_compose exec $EXTRA_DOCKER_ENV \
-e DBAL_DRIVER=pdo_sqlsrv \
-e DBAL_DBNAME=test_db \
-e DBAL_HOST=sqlsrv2022 \
-e DBAL_PASSWORD=P@ssword123 \
-e DBAL_PORT=1433 \
-e DBAL_ROOT_PASSWORD=P@ssword123 \
-e DBAL_ROOT_USER=sa \
-e DBAL_USER=sa \
-e DATABASE_URL="pdo-sqlsrv://sa:P%40ssword123@sqlsrv2022:1433/test_db?serverVersion=2022&charset=utf8&driverOptions[TrustServerCertificate]=true" \
$PHPUNIT_CONTAINER vendor/bin/phpunit "$@"
}
do_test_sqlsrv() {
do_test_sqlsrv2019 "$@"
do_test_sqlsrv2022 "$@"
}
# SQLite version depends upon the PHP embeded version or linked
# library, we cannot target X or Y version.
do_test_sqlite() {
section_title "Running tests with SQLite"
do_docker_compose exec $EXTRA_DOCKER_ENV \
-e DBAL_DRIVER=pdo_sqlite \
-e DBAL_DBNAME=test_db \
-e DBAL_HOST=127.0.0.1 \
-e DBAL_PATH="test_db.sqlite" \
-e DATABASE_URL="pdo-sqlite:///test_db.sqlite" \
$PHPUNIT_CONTAINER vendor/bin/phpunit "$@"
}
# Run PHPunit tests for all database vendors
do_test_all() {
do_composer_update
do_test_mysql57 "$@"
do_test_mysql80 "$@"
do_test_mysql83 "$@"
do_test_mariadb11 "$@"
do_test_postgresql10 "$@"
do_test_postgresql16 "$@"
do_test_sqlsrv2019 "$@"
do_test_sqlsrv2022 "$@"
do_test_sqlite "$@"
}
do_test_notice() {
section_title "Test a specicif database vendor or version"
printf "\nThis action will allow you to test a specific vendor or version."
printf "\n"
printf "\nLaunch this action with one of these available options:"
printf "\n"
printf "\n - ${GREEN}mysql${NC}: Launch test for MySQL 5.7, 8.0, 8.3 & MariaDB 11"
printf "\n - ${GREEN}mysql57${NC}: Launch test for MySQL 5.7"
printf "\n - ${GREEN}mysql80${NC}: Launch test for MySQL 8.0"
printf "\n - ${GREEN}mysql83${NC}: Launch test for MySQL 8.3"
printf "\n - ${GREEN}mariadb11${NC}: Launch test for MariaDB 11"
printf "\n - ${GREEN}postgresql${NC}: Launch test for PostgreSQL 10 & 16"
printf "\n - ${GREEN}postgresql10${NC}: Launch test for PostgreSQL 10"
printf "\n - ${GREEN}postgresql16${NC}: Launch test for PostgreSQL 16"
printf "\n - ${GREEN}sqlsrv${NC}: Launch test for SQL Server 2019 & 2022"
printf "\n - ${GREEN}sqlsrv2019${NC}: Launch test for SQL Server 2019"
printf "\n - ${GREEN}sqlsrv2022${NC}: Launch test for SQL Server 2022"
printf "\n - ${GREEN}sqlite${NC}: Launch test for SQLite"
printf "\n\nYou can then use PHPUnit option as usual:"
printf "\n${GREEN}./dev.sh test mysql --filter AnonymizatorFactoryTest${NC}"
printf "\n\n"
}
do_test() {
suit=${1-}
if [[ -n $@ ]];then shift;fi
case $suit in
mysql57|mysql80|mysql83|mariadb11|mysql|postgresql10|postgresql16|postgresql|sqlsrv2019|sqlsrv2022|sqlsrv|sqlite) do_composer_update && do_test_$suit "$@";;
*) do_test_notice;;
esac
}
# Display help
do_notice() {
section_title "DbToolsTest dev scripts"
printf "\nWelcome to DbToolsBundle dev script !"
printf "\n"
printf "\nThis script will help you to contribute to the DbToolsBundle."
printf "\n"
printf "\nIt will allow you to :"
printf "\n"
printf "\n - build, up and down a complete docker stack with all database vendors"
printf "\n and versions that the DbToolsBundle supports"
printf "\n - run Code Style Fixer (with PHP CS Fixer) and launch Static Analysis (with PHPStan)"
printf "\n - run PHPUnit tests for all database vendors"
printf "\n\n--\n"
printf "\nLaunch the script with one of these available actions:"
printf "\n"
printf "\n - ${GREEN}build${NC}: Build docker containers"
printf "\n - ${GREEN}up${NC}: Start docker containers"
printf "\n - ${GREEN}down${NC}: Stop docker containers"
printf "\n - ${GREEN}checks${NC}: Launch composer checks (for Static analysis & Code style fixer)"
printf "\n - ${GREEN}test_all${NC}: Run PHPUnit tests for all database vendors."
printf "\n PHPUnit options can be used as usual:"
printf "\n ${GREEN}./dev.sh test_all --filter AnonymizatorFactoryTest${NC}"
printf "\n - ${GREEN}test${NC}: Run PHPUnit tests for a specific database vendors or version"
printf "\n - ${GREEN}unittest${NC}: Run PHPUnit tests without any database vendor"
printf "\n - ${GREEN}clean${NC}: Cleanup containers and images"
printf "\n - ${GREEN}notice${NC}: Display this help"
printf "\n"
printf "\nAvailable options:"
printf "\n ${GREEN}-l${NC}: run ${GREEN}composer update${NC} with ${GREEN}--prefer-lowest${NC} option"
printf "\n ${GREEN}-x${NC}: trigger ${GREEN}xdebug${NC} when running test suites (ignored otherwise)"
printf "\n ${GREEN}-p 8.3${NC}: choose PHP version to run, ${GREEN}8.2${NC} or ${GREEN}8.3${NC}"
printf "\n"
printf "\n\n"
}
args=${@:-usage}
action=${1-}
if [[ -n $@ ]];then shift;fi
case $action in
build|up|down|ps|checks|test_all|unittest|test|composer_update|notice|clean) do_$action "$@";;
*) do_notice;;
esac