Skip to content

Commit 52caae0

Browse files
committed
new dev.sh script for running tests, deprecates run-tests.sh, minor bug fix in modulo expression
1 parent e2a5bff commit 52caae0

File tree

5 files changed

+353
-41
lines changed

5 files changed

+353
-41
lines changed

dev.sh

+252
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,252 @@
1+
#!/bin/bash
2+
3+
RED='\033[0;31m'
4+
GREEN='\033[0;32m'
5+
NC='\033[0m' # No Color
6+
7+
section_title() {
8+
printf "${RED}\n-------------------------------- ${NC}"
9+
printf "${RED}$1${NC}"
10+
printf "${RED} --------------------------------\n${NC}"
11+
}
12+
13+
# Build docker containers
14+
do_build() {
15+
section_title "Rebuilding containers"
16+
docker compose -p query_builder_test build;
17+
}
18+
19+
# Start docker containers
20+
do_up() {
21+
section_title "Up containers"
22+
docker compose -p query_builder_test up -d --force-recreate --remove-orphans
23+
}
24+
25+
# Stop docker containers
26+
do_down() {
27+
section_title "Down containers"
28+
docker compose -p query_builder_test down
29+
}
30+
31+
do_composer_install() {
32+
echo 'composer install'
33+
docker compose -p query_builder_test exec phpunit composer install
34+
}
35+
36+
# Launch composer checks (for Static analysis & Code style fixer)
37+
do_checks() {
38+
section_title "Composer checks"
39+
40+
do_composer_install
41+
42+
echo 'composer checks'
43+
docker compose -p query_builder_test exec phpunit composer checks
44+
}
45+
46+
# Launch PHPUnit tests without any database vendor
47+
do_unittest() {
48+
section_title "PHPUnit unit tests"
49+
docker compose -p query_builder_test exec phpunit vendor/bin/phpunit
50+
}
51+
52+
do_test_mysql57() {
53+
section_title "Running tests with MySQL 5.7"
54+
docker compose -p query_builder_test exec \
55+
-e DBAL_DRIVER=pdo_mysql \
56+
-e DBAL_DBNAME=test_db \
57+
-e DBAL_HOST=mysql57 \
58+
-e DBAL_PASSWORD=password \
59+
-e DBAL_PORT=3306 \
60+
-e DBAL_ROOT_PASSWORD=password \
61+
-e DBAL_ROOT_USER="root" \
62+
-e DBAL_USER=root \
63+
-e DATABASE_URL=mysql://root:password@mysql57:3306/test_db?serverVersion=5.7 \
64+
phpunit vendor/bin/phpunit $@
65+
}
66+
67+
do_test_mysql80() {
68+
section_title "Running tests with MySQL 8"
69+
docker compose -p query_builder_test exec \
70+
-e DBAL_DRIVER=pdo_mysql \
71+
-e DBAL_DBNAME=test_db \
72+
-e DBAL_HOST=mysql80 \
73+
-e DBAL_PASSWORD=password \
74+
-e DBAL_PORT=3306 \
75+
-e DBAL_ROOT_PASSWORD=password \
76+
-e DBAL_ROOT_USER=root \
77+
-e DBAL_USER=root \
78+
-e DATABASE_URL=mysql://root:password@mysql80:3306/test_db?serverVersion=8 \
79+
phpunit vendor/bin/phpunit $@
80+
}
81+
82+
do_test_mariadb11() {
83+
section_title "Running tests with MariaDB 11"
84+
docker compose -p query_builder_test exec \
85+
-e DBAL_DRIVER=pdo_mysql \
86+
-e DBAL_DBNAME=test_db \
87+
-e DBAL_HOST=mariadb11 \
88+
-e DBAL_PASSWORD=password \
89+
-e DBAL_PORT=3306 \
90+
-e DBAL_ROOT_PASSWORD="password" \
91+
-e DBAL_ROOT_USER="root" \
92+
-e DBAL_USER=root \
93+
-e DATABASE_URL=mysql://root:password@mariadb11:3306/test_db?serverVersion=11.1.3-MariaDB \
94+
phpunit vendor/bin/phpunit $@
95+
}
96+
97+
do_test_mysql() {
98+
do_test_mysql57
99+
do_test_mysql80
100+
do_test_mariadb11
101+
}
102+
103+
do_test_postgresql10() {
104+
section_title "Running tests with PostgreSQL 10"
105+
docker compose -p query_builder_test exec \
106+
-e DBAL_DRIVER=pdo_pgsql \
107+
-e DBAL_DBNAME=test_db \
108+
-e DBAL_HOST=postgresql10 \
109+
-e DBAL_PASSWORD=password \
110+
-e DBAL_PORT=5432 \
111+
-e DBAL_ROOT_PASSWORD=password \
112+
-e DBAL_ROOT_USER=postgres \
113+
-e DBAL_USER=postgres \
114+
-e DATABASE_URL="postgresql://postgres:password@postgresql10:5432/test_db?serverVersion=10&charset=utf8" \
115+
phpunit vendor/bin/phpunit $@
116+
}
117+
118+
do_test_postgresql16() {
119+
section_title "Running tests with PostgreSQL 16"
120+
docker compose -p query_builder_test exec \
121+
-e DBAL_DRIVER=pdo_pgsql \
122+
-e DBAL_DBNAME=test_db \
123+
-e DBAL_HOST=postgresql16 \
124+
-e DBAL_PASSWORD=password \
125+
-e DBAL_PORT=5432 \
126+
-e DBAL_ROOT_PASSWORD=password \
127+
-e DBAL_ROOT_USER=postgres \
128+
-e DBAL_USER=postgres \
129+
-e DATABASE_URL="postgresql://postgres:password@postgresql16:5432/test_db?serverVersion=16&charset=utf8" \
130+
phpunit vendor/bin/phpunit $@
131+
}
132+
133+
do_test_postgresql() {
134+
do_test_postgresql10
135+
do_test_postgresql16
136+
}
137+
138+
do_test_sqlsrv2019() {
139+
section_title "Running tests with SQL Server 2019"
140+
docker compose -p query_builder_test exec \
141+
-e DBAL_DRIVER=pdo_sqlsrv \
142+
-e DBAL_DBNAME=test_db \
143+
-e DBAL_HOST=sqlsrv2019 \
144+
-e DBAL_PASSWORD=P@ssword123 \
145+
-e DBAL_PORT=1433 \
146+
-e DBAL_ROOT_PASSWORD=P@ssword123 \
147+
-e DBAL_ROOT_USER=sa \
148+
-e DBAL_USER=sa \
149+
-e DATABASE_URL="pdo-sqlsrv://sa:P%40ssword123@sqlsrv2019:1433/test_db?serverVersion=2019&charset=utf8&driverOptions[TrustServerCertificate]=true" \
150+
phpunit vendor/bin/phpunit $@
151+
}
152+
153+
do_test_sqlsrv() {
154+
do_test_sqlsrv2019
155+
}
156+
157+
# SQLite version depends upon the PHP embeded version or linked
158+
# library, we cannot target X or Y version.
159+
do_test_sqlite() {
160+
section_title "Running tests with SQLite"
161+
docker compose -p query_builder_test exec \
162+
-e DBAL_DRIVER=pdo_sqlite \
163+
-e DBAL_DBNAME=test_db \
164+
-e DBAL_HOST=127.0.0.1 \
165+
-e DATABASE_URL="pdo-sqlite:///:memory:" \
166+
phpunit vendor/bin/phpunit $@
167+
}
168+
169+
# Run PHPunit tests for all database vendors
170+
do_test_all() {
171+
do_composer_install
172+
173+
do_test_mysql57
174+
do_test_mysql80
175+
do_test_mariadb11
176+
do_test_postgresql10
177+
do_test_postgresql16
178+
do_test_sqlsrv2019
179+
do_test_sqlite
180+
}
181+
182+
do_test_notice() {
183+
section_title "Test a specicif database vendor or version"
184+
printf "\nThis action will allow you to test a specific vendor or version."
185+
printf "\n"
186+
printf "\nLaunch this action with one of these available options:"
187+
printf "\n"
188+
printf "\n - ${GREEN}mysql${NC}: Launch test for MySQL 5.7, MySQL 8.0 & MariaDB 11"
189+
printf "\n - ${GREEN}mysql57${NC}: Launch test for MySQL 5.7"
190+
printf "\n - ${GREEN}mysql80${NC}: Launch test for MySQL 8.0"
191+
printf "\n - ${GREEN}mariadb11${NC}: Launch test for MariaDB 11"
192+
printf "\n - ${GREEN}postgresql${NC}: Launch test for PostgreSQL 10 & 16"
193+
printf "\n - ${GREEN}postgresql10${NC}: Launch test for PostgreSQL 10"
194+
printf "\n - ${GREEN}postgresql16${NC}: Launch test for PostgreSQL 16"
195+
printf "\n - ${GREEN}sqlsrv${NC}: Launch test for SQL Server 2019"
196+
printf "\n - ${GREEN}sqlsrv2019${NC}: Launch test for SQL Server 2019"
197+
printf "\n - ${GREEN}sqlite${NC}: Launch test for SQLite"
198+
printf "\n\nYou can then use PHPUnit option as usual:"
199+
printf "\n${GREEN}./dev.sh test mysql --filter AnonymizatorFactoryTest${NC}"
200+
printf "\n\n"
201+
}
202+
203+
do_test() {
204+
suit=${1-}
205+
206+
if [[ -n $@ ]];then shift;fi
207+
208+
case $suit in
209+
mysql57|mysql80|mariadb11|mysql|postgresql10|postgresql16|postgresql|sqlsrv2019|sqlsrv|sqlite) do_composer_install && do_test_$suit "$@";;
210+
*) do_test_notice;;
211+
esac
212+
}
213+
214+
# Display help
215+
do_notice() {
216+
section_title "QueryBuilder dev scripts"
217+
218+
printf "\nWelcome to QueryBuilder dev script !"
219+
printf "\n"
220+
printf "\nThis script will help you to contribute to the QueryBuilder."
221+
printf "\n"
222+
printf "\nIt will allow you to :"
223+
printf "\n"
224+
printf "\n - build, up and down a complete docker stack with all database vendors"
225+
printf "\n and versions that the QueryBuilder supports"
226+
printf "\n - run Code Style Fixer (with PHP CS Fixer) and launch Static Analysis (with PHPStan)"
227+
printf "\n - run PHPUnit tests for all database vendors"
228+
printf "\n\n--\n"
229+
printf "\nLaunch the script with one of these available actions:"
230+
printf "\n"
231+
printf "\n - ${GREEN}build${NC}: Build docker containers"
232+
printf "\n - ${GREEN}up${NC}: Start docker containers"
233+
printf "\n - ${GREEN}down${NC}: Stop docker containers"
234+
printf "\n - ${GREEN}checks${NC}: Launch composer checks (for Static analysis & Code style fixer)"
235+
printf "\n - ${GREEN}test_all${NC}: Run PHPUnit tests for all database vendors."
236+
printf "\n PHPUnit options can be used as usual:"
237+
printf "\n ${GREEN}./dev.sh test_all --filter FunctionalTest${NC}"
238+
printf "\n - ${GREEN}test${NC}: Run PHPUnit tests for a specific database vendors or version"
239+
printf "\n - ${GREEN}unittest${NC}: Run PHPUnit tests without any database vendor"
240+
printf "\n - ${GREEN}notice${NC}: Display this help"
241+
printf "\n\n"
242+
}
243+
244+
args=${@:-usage}
245+
action=${1-}
246+
247+
if [[ -n $@ ]];then shift;fi
248+
249+
case $action in
250+
build|up|down|checks|test_all|unittest|test|notice) do_$action "$@";;
251+
*) do_notice;;
252+
esac

