forked from netgen/ezpublish-legacy
-
-
Notifications
You must be signed in to change notification settings - Fork 9
214 lines (184 loc) · 8.06 KB
/
Copy pathphpunit.yml
File metadata and controls
214 lines (184 loc) · 8.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
name: PHPUnit
on:
push:
branches: [ main, master ]
paths:
- '**.php'
- 'composer.json'
- 'composer.lock'
- 'phpunit.xml'
- '.github/workflows/phpunit.yml'
pull_request:
branches: [ main, master ]
paths:
- '**.php'
- 'composer.json'
- 'composer.lock'
- 'phpunit.xml'
- '.github/workflows/phpunit.yml'
workflow_dispatch:
permissions:
contents: read
env:
CI_COMPOSER_FILE: composer.ci-phpunit.json
jobs:
phpunit:
name: PHPUnit (PHP ${{ matrix.php }})
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
php: ['8.1', '8.2', '8.3', '8.4', '8.5'] # matches composer.json support
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: dom, libxml, mbstring, pcre, json, iconv, reflection, session, spl, simplexml, gd, mongodb, mysqli, pdo_mysql, pdo_sqlite, sqlite3, zip
coverage: xdebug
tools: composer:v2
- name: Install system packages
run: |
sudo apt-get update
sudo apt-get install -y imagemagick libbson-dev libmongoc-dev
- name: Get Composer cache directory
id: composer-cache
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
- name: Cache Composer dependencies
uses: actions/cache@v4
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock', 'composer.json', '.github/workflows/phpunit.yml') }}
restore-keys: ${{ runner.os }}-composer-
- name: Install dependencies
run: |
cp composer.json "${CI_COMPOSER_FILE}"
if [[ "${{ matrix.php }}" == "8.1" || "${{ matrix.php }}" == "8.2" || "${{ matrix.php }}" == "8.3" ]]; then
if [[ "${{ matrix.php }}" == "8.1" ]]; then
export PHPUNIT_VERSION="^10.5"
else
export PHPUNIT_VERSION="^11.5"
fi
fi
php -r '$file = getenv("CI_COMPOSER_FILE"); $data = json_decode(file_get_contents($file), true, 512, JSON_THROW_ON_ERROR); if (($phpunit = getenv("PHPUNIT_VERSION")) !== false && $phpunit !== "") { $data["require-dev"]["phpunit/phpunit"] = $phpunit; } $data["require-dev"]["mongodb/mongodb"] = "^1.21 || ^2.0"; file_put_contents($file, json_encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES) . PHP_EOL);'
if [[ -n "${PHPUNIT_VERSION:-}" ]]; then
COMPOSER="${CI_COMPOSER_FILE}" composer update phpunit/phpunit --with-all-dependencies --prefer-dist --no-progress --no-interaction --ignore-platform-req=php --ignore-platform-req=ext-mongodb
else
COMPOSER="${CI_COMPOSER_FILE}" composer install --prefer-dist --no-progress --no-interaction --ignore-platform-req=php --ignore-platform-req=ext-mongodb
fi
- name: Ensure vendor is present
run: |
if [[ ! -x vendor/bin/phpunit ]]; then
echo "vendor/bin/phpunit is missing, reinstalling dependencies"
COMPOSER="${CI_COMPOSER_FILE}" composer install --prefer-dist --no-progress --no-interaction --ignore-platform-req=php --ignore-platform-req=ext-mongodb
fi
test -x vendor/bin/phpunit
# Optional but recommended – regenerates autoloads the same way the project does
- name: Generate autoloads
run: php bin/php/ezpgenerateautoloads.php -s -e || true
- name: Run PHPUnit
run: vendor/bin/phpunit --colors=always
- name: Clean CI Composer overlay
if: always()
run: rm -f "${CI_COMPOSER_FILE}" "${CI_COMPOSER_FILE%.json}.lock"
phpunit-db:
name: Database tests (${{ matrix.db }}, PHP ${{ matrix.php }})
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
include:
- php: '8.3'
db: mysql
dsn: 'mysql://root@127.0.0.1/testdb'
- php: '8.3'
db: postgresql
dsn: 'postgresql://postgres@127.0.0.1/testdb'
services:
mysql:
image: mysql:8.0
env:
MYSQL_ALLOW_EMPTY_PASSWORD: 'yes'
MYSQL_DATABASE: testdb
ports:
- 3306:3306
options: >-
--health-cmd="mysqladmin ping -h 127.0.0.1 -uroot"
--health-interval=10s
--health-timeout=5s
--health-retries=10
postgresql:
image: postgres:15
env:
POSTGRES_USER: postgres
POSTGRES_DB: postgres
POSTGRES_HOST_AUTH_METHOD: trust
ports:
- 5432:5432
options: >-
--health-cmd="pg_isready -h 127.0.0.1 -U postgres -d postgres"
--health-interval=10s
--health-timeout=5s
--health-retries=10
env:
TEST_DB_NAME: testdb
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: dom, libxml, mbstring, pcre, json, iconv, reflection, session, spl, simplexml, gd, mongodb, mysqli, pgsql, pdo_mysql, pdo_pgsql, pdo_sqlite, sqlite3, zip
coverage: none
tools: composer:v2
- name: Install system packages
run: |
sudo apt-get update
sudo apt-get install -y imagemagick libbson-dev libmongoc-dev
- name: Get Composer cache directory
id: composer-cache-db
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
- name: Cache Composer dependencies
uses: actions/cache@v4
with:
path: ${{ steps.composer-cache-db.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock', 'composer.json', '.github/workflows/phpunit.yml') }}
restore-keys: ${{ runner.os }}-composer-
- name: Install dependencies
run: |
cp composer.json "${CI_COMPOSER_FILE}"
export PHPUNIT_VERSION="^11.5"
php -r '$file = getenv("CI_COMPOSER_FILE"); $data = json_decode(file_get_contents($file), true, 512, JSON_THROW_ON_ERROR); if (($phpunit = getenv("PHPUNIT_VERSION")) !== false && $phpunit !== "") { $data["require-dev"]["phpunit/phpunit"] = $phpunit; } $data["require-dev"]["mongodb/mongodb"] = "^1.21 || ^2.0"; file_put_contents($file, json_encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES) . PHP_EOL);'
COMPOSER="${CI_COMPOSER_FILE}" composer update phpunit/phpunit --with-all-dependencies --prefer-dist --no-progress --no-interaction --ignore-platform-req=php --ignore-platform-req=ext-mongodb
- name: Ensure vendor is present
run: |
if [[ ! -x vendor/bin/phpunit ]]; then
echo "vendor/bin/phpunit is missing, reinstalling dependencies"
COMPOSER="${CI_COMPOSER_FILE}" composer install --prefer-dist --no-progress --no-interaction --ignore-platform-req=php --ignore-platform-req=ext-mongodb
fi
test -x vendor/bin/phpunit
- name: Generate autoloads
run: php bin/php/ezpgenerateautoloads.php -s -e || true
- name: Prepare database
run: |
case "${{ matrix.db }}" in
mysql)
mysql -h 127.0.0.1 -uroot -e "CREATE DATABASE IF NOT EXISTS ${TEST_DB_NAME};"
;;
postgresql)
psql -v ON_ERROR_STOP=1 -h 127.0.0.1 -U postgres -d postgres -c "CREATE DATABASE ${TEST_DB_NAME};"
psql -v ON_ERROR_STOP=1 -h 127.0.0.1 -U postgres -d "${TEST_DB_NAME}" -c "CREATE EXTENSION IF NOT EXISTS pgcrypto;"
;;
esac
- name: Run database tests
run: |
# Keep DB suite timezone deterministic for CI stability.
TEST_TIMEZONE=America/Los_Angeles
echo "$TEST_TIMEZONE"
php -d date.timezone="$TEST_TIMEZONE" tests/runtests.php --dsn "${{ matrix.dsn }}" --db-per-test tests extension/ezoe
- name: Clean CI Composer overlay
if: always()
run: rm -f "${CI_COMPOSER_FILE}" "${CI_COMPOSER_FILE%.json}.lock"