-
Notifications
You must be signed in to change notification settings - Fork 0
160 lines (134 loc) · 5.88 KB
/
Copy pathphpunit.yml
File metadata and controls
160 lines (134 loc) · 5.88 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
name: PHPUnit Tests
on:
push:
branches: [ master, main, develop ]
pull_request:
branches: [ master, main, develop ]
jobs:
test:
name: PHPUnit Test Suite
runs-on: ubuntu-latest
services:
mysql:
image: mysql:8.0
env:
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: phlix_test
ports:
- 3306:3306
options: >-
--health-cmd="mysqladmin ping"
--health-interval=10s
--health-timeout=5s
--health-retries=5
steps:
- name: Checkout code
uses: actions/checkout@v6
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.3'
extensions: mysql, pdo, pdo_mysql, json, gd, zip, fileinfo, swoole
coverage: xdebug
- name: Build and enable php-uv
run: |
sudo apt-get update && sudo apt-get install -y --no-install-recommends libuv1-dev
git clone --depth=1 https://github.com/bwoebi/php-uv.git /tmp/php-uv
cd /tmp/php-uv && phpize && ./configure --with-uv && make -j"$(nproc)" && sudo make install
echo "extension=uv.so" | sudo tee "$(php-config --ini-dir 2>/dev/null || php -i | awk -F'=> ' '/Scan this dir/{print $2}')/zz-uv.ini"
- name: Verify swoole + uv loaded
run: php -m | grep -iE '^(swoole|uv)$'
- name: Install ffmpeg
run: sudo apt-get install -y --no-install-recommends ffmpeg
- 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@v5
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: ${{ runner.os }}-composer-
- name: Install Composer dependencies
run: composer install --no-interaction --prefer-dist
- name: Apply database migrations
# Apply every migration to the MySQL service DB so real-DB Integration
# tests run against the actual schema (table defs, foreign keys, bound
# LIMIT queries) instead of a hand-rolled simulation. Idempotent: the
# runner downgrades duplicate-column/key errors to notes.
env:
DB_HOST: 127.0.0.1
DB_PORT: '3306'
DB_DATABASE: phlix_test
DB_USER: root
DB_PASSWORD: root
run: php scripts/run-migrations.php
- name: Run PHPUnit tests
# Run the full suite (Unit + Integration). This job provisions a MySQL
# service container AND applies migrations (step above), so Integration
# tests that probe 127.0.0.1:3306 execute for real here against the live
# schema; they self-skip only when no DB is reachable (e.g. locally).
run: ./vendor/bin/phpunit --coverage-clover coverage.xml --coverage-html coverage-report
- name: Check minimum coverage threshold
run: |
# PHPUnit's --coverage-clover writes Clover XML, which uses
# `statements`/`coveredstatements` on /coverage/project/metrics.
# The Cobertura-style `line-rate` attribute does not exist here,
# so compute the percentage from the raw counts.
STMTS=$(xmllint --xpath "string(/coverage/project/metrics/@statements)" coverage.xml 2>/dev/null || echo "0")
COVERED=$(xmllint --xpath "string(/coverage/project/metrics/@coveredstatements)" coverage.xml 2>/dev/null || echo "0")
if [ -z "$STMTS" ] || [ "$STMTS" = "0" ]; then
echo "WARNING: no statements found in coverage.xml — skipping threshold check"
exit 0
fi
PCT=$(echo "scale=2; $COVERED * 100 / $STMTS" | bc)
MIN_COVERAGE=40
echo "Statement coverage: ${PCT}% ($COVERED / $STMTS)"
echo "Minimum required: ${MIN_COVERAGE}%"
if [ "$(echo "$PCT < $MIN_COVERAGE" | bc)" -eq 1 ]; then
echo "ERROR: Coverage ${PCT}% is below minimum ${MIN_COVERAGE}%"
exit 1
fi
echo "Coverage check passed."
- name: Upload coverage to Codecov
if: env.CODECOV_TOKEN != ''
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
uses: codecov/codecov-action@v6
with:
files: ./coverage.xml
# Non-blocking: Codecov upload is informational. A repo not
# yet activated in the Codecov UI returns "Repository not
# found" — that should not fail the test workflow. Activate
# at https://app.codecov.io to flip this on later.
fail_ci_if_error: false
token: ${{ secrets.CODECOV_TOKEN }}
test-server:
name: Server Component Tests
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v6
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.3'
extensions: json, pcntl, posix, swoole
coverage: xdebug
- name: Build and enable php-uv
run: |
sudo apt-get update && sudo apt-get install -y --no-install-recommends libuv1-dev
git clone --depth=1 https://github.com/bwoebi/php-uv.git /tmp/php-uv
cd /tmp/php-uv && phpize && ./configure --with-uv && make -j"$(nproc)" && sudo make install
echo "extension=uv.so" | sudo tee "$(php-config --ini-dir 2>/dev/null || php -i | awk -F'=> ' '/Scan this dir/{print $2}')/zz-uv.ini"
- name: Verify swoole + uv loaded
run: php -m | grep -iE '^(swoole|uv)$'
- name: Install Composer dependencies
run: composer install --no-interaction --prefer-dist
- name: Run Server-specific tests
run: ./vendor/bin/phpunit tests/Unit/Server/
- name: Check code style
run: |
if [ -f vendor/bin/phpcs ]; then
./vendor/bin/phpcs --standard=PSR12 src/Server/
fi