Skip to content

Commit cda1bf4

Browse files
authored
Tests: Make it easier to run unit tests locally (#1083)
1 parent ce32243 commit cda1bf4

File tree

4 files changed

+24
-2
lines changed

4 files changed

+24
-2
lines changed

.wp-env.json

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,17 @@
11
{
22
"core": null,
3-
"plugins": [ "." ]
3+
"plugins": [ "." ],
4+
"env": {
5+
"tests": {
6+
"config": {
7+
"WP_TESTS_DOMAIN": "example.org",
8+
"WP_SITEURL": "http://example.org",
9+
"WP_HOME": "http://example.org"
10+
},
11+
"mappings": {
12+
"wp-content/plugins/activitypub": ".",
13+
"wp-content/plugins/activitypub/tests": "./tests"
14+
}
15+
}
16+
}
417
}

composer.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@
4040
"bin/install-wp-tests.sh activitypub-test root activitypub-test test-db latest true",
4141
"vendor/bin/phpunit"
4242
],
43+
"test:wp-env": [
44+
"wp-env run tests-cli --env-cwd=\"wp-content/plugins/activitypub\" vendor/bin/phpunit"
45+
],
4346
"lint": [
4447
"vendor/bin/phpcs"
4548
],

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
"dev": "wp-scripts start",
1414
"build": "wp-scripts build",
1515
"env-start": "wp-env start && wp-env run cli wp rewrite structure '/%year%/%monthnum%/%postname%/'",
16-
"env-stop": "wp-env stop"
16+
"env-stop": "wp-env stop",
17+
"env-test": "wp-env run tests-cli --env-cwd=\"wp-content/plugins/activitypub\" vendor/bin/phpunit"
1718
},
1819
"license": "MIT",
1920
"bugs": {

tests/bootstrap.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@
88
\define( 'ACTIVITYPUB_DISABLE_REACTIONS', false );
99
\define( 'ACTIVITYPUB_DISABLE_INCOMING_INTERACTIONS', false );
1010

11+
// Defined here because setting them in .wp-env.json doesn't work for some reason.
12+
\define( 'WP_TESTS_DOMAIN', 'example.org' );
13+
\define( 'WP_SITEURL', 'http://example.org' );
14+
\define( 'WP_HOME', 'http://example.org' );
15+
1116
$_tests_dir = \getenv( 'WP_TESTS_DIR' );
1217

1318
if ( ! $_tests_dir ) {

0 commit comments

Comments
 (0)