Skip to content

Commit

Permalink
Tests: Make it easier to run unit tests locally (#1083)
Browse files Browse the repository at this point in the history
  • Loading branch information
obenland authored Dec 17, 2024
1 parent ce32243 commit cda1bf4
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 2 deletions.
15 changes: 14 additions & 1 deletion .wp-env.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,17 @@
{
"core": null,
"plugins": [ "." ]
"plugins": [ "." ],
"env": {
"tests": {
"config": {
"WP_TESTS_DOMAIN": "example.org",
"WP_SITEURL": "http://example.org",
"WP_HOME": "http://example.org"
},
"mappings": {
"wp-content/plugins/activitypub": ".",
"wp-content/plugins/activitypub/tests": "./tests"
}
}
}
}
3 changes: 3 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@
"bin/install-wp-tests.sh activitypub-test root activitypub-test test-db latest true",
"vendor/bin/phpunit"
],
"test:wp-env": [
"wp-env run tests-cli --env-cwd=\"wp-content/plugins/activitypub\" vendor/bin/phpunit"
],
"lint": [
"vendor/bin/phpcs"
],
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
"dev": "wp-scripts start",
"build": "wp-scripts build",
"env-start": "wp-env start && wp-env run cli wp rewrite structure '/%year%/%monthnum%/%postname%/'",
"env-stop": "wp-env stop"
"env-stop": "wp-env stop",
"env-test": "wp-env run tests-cli --env-cwd=\"wp-content/plugins/activitypub\" vendor/bin/phpunit"
},
"license": "MIT",
"bugs": {
Expand Down
5 changes: 5 additions & 0 deletions tests/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@
\define( 'ACTIVITYPUB_DISABLE_REACTIONS', false );
\define( 'ACTIVITYPUB_DISABLE_INCOMING_INTERACTIONS', false );

// Defined here because setting them in .wp-env.json doesn't work for some reason.
\define( 'WP_TESTS_DOMAIN', 'example.org' );
\define( 'WP_SITEURL', 'http://example.org' );
\define( 'WP_HOME', 'http://example.org' );

$_tests_dir = \getenv( 'WP_TESTS_DIR' );

if ( ! $_tests_dir ) {
Expand Down

0 comments on commit cda1bf4

Please sign in to comment.