Skip to content

Commit b2f45c7

Browse files
committed
added Docker Compose setup for database testing
1 parent abe0d80 commit b2f45c7

4 files changed

Lines changed: 89 additions & 85 deletions

File tree

.github/workflows/tests.yml

Lines changed: 11 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -17,78 +17,18 @@ jobs:
1717

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

20-
services:
21-
mysql57:
22-
image: mysql:5.7
23-
env:
24-
MYSQL_DATABASE: nette_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=nette_test
46-
47-
postgres96:
48-
image: postgres:9.6
49-
env:
50-
POSTGRES_USER: postgres
51-
POSTGRES_PASSWORD: postgres
52-
POSTGRES_DB: nette_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
20+
steps:
21+
- uses: actions/checkout@v6
6022

61-
postgres13:
62-
image: postgres:13
63-
env:
64-
POSTGRES_USER: postgres
65-
POSTGRES_PASSWORD: postgres
66-
POSTGRES_DB: nette_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
23+
- name: Start database containers
24+
run: docker compose up -d --wait --quiet-pull
7425

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
26+
- name: Create MS SQL Database
27+
run: |
28+
docker compose exec -T mssql /opt/mssql-tools18/bin/sqlcmd \
29+
-S localhost -U SA -P 'YourStrong!Passw0rd' \
30+
-Q 'CREATE DATABASE nette_test' -N -C
8931
90-
steps:
91-
- uses: actions/checkout@v4
9232
- uses: shivammathur/setup-php@v2
9333
with:
9434
php-version: ${{ matrix.php }}
@@ -97,10 +37,7 @@ jobs:
9737
coverage: none
9838

9939
- name: Create databases.ini
100-
run: cp ./tests/databases.github.ini ./tests/Database/databases.ini
101-
102-
- name: Create MS SQL Database
103-
run: docker exec -i mssql /opt/mssql-tools18/bin/sqlcmd -S localhost -U SA -P 'YourStrong!Passw0rd' -Q 'CREATE DATABASE nette_test' -N -C
40+
run: cp ./tests/databases.docker.ini ./tests/Database/databases.ini
10441

10542
- run: composer install --no-progress --prefer-dist
10643
- run: composer tester
@@ -115,7 +52,7 @@ jobs:
11552
name: Lowest Dependencies
11653
runs-on: ubuntu-latest
11754
steps:
118-
- uses: actions/checkout@v4
55+
- uses: actions/checkout@v6
11956
- uses: shivammathur/setup-php@v2
12057
with:
12158
php-version: 8.1

docker-compose.yml

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
services:
2+
mysql:
3+
image: mysql:8.0
4+
ports:
5+
- "3307:3306"
6+
environment:
7+
MYSQL_ROOT_PASSWORD: root
8+
MYSQL_DATABASE: nette_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: nette_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: nette_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' -Q 'SELECT 1' -N -C
53+
interval: 10s
54+
start_period: 30s
55+
timeout: 5s
56+
retries: 5

readme.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,24 @@ composer require nette/database
4343
It requires PHP version 8.1 and supports PHP up to 8.5.
4444

4545

46+
Running Tests
47+
-------------
48+
49+
Run tests against SQLite (no setup needed):
50+
51+
```
52+
composer run tester
53+
```
54+
55+
To test against MySQL, PostgreSQL, etc., start the Docker containers and copy the configuration:
56+
57+
```
58+
docker compose up -d
59+
cp tests/databases.docker.ini tests/Database/databases.ini
60+
composer run tester
61+
```
62+
63+
4664
Usage
4765
-----
4866

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,24 @@
1-
[mysql 5.7]
2-
dsn = "mysql:host=127.0.0.1;port=3306;dbname=nette_test"
3-
username = root
4-
password = root
5-
options[convertBoolean] = yes
6-
options[newDateTime] = yes
7-
8-
[mysql 8.0]
1+
[mysql]
92
dsn = "mysql:host=127.0.0.1;port=3307;dbname=nette_test"
103
username = root
114
password = root
125
options[convertBoolean] = yes
136
options[newDateTime] = yes
147

158
[postgresql 9.6]
16-
dsn = "pgsql:host=127.0.0.1;port=5432;dbname=nette_test"
9+
dsn = "pgsql:host=127.0.0.1;port=5433;dbname=nette_test"
1710
username = postgres
1811
password = postgres
1912
options[newDateTime] = yes
2013

2114
[postgresql 13]
22-
dsn = "pgsql:host=127.0.0.1;port=5433;dbname=nette_test"
15+
dsn = "pgsql:host=127.0.0.1;port=5434;dbname=nette_test"
2316
username = postgres
2417
password = postgres
2518
options[newDateTime] = yes
2619

2720
[sqlsrv]
28-
dsn = "sqlsrv:Server=localhost,1433;Database=nette_test"
21+
dsn = "sqlsrv:Server=localhost,1434;Database=nette_test"
2922
username = SA
3023
password = "YourStrong!Passw0rd"
3124
options[newDateTime] = yes

0 commit comments

Comments
 (0)