Skip to content

Commit 2e0a1e0

Browse files
ci: run integration tests for the data types against a real PostgreSQL instance (#360)
1 parent 18ec906 commit 2e0a1e0

File tree

150 files changed

+838
-145
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

150 files changed

+838
-145
lines changed

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@
66
.gitattributes export-ignore
77
.gitignore export-ignore
88
.scrutinizer.yml export-ignore
9+
docker-compose.yml export-ignore
910
README.md export-ignore

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,8 @@ jobs:
112112
- name: Check for security vulnerabilities in 3rd party dependencies
113113
run: composer audit
114114

115-
- name: Run test suite
116-
run: composer run-tests-with-clover
115+
- name: Run unit test suite
116+
run: composer run-unit-tests-with-clover
117117

118118
- name: Upload coverage results to Coveralls
119119
if: matrix.calculate-code-coverage == true
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
name: Integrations
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
paths-ignore:
8+
- '.github/actions/release-please/**'
9+
pull_request:
10+
branches:
11+
- main
12+
13+
permissions:
14+
contents: read
15+
16+
jobs:
17+
should-run:
18+
runs-on: ubuntu-latest
19+
outputs:
20+
run: ${{ steps.check.outputs.run }}
21+
steps:
22+
- name: Skip for release-please
23+
id: check
24+
run: |
25+
if [ "${{ github.event.pull_request.user.id }}" = "41898282" ]; then
26+
echo "run=false" >> $GITHUB_OUTPUT
27+
echo "::notice::Skipping integration tests - this a release-please bot's interaction"
28+
else
29+
echo "run=true" >> $GITHUB_OUTPUT
30+
echo "::notice::integration tests will execute - the actor is not the release-please bot"
31+
fi
32+
33+
integration-tests:
34+
needs: should-run
35+
if: needs.should-run.outputs.run == 'true'
36+
runs-on: ubuntu-latest
37+
name: "PostgreSQL ${{ matrix.postgres }} + PHP ${{ matrix.php }}"
38+
39+
strategy:
40+
fail-fast: false
41+
matrix:
42+
php: ['8.1', '8.2', '8.3', '8.4']
43+
postgres: ['16', '17']
44+
45+
services:
46+
postgres:
47+
image: postgres:${{ matrix.postgres }}
48+
env:
49+
POSTGRES_PASSWORD: postgres
50+
POSTGRES_USER: postgres
51+
POSTGRES_DB: postgres_doctrine_test
52+
ports:
53+
- 5432:5432
54+
options: >-
55+
--health-cmd pg_isready
56+
--health-interval 10s
57+
--health-timeout 5s
58+
--health-retries 5
59+
--mount type=tmpfs,destination=/var/lib/postgresql/data
60+
-e POSTGRES_INITDB_ARGS="--data-checksums"
61+
62+
steps:
63+
- uses: actions/checkout@v4
64+
65+
- name: Set up PHP
66+
uses: shivammathur/setup-php@v2
67+
with:
68+
php-version: ${{ matrix.php }}
69+
coverage: xdebug
70+
extensions: ctype, json, mbstring, pdo_pgsql
71+
tools: composer
72+
73+
- name: Validate composer.json and composer.lock
74+
run: composer validate --strict
75+
76+
- name: Cache Composer packages
77+
id: composer-cache
78+
uses: actions/cache@v4
79+
with:
80+
path: vendor
81+
key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}
82+
restore-keys: |
83+
${{ runner.os }}-php-
84+
85+
- name: Install dependencies
86+
run: composer install --prefer-dist --no-interaction --no-progress
87+
88+
- name: Install PostgreSQL client tools
89+
run: |
90+
sudo apt-get update
91+
sudo apt-get install -y postgresql-client
92+
93+
- name: Verify PostgreSQL connection and setup
94+
run: |
95+
echo "Checking PostgreSQL version:"
96+
PGPASSWORD=postgres psql -h localhost -U postgres -d postgres_doctrine_test -c "SELECT version();"
97+
98+
echo "\nChecking PostgreSQL configuration:"
99+
PGPASSWORD=postgres psql -h localhost -U postgres -d postgres_doctrine_test -c "SHOW server_version;"
100+
PGPASSWORD=postgres psql -h localhost -U postgres -d postgres_doctrine_test -c "SHOW max_connections;"
101+
PGPASSWORD=postgres psql -h localhost -U postgres -d postgres_doctrine_test -c "SHOW shared_buffers;"
102+
103+
echo "\nCreating test schema:"
104+
PGPASSWORD=postgres psql -h localhost -U postgres -d postgres_doctrine_test -c "CREATE SCHEMA IF NOT EXISTS test;"
105+
106+
echo "\nListing available PostgreSQL extensions:"
107+
PGPASSWORD=postgres psql -h localhost -U postgres -d postgres_doctrine_test -c "SELECT * FROM pg_available_extensions;"
108+
109+
- name: Run integration test suite
110+
run: composer run-integration-tests
111+
env:
112+
POSTGRES_HOST: localhost
113+
POSTGRES_PORT: 5432
114+
POSTGRES_DB: postgres_doctrine_test
115+
POSTGRES_USER: postgres
116+
POSTGRES_PASSWORD: postgres

README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,29 @@ composer require martin-georgiev/postgresql-for-doctrine
9898
## 💡 Usage Examples
9999
See our [Common Use Cases and Examples](docs/USE-CASES-AND-EXAMPLES.md) for detailed code samples.
100100

