Skip to content

Commit c76dac3

Browse files
committed
added Docker Compose setup for database testing
1 parent 6906f75 commit c76dac3

6 files changed

Lines changed: 91 additions & 132 deletions

File tree

.github/workflows/coding-style.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ jobs:
77
name: Nette Code Checker
88
runs-on: ubuntu-latest
99
steps:
10-
- uses: actions/checkout@v4
10+
- uses: actions/checkout@v6
1111
- uses: shivammathur/setup-php@v2
1212
with:
1313
php-version: 8.3
@@ -21,7 +21,7 @@ jobs:
2121
name: Nette Coding Standard
2222
runs-on: ubuntu-latest
2323
steps:
24-
- uses: actions/checkout@v4
24+
- uses: actions/checkout@v6
2525
- uses: shivammathur/setup-php@v2
2626
with:
2727
php-version: 8.3

.github/workflows/static-analysis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ jobs:
77
name: PHPStan
88
runs-on: ubuntu-latest
99
steps:
10-
- uses: actions/checkout@v4
10+
- uses: actions/checkout@v6
1111
- uses: shivammathur/setup-php@v2
1212
with:
1313
php-version: 8.5

.github/workflows/tests.yml

Lines changed: 5 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -17,113 +17,21 @@ jobs:
1717

1818
name: PHP ${{ matrix.php }} tests
1919

20-
services:
21-
mysql57:
22-
image: mysql:5.7
23-
env:
24-
MYSQL_DATABASE: dibi_test
25-
MYSQL_ROOT_PASSWORD: root
26-
ports:
27-
- 3306:3306
28-
options: >-
29-
--health-cmd "mysqladmin ping -ppass"
30-
--health-interval 10s
31-
--health-start-period 10s
32-
--health-timeout 5s
33-
--health-retries 10
34-
35-
mysql80:
36-
image: mysql:8.0
37-
ports:
38-
- 3307:3306
39-
options: >-
40-
--health-cmd="mysqladmin ping -ppass"
41-
--health-interval=10s
42-
--health-timeout=5s
43-
--health-retries=5
44-
-e MYSQL_ROOT_PASSWORD=root
45-
-e MYSQL_DATABASE=dibi_test
46-
47-
postgres96:
48-
image: postgres:9.6
49-
env:
50-
POSTGRES_USER: postgres
51-
POSTGRES_PASSWORD: postgres
52-
POSTGRES_DB: dibi_test
53-
ports:
54-
- 5432:5432
55-
options: >-
56-
--health-cmd pg_isready
57-
--health-interval 10s
58-
--health-timeout 5s
59-
--health-retries 5
60-
61-
postgres13:
62-
image: postgres:13
63-
env:
64-
POSTGRES_USER: postgres
65-
POSTGRES_PASSWORD: postgres
66-
POSTGRES_DB: dibi_test
67-
ports:
68-
- 5433:5432
69-
options: >-
70-
--health-cmd pg_isready
71-
--health-interval 10s
72-
--health-timeout 5s
73-
--health-retries 5
20+
steps:
21+
- uses: actions/checkout@v6
7422

75-
mssql:
76-
image: mcr.microsoft.com/mssql/server:latest
77-
env:
78-
ACCEPT_EULA: Y
79-
SA_PASSWORD: YourStrong!Passw0rd
80-
MSSQL_PID: Developer
81-
ports:
82-
- 1433:1433
83-
options: >-
84-
--name=mssql
85-
--health-cmd "/opt/mssql-tools18/bin/sqlcmd -S localhost -U SA -P 'YourStrong!Passw0rd' -Q 'SELECT 1' -N -C"
86-
--health-interval 10s
87-
--health-timeout 5s
88-
--health-retries 5
23+
- name: Start database containers
24+
run: docker compose up -d --wait --quiet-pull
8925

