Repository navigation
279 lines (239 loc) · 9 KB
/
Copy pathphpunit.yml
File metadata and controls
279 lines (239 loc) · 9 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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
name: PHPUnit Tests
on:
push:
branches: [ "main" ]
pull_request:
branches: [ "**" ]
permissions:
contents: read
jobs:
test:
runs-on: ubuntu-latest
services:
mysql:
image: mysql:9.7.2@sha256:c7cb87a9822f499375287930cbff71d6d3b201e346b45108b1115b435ee2df13
env:
MYSQL_ROOT_PASSWORD: root_password
MYSQL_DATABASE: mde2-msl-test
MYSQL_USER: test_user
MYSQL_PASSWORD: test_password
ports:
- 3306:3306
options: >-
--health-cmd "mysqladmin ping --silent"
--health-interval 10s
--health-timeout 5s
--health-retries 3
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
fetch-depth: 0
- name: Set up PHP
uses: shivammathur/setup-php@eb7c497e18156a6bbabfef1d3a82760b9eda3962 # 2.40.0
with:
php-version: '8.5'
extensions: mbstring, xml, ctype, iconv, intl, pdo_sqlite, pdo_mysql, mysqli, zip
coverage: xdebug
- name: Determine Composer cache directory
id: composer-cache
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
- name: Cache Composer dependencies
uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-php-8.5-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-php-8.5-composer-
${{ runner.os }}-php-composer-
- name: Set up Node.js
uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
with:
node-version-file: '.nvmrc'
cache: 'npm'
- name: Install PHP dependencies
run: |
composer install --prefer-dist --no-progress --no-suggest
composer dump-autoload -o
- name: Validate composer.json and composer.lock
run: composer validate --strict
- name: Check file-name conventions
env:
FILE_NAME_BASE: ${{ github.event.pull_request.base.sha || github.event.before }}
run: composer check:file-names -- --base="$FILE_NAME_BASE"
- name: Install JS dependencies
run: npm ci
- name: Wait for MySQL to be ready
run: |
for i in {30..0}; do
if mysqladmin ping -h127.0.0.1 --silent; then
break
fi
echo 'Waiting for MySQL...'
sleep 5
done
if [ "$i" = 0 ]; then
echo >&2 'MySQL did not start in time.'
exit 1
fi
- name: Grant privileges to test_user
run: |
mysql -h127.0.0.1 -uroot -proot_password -e "
CREATE USER IF NOT EXISTS 'test_user'@'%' IDENTIFIED BY 'test_password';
GRANT ALL PRIVILEGES ON *.* TO 'test_user'@'%';
FLUSH PRIVILEGES;
"
- name: Create settings.php
run: |
cat <<'PHP' > settings.php
<?php
function connectDb() {
$host = '127.0.0.1';
$username = 'test_user';
$password = 'test_password';
$database = 'mde2-msl-test';
$conn = new mysqli($host, $username, $password, $database);
return $conn;
}
// Establish the database connection (skip in unit testing context)
if (!defined('INCLUDED_FROM_TEST')) {
$connection = connectDb();
}
$ELMO_API_KEY = '1234-1234-1234-1234';
$apiKeyGoogleMaps = 'test_api_key';
$apiKeyTimezone = 'test_timezone_api_key';
$ernieUrl = '';
$ernieApiKey = '';
$ernieCacheTtl = 21600;
$dataUploadUrl = getenv('DATA_UPLOAD_URL') ?: '';
$maxTitles = 2;
$showMslLogo = false;
$showThesauri = true;
$showFreeKeywords = true;
$showSpatialTemporalCoverage = true;
$showRelatedWork = true;
$showFundingReference = true;
$showAuthorInstitution = true;
$showLicense = true;
$defaultLicense = 'CC-BY-4.0';
$showMslLabs = false;
$showMslVocabs = false;
$mslVocabsUrl = '';
$showUsedInstruments = false;
$showGGMsProperties = false;
$showFeedbackLink = true;
$smtpHost = 'smtp.test.de';
$smtpPort = 465;
$smtpUser = 'test_user';
$smtpPassword = 'test_password';
$smtpSender = 'test_sender@test.com';
$smtpSecure = '';
$smtpAuth = '';
$SIMULATE_EMAIL = true;
$feedbackAddress = 'feedback@test.com';
$xmlSubmitAddress = 'xmlsubmit@test.com';
$instanceTitle = 'ELMO Test';
function getSettings($setting) {
global $apiKeyGoogleMaps, $showMslLabs;
header('Content-Type: application/json; charset=utf-8');
switch ($setting) {
case 'apiKey':
echo json_encode(['apiKey' => $apiKeyGoogleMaps]);
break;
case 'all':
echo json_encode(['apiKey' => $apiKeyGoogleMaps, 'showMslLabs' => $showMslLabs]);
break;
default:
echo json_encode(['error' => 'Unknown setting']);
break;
}
exit;
}
if (isset($_GET['setting'])) {
getSettings($_GET['setting']);
exit;
}
function elmo_log($msg) {
error_log('[ELMO save_data] ' . $msg);
}
PHP
- name: Initialize database structure and lookup data
run: php -r "require 'scripts/install.php'; createDatabaseStructure(\$connection); insertLookupData(\$connection);"
- name: Start PHP built-in web server
run: |
php -S localhost:8000 -t . tests/server.php 2>&1 > server.log &
echo $! > server.pid
sleep 10
echo "Testing initial API endpoints:"
curl -v http://localhost:8000/api/v2/general/alive
echo "\nTesting licenses endpoint:"
curl -v http://localhost:8000/api/v2/vocabs/licenses/all
echo "\nInitial server log contents:"
cat server.log
echo "\nPHP error log:"
if [ -f /var/log/php_errors.log ]; then
cat /var/log/php_errors.log
fi
- name: Set PHPUnit permissions
run: chmod +x vendor/bin/phpunit
- name: Run PHPUnit tests
env:
API_BASE_URL: http://localhost:8000
run: |
set -euo pipefail
output_file="$(mktemp)"
junit_file="$(mktemp)"
if ! vendor/bin/phpunit --configuration phpunit.xml --colors=never --log-junit "$junit_file" 2>&1 | tee "$output_file"; then
echo "PHPUnit test run failed."
exit 1
fi
if [ ! -s "$junit_file" ]; then
echo "PHPUnit did not produce a JUnit report. The process may have terminated before completing the test suite."
exit 1
fi
test_count="$(grep -c '<testcase ' "$junit_file" || true)"
if [ "$test_count" -eq 0 ]; then
echo "PHPUnit completed without recording any executed tests."
exit 1
fi
if ! grep -Eq 'OK \([1-9][0-9]* tests?|Tests: [1-9][0-9]*,' "$output_file"; then
echo "PHPUnit did not reach its final test summary. The process may have terminated prematurely."
exit 1
fi
echo "PHPUnit completed and recorded ${test_count} tests."
echo "\nFinal Server Log:"
cat server.log
- name: Generate coverage (PHP 8.5 push builds only)
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
env:
API_BASE_URL: http://localhost:8000
XDEBUG_MODE: coverage
run: |
echo "Checking Xdebug status:"
php -m | grep -i xdebug || echo "Xdebug not found!"
php -v
vendor/bin/phpunit --configuration phpunit.coverage.xml
echo "\nChecking clover.xml:"
if [ -f clover.xml ]; then
echo "clover.xml created successfully!"
head -20 clover.xml
else
echo "ERROR: clover.xml was not created!"
fi
- name: Upload coverage to Codecov
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
uses: codecov/codecov-action@303a32d7a59b442fa8d48b6a1cc6825c09c847a5 # v7.1.1
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: ./clover.xml
flags: php
name: phpunit-coverage
fail_ci_if_error: true
verbose: true
- name: Stop PHP server
if: always()
run: |
if [ -f server.pid ]; then
kill "$(cat server.pid)"
else
echo "server.pid not found; PHP server was likely not started."
fi