101+
## 🧪 Testing
102+
103+
### Unit Tests
104+
```bash
105+
composer run-unit-tests
106+
```
107+
108+
### PostgreSQL Integration Tests
109+
We also provide integration tests that run against a real PostgreSQL database to ensure compatibility:
110+
111+
```bash
112+
# Start PostgreSQL using Docker Compose
113+
docker-compose up -d
114+
115+
# Run integration tests
116+
composer run-integration-tests
117+
118+
# Stop PostgreSQL
119+
docker-compose down -v
120+
```
121+
122+
See [tests-integration/README.md](tests-integration/README.md) for more details.
123+
101124
## ⭐ Support the Project
102125

103126
### 💖 GitHub Sponsors

ci/phpunit/config-integration.xml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
colors="true"
4+
stopOnFailure="false"
5+
bootstrap="../../tests/Integration/bootstrap.php"
6+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd"
7+
cacheDirectory="../../var/cache/phpunit/"
8+
executionOrder="random"
9+
failOnRisky="true"
10+
failOnWarning="true"
11+
beStrictAboutOutputDuringTests="true"
12+
displayDetailsOnTestsThatTriggerDeprecations="true"
13+
displayDetailsOnTestsThatTriggerErrors="true"
14+
displayDetailsOnTestsThatTriggerNotices="true"
15+
displayDetailsOnTestsThatTriggerWarnings="true"
16+
displayDetailsOnPhpunitDeprecations="true">
17+
<testsuites>
18+
<testsuite name="PostgreSQL-for-Doctrine Integration Test Suite">
19+
<directory>../../tests/Integration</directory>
20+
</testsuite>
21+
</testsuites>
22+
<source>
23+
<include>
24+
<directory suffix=".php">../../src</directory>
25+
</include>
26+
</source>
27+
<php>
28+
<env name="POSTGRES_HOST" value="localhost"/>
29+
<env name="POSTGRES_PORT" value="5432"/>
30+
<env name="POSTGRES_DB" value="postgres_doctrine_test"/>
31+
<env name="POSTGRES_USER" value="postgres"/>
32+
<env name="POSTGRES_PASSWORD" value="postgres"/>
33+
</php>
34+
</phpunit>

ci/phpunit/config.xml renamed to ci/phpunit/config-unit.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
displayDetailsOnTestsThatTriggerWarnings="true"
1616
displayDetailsOnPhpunitDeprecations="true">
1717
<testsuites>
18-
<testsuite name="PostgreSQL-for-Doctrine Test Suite">
19-
<directory>../../tests</directory>
18+
<testsuite name="PostgreSQL-for-Doctrine Unit Test Suite">
19+
<directory>../../tests/Unit</directory>
2020
</testsuite>
2121
</testsuites>
2222
<coverage>

composer.json

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@
3131
"autoload-dev": {
3232
"psr-4": {
3333
"Fixtures\\MartinGeorgiev\\": "fixtures/MartinGeorgiev/",
34-
"Tests\\MartinGeorgiev\\": "tests/MartinGeorgiev/"
34+
"Tests\\Integration\\MartinGeorgiev\\": "tests/Integration/MartinGeorgiev/",
35+
"Tests\\Unit\\MartinGeorgiev\\": "tests/Unit/MartinGeorgiev/"
3536
}
3637
},
3738

@@ -71,7 +72,13 @@
7172
"phpstan analyse --configuration=./ci/phpstan/config.neon"
7273
],
7374
"phpunit": [
74-
"XDEBUG_MODE=coverage phpunit --configuration=./ci/phpunit/config.xml"
75+
"XDEBUG_MODE=coverage phpunit"
76+
],
77+
"phpunit:unit": [
78+
"@phpunit --configuration=./ci/phpunit/config-unit.xml"
79+
],
80+
"phpunit:integration": [
81+
"@phpunit --configuration=./ci/phpunit/config-integration.xml"
7582
],
7683
"rector": [
7784
"rector --config=./ci/rector/config.php --ansi --no-progress-bar"
@@ -89,11 +96,18 @@
8996
"@phpstan",
9097
"@deptrac"
9198
],
92-
"run-tests": [
93-
"@phpunit"
99+
"run-integration-tests": [
100+
"@phpunit:integration"
101+
],
102+
"run-unit-tests": [
103+
"@phpunit:unit"
104+
],
105+
"run-unit-tests-with-clover": [
106+
"@phpunit:unit --coverage-clover=./var/logs/test-coverage/clover.xml"
94107
],
95-
"run-tests-with-clover": [
96-
"@phpunit --coverage-clover=./var/logs/test-coverage/clover.xml"
108+
"run-all-tests": [
109+
"@run-unit-tests",
110+
"@run-integration-tests"
97111
]
98112
},
99113

docker-compose.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
version: '3.8'
2+
3+
services:
4+
postgres:
5+
image: postgres:17
6+
environment:
7+
POSTGRES_USER: postgres
8+
POSTGRES_PASSWORD: postgres
9+
POSTGRES_DB: postgres_doctrine_test
10+
ports:
11+
- "5432:5432"
12+
volumes:
13+
- postgres_data:/var/lib/postgresql/data
14+
healthcheck:
15+
test: ["CMD-SHELL", "pg_isready -U postgres"]
16+
interval: 10s
17+
timeout: 5s
18+
retries: 5
19+
20+
volumes:
21+
postgres_data:

0 commit comments

Comments
 (0)