90-
steps:
91-
- uses: actions/checkout@v4
9226
- uses: shivammathur/setup-php@v2
9327
with:
9428
php-version: ${{ matrix.php }}
9529
extensions: ${{ env.php-extensions }}
9630
tools: ${{ env.php-tools }}
9731
coverage: none
9832

99-
- name: Install MS ODBC Driver for SQL Server
100-
run: |
101-
set -euxo pipefail
102-
103-
sudo apt-get update
104-
sudo apt-get install -y curl ca-certificates gnupg
105-
106-
# Microsoft apt repo key (non-interactive; fixes "gpg: cannot open /dev/tty")
107-
sudo install -d -m 0755 /etc/apt/keyrings
108-
curl -fsSL https://packages.microsoft.com/keys/microsoft.asc \
109-
| sudo gpg --dearmor --batch --yes --no-tty -o /etc/apt/keyrings/microsoft.gpg
110-
sudo chmod a+r /etc/apt/keyrings/microsoft.gpg
111-
112-
# Microsoft apt repo for current Ubuntu runner
113-
. /etc/os-release
114-
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/microsoft.gpg] https://packages.microsoft.com/ubuntu/${VERSION_ID}/prod ${VERSION_CODENAME} main" \
115-
| sudo tee /etc/apt/sources.list.d/microsoft-prod.list > /dev/null
116-
117-
sudo apt-get update
118-
sudo ACCEPT_EULA=Y apt-get install -y msodbcsql18
119-
120-
# Create DB inside the MSSQL service container
121-
docker exec -i mssql /opt/mssql-tools18/bin/sqlcmd \
122-
-S localhost -U SA -P 'YourStrong!Passw0rd' \
123-
-Q "CREATE DATABASE dibi_test" -N -C
124-
12533
- name: Create databases.ini
126-
run: cp ./tests/databases.github.ini ./tests/databases.ini
34+
run: cp ./tests/databases.docker.ini ./tests/databases.ini
12735

12836
- run: composer install --no-progress --prefer-dist
12937
- run: composer tester -- -p phpdbg --coverage ./coverage.xml --coverage-src ./src

docker-compose.yml

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
services:
2+
mysql:
3+
image: mysql:8.0
4+
ports:
5+
- "3307:3306"
6+
environment:
7+
MYSQL_ROOT_PASSWORD: root
8+
MYSQL_DATABASE: dibi_test
9+
healthcheck:
10+
test: mysqladmin ping -proot
11+
interval: 10s
12+
timeout: 5s
13+
retries: 5
14+
15+
postgres96:
16+
image: postgres:9.6
17+
ports:
18+
- "5433:5432"
19+
environment:
20+
POSTGRES_USER: postgres
21+
POSTGRES_PASSWORD: postgres
22+
POSTGRES_DB: dibi_test
23+
healthcheck:
24+
test: pg_isready
25+
interval: 10s
26+
timeout: 5s
27+
retries: 5
28+
29+
postgres13:
30+
image: postgres:13
31+
ports:
32+
- "5434:5432"
33+
environment:
34+
POSTGRES_USER: postgres
35+
POSTGRES_PASSWORD: postgres
36+
POSTGRES_DB: dibi_test
37+
healthcheck:
38+
test: pg_isready
39+
interval: 10s
40+
timeout: 5s
41+
retries: 5
42+
43+
mssql:
44+
image: mcr.microsoft.com/mssql/server:2022-latest
45+
ports:
46+
- "1434:1433"
47+
environment:
48+
ACCEPT_EULA: "Y"
49+
SA_PASSWORD: "YourStrong!Passw0rd"
50+
MSSQL_PID: Developer
51+
healthcheck:
52+
test: /opt/mssql-tools18/bin/sqlcmd -S localhost -U SA -P 'YourStrong!Passw0rd' -d dibi_test -Q 'SELECT 1' -N -C
53+
interval: 10s
54+
start_period: 30s
55+
timeout: 5s
56+
retries: 5
57+
entrypoint: /bin/bash -c "/opt/mssql/bin/sqlservr & until /opt/mssql-tools18/bin/sqlcmd -S localhost -U SA -P 'YourStrong!Passw0rd' -Q 'SELECT 1' -N -C 2>/dev/null; do sleep 2; done && /opt/mssql-tools18/bin/sqlcmd -S localhost -U SA -P 'YourStrong!Passw0rd' -Q 'CREATE DATABASE dibi_test' -N -C; wait"

