Skip to content

Commit 648405c

Browse files
p4veIPavel Karfik
andauthored
Add Postgres to Github workflows (#320)
Co-authored-by: Pavel Karfik <[email protected]>
1 parent 78caabb commit 648405c

File tree

7 files changed

+556
-3
lines changed

7 files changed

+556
-3
lines changed

.gitattributes

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@
33
.phpstan-dba-pdo.cache linguist-generated=true
44
.phpunit-phpstan-dba-mysqli.cache linguist-generated=true
55
.phpunit-phpstan-dba-pdo.cache linguist-generated=true
6+
.phpunit-phpstan-dba-pdo-pgsql.cache linguist-generated=true
67

78
# Exclude non-essential files from dist
89
/tests export-ignore
910
.phpunit-phpstan-dba-mysqli.cache
1011
.phpunit-phpstan-dba-pdo.cache
12+
.phpunit-phpstan-dba-pdo-pgsql.cache
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
name: Unit Tests Postgres
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
9+
jobs:
10+
phpunit:
11+
name: PHPUnit
12+
runs-on: ubuntu-latest
13+
14+
strategy:
15+
fail-fast: false
16+
matrix:
17+
include:
18+
- php-version: "8.0"
19+
db-image: 'postgres:14'
20+
reflector: "pdo-pgsql"
21+
mode: "recording"
22+
23+
env:
24+
DBA_REFLECTOR: ${{ matrix.reflector }}
25+
DBA_MODE: ${{ matrix.mode }}
26+
DBA_USER: postgres
27+
DBA_DATABASE: postgres
28+
DBA_PASSWORD: postgres
29+
30+
# https://docs.github.com/en/free-pro-team@latest/actions/guides/about-service-containers
31+
services:
32+
postgres:
33+
image: ${{ matrix.db-image }}
34+
env:
35+
POSTGRES_PASSWORD: postgres
36+
options: --health-cmd=pg_isready --health-interval=10s --health-timeout=5s --health-retries=3
37+
ports:
38+
- 5432:5432
39+
40+
steps:
41+
- uses: actions/checkout@v2
42+
with:
43+
repository: ${{ github.event.client_payload.pull_request.head.repo.full_name }}
44+
ref: ${{ github.event.client_payload.pull_request.head.ref }}
45+
46+
- name: Setup PHP with PDO
47+
uses: shivammathur/setup-php@v2
48+
with:
49+
php-version: "${{ matrix.php-version }}"
50+
coverage: none
51+
52+
- uses: "ramsey/composer-install@v2"
53+
with:
54+
composer-options: "--prefer-dist --no-progress"
55+
56+
- name: Setup Problem Matchers for PHPUnit
57+
run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"
58+
59+
- name: Install PostgreSQL client
60+
run: |
61+
sudo apt-get update
62+
sudo apt-get install --yes postgresql-client
63+
64+
- name: Setup PSQL
65+
run: psql -h localhost -U postgres < tests/pgsql-schema.sql
66+
env:
67+
PGPASSWORD: postgres
68+
69+
- run: composer phpunit
70+
71+
replay:
72+
name: PHPUnit (reflection replay)
73+
runs-on: ubuntu-latest
74+
75+
strategy:
76+
fail-fast: false
77+
matrix:
78+
include:
79+
- php-version: "8.1"
80+
reflector: "pdo-pgsql"
81+
mode: "replay"
82+
dsn: "pgsql"
83+
84+
env:
85+
DBA_REFLECTOR: ${{ matrix.reflector }}
86+
DBA_MODE: ${{ matrix.mode }}
87+
DBA_DSN: ${{ matrix.dsn }}
88+
DBA_USER: postgres
89+
DBA_DATABASE: postgres
90+
DBA_PASSWORD: postgres
91+
92+
steps:
93+
- uses: actions/checkout@v2
94+
with:
95+
repository: ${{ github.event.client_payload.pull_request.head.repo.full_name }}
96+
ref: ${{ github.event.client_payload.pull_request.head.ref }}
97+
98+
- name: Setup PHP
99+
uses: shivammathur/setup-php@v2
100+
with:
101+
php-version: "${{ matrix.php-version }}"
102+
coverage: none
103+
104+
- uses: "ramsey/composer-install@v2"
105+
with:
106+
composer-options: "--prefer-dist --no-progress"
107+
108+
- name: Setup Problem Matchers for PHPUnit
109+
run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"
110+
111+
- run: composer phpunit

.github/workflows/tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Unit Tests
1+
name: Unit Tests MySQL
22

33
on:
44
push:

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,5 @@ mysqli.php
77
pdo.php
88

99
.env
10+
11+
.idea/

tests/ReflectorFactory.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,11 @@ public static function create(string $cacheDir): QueryReflector
4040
// we need to record the reflection information in both, phpunit and phpstan since we are replaying it in both CI jobs.
4141
// in a regular application you will use phpstan-dba only within your phpstan CI job, therefore you only need 1 cache-file.
4242
// phpstan-dba itself is a special case, since we are testing phpstan-dba with phpstan-dba.
43-
$cacheFile = $cacheDir.'/.phpunit-phpstan-dba-'.$reflector.'.cache';
43+
$cacheFile = sprintf(
44+
'%s/.phpunit-phpstan-dba-%s.cache',
45+
$cacheDir,
46+
$reflector,
47+
);
4448
if (\defined('__PHPSTAN_RUNNING__')) {
4549
$cacheFile = $cacheDir.'/.phpstan-dba-'.$reflector.'.cache';
4650
}
@@ -58,6 +62,9 @@ public static function create(string $cacheDir): QueryReflector
5862
$pdo = new PDO(sprintf('mysql:dbname=%s;host=%s', $dbname, $host), $user, $password);
5963
$reflector = new PdoQueryReflector($pdo);
6064
$schemaHasher = new SchemaHasherMysql($pdo);
65+
} elseif ('pdo-pgsql' === $reflector) {
66+
$pdo = new PDO(sprintf('pgsql:dbname=%s;host=%s', $dbname, $host), $user, $password);
67+
$reflector = new PdoQueryReflector($pdo);
6168
} else {
6269
throw new \RuntimeException('Unknown reflector: '.$reflector);
6370
}
@@ -66,7 +73,7 @@ public static function create(string $cacheDir): QueryReflector
6673
$reflector = new ReplayAndRecordingQueryReflector(
6774
$reflectionCache,
6875
$reflector,
69-
$schemaHasher
76+
$schemaHasher ?? throw new \RuntimeException('Schema hasher required.')
7077
);
7178
} else {
7279
$reflector = new RecordingQueryReflector(

0 commit comments

Comments
 (0)