docker-compose.yaml

+33-12
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,59 @@
11
version: '3.8'
22
services:
3+
phpunit:
4+
build: ./docker/php
5+
networks:
6+
- query-builder-test
7+
volumes:
8+
- ./:/var/www
39
mysql57:
410
image: mysql:5.7
5-
restart: unless-stopped
11+
restart: 'no'
612
environment:
713
MYSQL_DATABASE: test_db
814
MYSQL_ROOT_PASSWORD: password
915
ports:
10-
- 9001:3306
16+
- 9601:3306
17+
networks:
18+
- query-builder-test
1119
mysql80:
1220
image: mysql:8
13-
restart: unless-stopped
21+
restart: 'no'
1422
environment:
1523
MYSQL_DATABASE: test_db
1624
MYSQL_ROOT_PASSWORD: password
1725
ports:
18-
- 9002:3306
26+
- 9602:3306
27+
networks:
28+
- query-builder-test
1929
mariadb11:
20-
image: mariadb:11
21-
restart: unless-stopped
30+
image: mariadb:11.1.3
31+
restart: 'no'
2232
environment:
2333
MYSQL_DATABASE: test_db
2434
MARIADB_ROOT_PASSWORD: password
2535
ports:
26-
- 9003:3306
36+
- 9603:3306
37+
networks:
38+
- query-builder-test
2739
postgresql10:
2840
image: postgres:10
29-
restart: unless-stopped
41+
restart: 'no'
3042
environment:
3143
POSTGRES_PASSWORD: password
3244
ports:
33-
- 9004:5432
45+
- 9604:5432
46+
networks:
47+
- query-builder-test
3448
postgresql16:
3549
image: postgres:16
36-
restart: unless-stopped
50+
restart: 'no'
3751
environment:
3852
POSTGRES_PASSWORD: password
3953
ports:
40-
- 9005:5432
54+
- 9605:5432
55+
networks:
56+
- query-builder-test
4157
sqlsrv2019:
4258
image: mcr.microsoft.com/mssql/server:2019-latest
4359
restart: unless-stopped
@@ -47,4 +63,9 @@ services:
4763
MSSQL_SA_PASSWORD: P@ssword123
4864
SA_PASSWORD: P@ssword123
4965
ports:
50-
- 9007:1433
66+
- 9606:1433
67+
networks:
68+
- query-builder-test
69+
70+
networks:
71+
query-builder-test:

