Skip to content

Commit 40f46d3

Browse files
committed
Add a PHPUnit workflow. (#1)
* Updated composer lock file. * Added a PHPUnit workflow file. * Removed a non-existing switch and replaced it with testdox.
1 parent 3a17fae commit 40f46d3

3 files changed

Lines changed: 1878 additions & 2 deletions

File tree

.github/workflows/phpunit.xml

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
name: PHPUnit tests
2+
3+
on:
4+
push:
5+
branches: [ trunk, main ]
6+
pull_request:
7+
branches: [ trunk, main ]
8+
9+
jobs:
10+
test:
11+
runs-on: ubuntu-latest
12+
13+
services:
14+
mysql:
15+
image: mysql:8.0
16+
env:
17+
MYSQL_ROOT_PASSWORD: root
18+
MYSQL_DATABASE: wordpress_test
19+
ports:
20+
- 3306:3306
21+
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
22+
23+
steps:
24+
- name: Checkout plugin
25+
uses: actions/checkout@v3
26+
27+
- name: Setup PHP
28+
uses: shivammathur/setup-php@v2
29+
with:
30+
php-version: '8.2'
31+
extensions: mysqli
32+
coverage: none
33+
34+
- name: Install plugin dependencies
35+
run: composer install --prefer-dist --no-progress
36+
37+
- name: Create test configuration file
38+
run: |
39+
# Create a minimal ttt-config.php that will be overridden by test bootstrap
40+
cat > ttt-config.php << 'EOF'
41+
<?php
42+
// Minimal config for CI - values are overridden by test bootstrap filters
43+
return array(
44+
'db/backend' => 'mysqli',
45+
'db/hostname' => 'localhost',
46+
'db/username' => 'root',
47+
'db/password' => 'root',
48+
'db/database' => 'wordpress_test',
49+
'db/socket' => null,
50+
'db/port' => null,
51+
'db/prefix' => 'wptests_ttt_',
52+
'hmac/secret' => 'test-secret',
53+
'js/interval' => 1000,
54+
);
55+
EOF
56+
57+
- name: Set up WordPress test suite
58+
run: |
59+
# Clone WordPress develop
60+
git clone --depth=1 --branch=trunk https://github.com/WordPress/wordpress-develop.git /tmp/wordpress-develop
61+
cd /tmp/wordpress-develop
62+
63+
# Install WordPress test dependencies
64+
composer install --no-dev
65+
66+
# Create wp-tests-config.php
67+
cp wp-tests-config-sample.php wp-tests-config.php
68+
sed -i "s/youremptytestdbnamehere/wordpress_test/" wp-tests-config.php
69+
sed -i "s/yourusernamehere/root/" wp-tests-config.php
70+
sed -i "s/yourpasswordhere/root/" wp-tests-config.php
71+
sed -i "s|localhost|127.0.0.1:3306|" wp-tests-config.php
72+
73+
- name: Run test suite
74+
env:
75+
WP_TESTS_DIR: /tmp/wordpress-develop/tests/phpunit
76+
WP_DB_NAME: wordpress_test
77+
WP_DB_USER: root
78+
WP_DB_PASSWORD: root
79+
WP_DB_HOST: 127.0.0.1
80+
run: vendor/bin/phpunit --verbose

.github/workflows/phpunit.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: PHPUnit tests
2+
3+
on:
4+
push:
5+
branches: [ master ]
6+
pull_request:
7+
branches: [ master ]
8+
9+
jobs:
10+
test:
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- name: Checkout plugin
15+
uses: actions/checkout@v3
16+
17+
- name: Setup PHP
18+
uses: shivammathur/setup-php@v2
19+
with:
20+
php-version: '8.2'
21+
coverage: none
22+
23+
- name: Install plugin dependencies
24+
run: composer install --prefer-dist --no-progress
25+
26+
- name: Run test suite
27+
run: vendor/bin/phpunit --testdox

0 commit comments

Comments
 (0)