Skip to content

Commit 0cf1552

Browse files
committed
feat: use wp-env for testing
1 parent 27192d9 commit 0cf1552

File tree

8 files changed

+1535
-185
lines changed

8 files changed

+1535
-185
lines changed

.github/workflows/ci.yml

Lines changed: 48 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,62 @@
11
name: CI
22

3-
on: [push, pull_request]
3+
on: # yamllint disable-line rule:truthy
4+
workflow_dispatch:
5+
pull_request:
6+
push:
7+
branches:
8+
- "master"
9+
- "develop"
10+
11+
permissions:
12+
contents: "read"
13+
14+
concurrency:
15+
group: "${{ github.workflow }}-${{ github.ref }}"
16+
cancel-in-progress: true
417

518
jobs:
619
run:
7-
runs-on: ${{ matrix.operating-system }}
8-
services:
9-
mysql:
10-
image: mysql:5.7
11-
env:
12-
MYSQL_ALLOW_EMPTY_PASSWORD: false
13-
MYSQL_ROOT_PASSWORD: root
14-
MYSQL_DATABASE: wordpress_test
15-
ports:
16-
- 3306:3306
17-
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
20+
runs-on: ubuntu-22.04
1821
strategy:
1922
matrix:
20-
operating-system: [ ubuntu-latest ]
2123
php-versions: [ '8.0', '8.1', '8.2', '8.3' ]
22-
wp: [ '6.0', '6.1', '6.2', '6.3', '6.4', '6.5', 'latest' ]
23-
name: PHP ${{ matrix.php-versions }} Test on ${{ matrix.operating-system }} with WP ${{ matrix.wp }}
24+
core: [ '6.0', '6.1', '6.2', '6.3', '6.4', '6.5', 'latest' ]
25+
name: Test PHP ${{ matrix.php-versions }} with WP ${{ matrix.core }}
2426
steps:
2527
- name: Checkout
2628
uses: actions/checkout@v1
2729

28-
- name: Setup PHP
30+
- name: Set up PHP
2931
uses: shivammathur/setup-php@v2
3032
with:
31-
php-version: ${{ matrix.php-versions }}
32-
coverage: xdebug #optional, setup coverage driver
33-
34-
- name: Install all depedencies
35-
run: composer update
36-
37-
- name: Install WP Tests
38-
run: bash bin/install-wp-tests.sh wordpress_test root root 127.0.0.1:3306 ${{ matrix.wp }} true
39-
40-
- name: phpunit tests
41-
run: ./vendor/bin/phpunit
33+
php-version: ${{ matrix.php_version }}
34+
ini-file: development
35+
coverage: none
36+
37+
- name: Override PHP version in composer.json
38+
run: composer config platform.php ${{ matrix.php_version }}
39+
40+
- name: Composer install
41+
run: composer install -o
42+
43+
- name: Setup Node
44+
uses: actions/setup-node@v4
45+
with:
46+
node-version: '20.11.*'
47+
cache: npm
48+
49+
- name: Install JS dependencies
50+
run: npm ci
51+
52+
- name: Launch environment
53+
run: WP_ENV_PHP_VERSION=${{ matrix.php_version }} WP_ENV_CORE=WordPress/WordPress#${{ matrix.core }} npm run env:start-ci
54+
55+
- name: Updates dependencies for tests
56+
run: npm run env run tests-wordpress composer update -- -W --working-dir=/var/www/html/wp-content/plugins/wp-http-blocklist/
57+
58+
- name: Update Yoast dependencies
59+
run: npm run env run tests-wordpress composer update -- --dev yoast/phpunit-polyfills -W --working-dir=/var/www/html/wp-content/plugins/wp-http-blocklist/
60+
61+
- name: Test PHP
62+
run: npm run test:php

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,9 @@
1313

1414
# Tests
1515
/tests/*.txt
16+
/tests/coverage/
17+
.phpunit.result.cache
18+
19+
20+
# Node
21+
/node_modules/

.wp-env.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"phpVersion": "8.0",
3+
"port": 4013,
4+
"plugins": [
5+
"."
6+
],
7+
"env": {
8+
"tests": {
9+
"port": 4012
10+
}
11+
}
12+
13+
}

bin/install-wp-tests.sh

Lines changed: 0 additions & 155 deletions
This file was deleted.

0 commit comments

Comments
 (0)