docker/php/Dockerfile

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
FROM php:8.1-fpm-bookworm
2+
3+
# Basic requirements
4+
RUN apt-get update
5+
RUN apt-get install -yqq --no-install-recommends default-mysql-client acl iproute2 zip zlib1g-dev libzip-dev \
6+
libxml2-dev libpng-dev libghc-curl-dev libldb-dev libldap2-dev gnupg2 libpq-dev
7+
8+
# Instaling postgresql-client-16
9+
RUN curl -fsSL https://www.postgresql.org/media/keys/ACCC4CF8.asc| gpg --dearmor -o /etc/apt/trusted.gpg.d/postgresql.gpg && \
10+
sh -c 'echo "deb https://apt.postgresql.org/pub/repos/apt bookworm-pgdg main" > /etc/apt/sources.list.d/pgdg.list' && \
11+
apt-get update && apt-get install -y postgresql-16
12+
13+
# PHP required extensions
14+
RUN docker-php-ext-configure pgsql -with-pgsql=/usr/local/pgsql
15+
RUN docker-php-ext-install -j$(nproc) pgsql pdo_pgsql pdo mysqli pdo_mysql zip xml gd curl bcmath
16+
RUN docker-php-ext-enable pdo_pgsql pdo_mysql sodium
17+
18+
# SQL Server support
19+
ENV ACCEPT_EULA=Y
20+
RUN curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add -
21+
RUN curl https://packages.microsoft.com/config/ubuntu/20.04/prod.list > /etc/apt/sources.list.d/mssql-release.list
22+
RUN apt-get update
23+
RUN apt-get -y --no-install-recommends install msodbcsql18 unixodbc-dev
24+
RUN pecl install sqlsrv
25+
RUN pecl install pdo_sqlsrv
26+
RUN docker-php-ext-enable sqlsrv pdo_sqlsrv
27+
28+
# Cleanup.
29+
RUN apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
30+
31+
COPY --from=composer /usr/bin/composer /usr/bin/composer
32+
33+
WORKDIR /var/www

0 commit comments

Comments
 (0)