Repository navigation
148 lines (144 loc) 路 6.25 KB
/
Copy pathphpunit.yml
File metadata and controls
148 lines (144 loc) 路 6.25 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
name: PHPUnit
on:
workflow_call:
inputs:
should-run:
type: boolean
default: true
secrets:
CODECOV_TOKEN:
required: true
permissions:
contents: read
jobs:
phpunit:
name: PHP ${{ matrix.php }}
runs-on: ubuntu-24.04
strategy:
fail-fast: false
matrix:
php: [ '7.4', '8.3' ]
include:
# The oldest PHP runs against the oldest WordPress the plugin supports, so the floor in the readme is tested.
- php: '7.4'
core: 'https://wordpress.org/wordpress-7.0.zip'
- php: '8.3'
coverage: true
steps:
# A job-level `if:` would skip before the matrix expands, collapsing
# both PHP versions into one unexpanded `phpunit / PHP ${{ matrix.php
# }}` check instead of the two named ones required checks expect. Every
# step below is gated instead, so the matrix still expands and the job
# reports success under each version's own name.
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
if: ${{ inputs.should-run }}
with:
persist-credentials: false
- uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
if: ${{ inputs.should-run }}
with:
node-version: 22
cache: npm
- uses: shivammathur/setup-php@eb7c497e18156a6bbabfef1d3a82760b9eda3962 # 2.40.0
if: ${{ inputs.should-run }}
with:
php-version: ${{ matrix.php }}
tools: composer
- run: npm ci
if: ${{ inputs.should-run }}
- name: Authenticate composer to GitHub
if: ${{ inputs.should-run }}
run: composer config --global --auth github-oauth.github.com '${{ secrets.GITHUB_TOKEN }}'
- name: Install Composer dependencies
if: ${{ inputs.should-run }}
run: composer install --no-interaction
- name: Start wp-env (retry on transient failures)
if: ${{ inputs.should-run }}
run: |
for attempt in 1 2 3; do
if npx wp-env start ${{ matrix.coverage && '--xdebug=coverage' || '' }}; then
exit 0
fi
if [ "$attempt" -eq 3 ]; then
exit 1
fi
npx wp-env destroy || true
echo "wp-env start failed on attempt $attempt, retrying..."
done
env:
WP_ENV_PHP_VERSION: ${{ matrix.php }}
WP_ENV_CORE: ${{ matrix.core }}
- run: npx wp-env run tests-cli --env-cwd='presence-api' -- ./vendor/bin/phpunit ${{ matrix.coverage && '--coverage-clover coverage.xml' || '' }}
if: ${{ inputs.should-run }}
- name: Upload coverage to Codecov
if: ${{ inputs.should-run && matrix.coverage }}
uses: codecov/codecov-action@303a32d7a59b442fa8d48b6a1cc6825c09c847a5 # v7.1.1
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: coverage.xml
flags: phpunit
# This is the only multisite run in CI. It lives here rather than in its
# own workflow because the run above skips every is_multisite() test, so
# the network provisioning paths in includes/plugin.php reported as uncovered
# no matter how well tested they were. Reusing this job's environment
# costs seconds, and Codecov merges the two reports for the commit.
#
# Keep the multisite suite running if this job's coverage matrix ever
# changes, otherwise network behaviour stops being tested at all.
#
# WP_MULTISITE=1 is what puts the test bootstrap into network mode. The
# bootstrap installs its own test database and never reads wp-config.php,
# so no `multisite-convert` is needed here. Without the variable the suite
# prints "Running as single site..." and this report adds nothing.
- name: Run the suite as multisite
if: ${{ inputs.should-run && matrix.coverage }}
run: npx wp-env run tests-cli --env-cwd='presence-api' -- env WP_MULTISITE=1 ./vendor/bin/phpunit --coverage-clover coverage-multisite.xml
- name: Upload multisite coverage to Codecov
if: ${{ inputs.should-run && matrix.coverage }}
uses: codecov/codecov-action@303a32d7a59b442fa8d48b6a1cc6825c09c847a5 # v7.1.1
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: coverage-multisite.xml
flags: multisite
# Single site only, since the multisite fixtures rely on MySQL keeping DDL and auto-increment counters outside the per-test rollback.
sqlite:
name: SQLite
if: ${{ inputs.should-run }}
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
with:
node-version: 22
cache: npm
- uses: shivammathur/setup-php@eb7c497e18156a6bbabfef1d3a82760b9eda3962 # 2.40.0
with:
php-version: '8.3'
tools: composer
- run: npm ci
- name: Authenticate composer to GitHub
run: composer config --global --auth github-oauth.github.com '${{ secrets.GITHUB_TOKEN }}'
- name: Install Composer dependencies
run: composer install --no-interaction
- name: Start wp-env (retry on transient failures)
run: |
for attempt in 1 2 3; do
if npx wp-env start; then
exit 0
fi
if [ "$attempt" -eq 3 ]; then
exit 1
fi
npx wp-env destroy || true
echo "wp-env start failed on attempt $attempt, retrying..."
done
env:
WP_ENV_PHP_VERSION: '8.3'
# Same drop-in setup as the SQLite integration's own wp-setup.sh, which is what Playground runs on.
- name: Swap the test database for SQLite
run: |
npx wp-env run tests-cli -- wp plugin install sqlite-database-integration
npx wp-env run tests-cli -- sh -c "sed -e \"s#'{SQLITE_IMPLEMENTATION_FOLDER_PATH}'#__DIR__ . '/plugins/sqlite-database-integration'#\" -e 's#{SQLITE_PLUGIN}#sqlite-database-integration/load.php#g' wp-content/plugins/sqlite-database-integration/db.copy > wp-content/db.php"
- run: npx wp-env run tests-cli --env-cwd='presence-api' -- ./vendor/bin/phpunit