readme.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,24 @@ composer require dibi/dibi
3737
The Dibi 5.1 requires PHP version 8.2 and supports PHP up to 8.5.
3838

3939

40+
Running Tests
41+
-------------
42+
43+
Run tests against SQLite (no setup needed):
44+
45+
```
46+
composer run tester
47+
```
48+
49+
To test against MySQL, PostgreSQL, etc., start the Docker containers and copy the configuration:
50+
51+
```
52+
docker compose up -d
53+
cp tests/databases.docker.ini tests/databases.ini
54+
vendor/bin/tester tests -s -c tests/php-win.ini
55+
```
56+
57+
4058
Usage
4159
-----
4260

Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
[sqlite] ; default
1+
[sqlite]
22
driver = sqlite
33
database = :memory:
44
system = sqlite
@@ -8,23 +8,7 @@ driver = pdo
88
dsn = "sqlite::memory:"
99
system = sqlite
1010

11-
[mysql 5.7]
12-
driver = mysqli
13-
host = "127.0.0.1"
14-
database = dibi_test
15-
username = root
16-
password = root
17-
port = 3306
18-
system = mysql
19-
20-
[mysql 5.7pdo]
21-
driver = pdo
22-
dsn = "mysql:host=127.0.0.1;port=3306;dbname=dibi_test"
23-
user = root
24-
password = root
25-
system = mysql
26-
27-
[mysql 8.0]
11+
[mysql]
2812
driver = mysqli
2913
host = "127.0.0.1"
3014
database = dibi_test
@@ -33,7 +17,7 @@ password = root
3317
port = 3307
3418
system = mysql
3519

36-
[mysql 8.0pdo]
20+
[mysql pdo]
3721
driver = pdo
3822
dsn = "mysql:host=127.0.0.1;port=3307;dbname=dibi_test"
3923
user = root
@@ -46,12 +30,12 @@ host = "127.0.0.1"
4630
database = dibi_test
4731
username = postgres
4832
password = postgres
49-
port = 5432
33+
port = 5433
5034
system = postgre
5135

5236
[postgre 9.6pdo]
5337
driver = pdo
54-
dsn = "pgsql:host=127.0.0.1;port=5432;dbname=dibi_test"
38+
dsn = "pgsql:host=127.0.0.1;port=5433;dbname=dibi_test"
5539
user = postgres
5640
password = postgres
5741
system = postgre
@@ -62,28 +46,20 @@ host = "127.0.0.1"
6246
database = dibi_test
6347
username = postgres
6448
password = postgres
65-
port = 5433
49+
port = 5434
6650
system = postgre
6751

6852
[postgre 13pdo]
6953
driver = pdo
70-
dsn = "pgsql:host=127.0.0.1;port=5433;dbname=dibi_test"
54+
dsn = "pgsql:host=127.0.0.1;port=5434;dbname=dibi_test"
7155
user = postgres
7256
password = postgres
7357
system = postgre
7458

7559
[sqlsrv]
7660
driver = sqlsrv
77-
host = "localhost"
61+
host = "localhost,1434"
7862
username = SA
7963
password = "YourStrong!Passw0rd"
8064
database = dibi_test
81-
port = 1433
8265
system = sqlsrv
83-
84-
;[sqlsrv pdo]
85-
;driver = pdo
86-
;dsn = "sqlsrv:Server=localhost,1433;Database=dibi_test"
87-
;user = SA
88-
;password = "YourStrong!Passw0rd"
89-
;system = sqlsrv

0 commit comments

Comments
 (0)