diff --git a/.wp-env.tests.json b/.wp-env.tests.json index 08c195a..8a4b285 100644 --- a/.wp-env.tests.json +++ b/.wp-env.tests.json @@ -4,9 +4,6 @@ "plugins": [ "." ], - "themes": [ - "https://downloads.wordpress.org/theme/twentytwentytwo.zip" - ], "testsEnvironment": false, "config": { "WP_DEBUG": true diff --git a/composer.json b/composer.json index 174380e..24f145c 100644 --- a/composer.json +++ b/composer.json @@ -57,7 +57,7 @@ "lint": "phpcs", "phpstan": "phpstan analyse --memory-limit=1G", "test": "vendor/bin/phpunit -c phpunit.xml.dist", - "test-multisite": "WP_MULTISITE=1 phpunit --exclude-group=ms-excluded", + "test-multisite": "WP_MULTISITE=1 vendor/bin/phpunit -c phpunit.xml.dist --exclude-group=ms-excluded", "pot": "wp i18n make-pot . ./languages/project-name-features.pot --domain=project-name-features --include=\"inc,templates,assets/build/blocks\"" } } diff --git a/docs/internal/maintenance.md b/docs/internal/maintenance.md index f7811c3..aae9166 100644 --- a/docs/internal/maintenance.md +++ b/docs/internal/maintenance.md @@ -177,4 +177,3 @@ Keep implementation follow-ups out of documentation pull requests; record each w - **Stale wording:** `.npmrc` still calls `wp-tooling` a private repository, and `bin/init.js` suggests the pilot `npm install --install-links`. - **Lockfile URLs:** `package-lock.json` resolves `@rtcamp/*` over `git+ssh://`. Confirm a clean `npm ci` works for a developer without a GitHub SSH key. - **Downstream docs workflow:** `documentation.yml` ships into client projects. It is inert there (its jobs only run in `rtCamp/plugin-elementary`), but decide whether init cleanup should remove it. -- **Multisite tests:** `composer test-multisite` has no `wp-env` wrapper. diff --git a/docs/local-development.md b/docs/local-development.md index 44e046a..980f1cc 100644 --- a/docs/local-development.md +++ b/docs/local-development.md @@ -54,6 +54,7 @@ Run the focused test first, then the full set before opening a pull request. # PHP tests — run inside the wp-env test environment (started on demand). npm run test:php -- --filter ShortcodesTest # one test class npm run test:php # the whole suite +npm run test:php:multisite # the whole suite on multisite # PHP style and static analysis — run on the host (PHP 8.2+). composer lint # PHPCS (rtCampWP ruleset) @@ -67,7 +68,7 @@ npm run lint:css npm run lint:package-json ``` -`npm run test:php` needs `npm run wp-env start` first; its `pretest` step runs `composer install` inside the container when `vendor/` is missing. `composer test` expects a WordPress test library on the host and is not the supported route. +`npm run test:php` starts the test environment unless it is already up with its database ready, and runs `composer install` inside it when `composer.lock` is newer than `vendor/`. A running environment is reused as it is, so restart it with `npm run wp-env start -- --config=.wp-env.tests.json` after editing `.wp-env.tests.json`. `npm run test:php:multisite` runs the same suite with `WP_MULTISITE=1`. `composer test` and `composer test-multisite` expect a WordPress test library on the host and are not the supported route. **Coverage:** start the environment with Xdebug, then run the coverage script. The HTML report is written to `coverage/`. diff --git a/package.json b/package.json index 271b955..db0ae63 100644 --- a/package.json +++ b/package.json @@ -105,8 +105,10 @@ "test": "npm-run-all --parallel test:js test:php", "test:js": "wp-scripts test-unit-jest --config=tests/js/jest.config.js --passWithNoTests", "test:js:watch": "npm run test:js -- --watch", - "pretest:php": "wp-env start --config=.wp-env.tests.json && wp-env run --config=.wp-env.tests.json cli --env-cwd=wp-content/plugins/$(basename \"$PWD\") -- sh -c 'test -f vendor/autoload.php || composer install --no-interaction'", + "pretest:php": "(wp-env run --config=.wp-env.tests.json cli wp core is-installed >/dev/null 2>&1 || wp-env start --config=.wp-env.tests.json) && ([ vendor/autoload.php -nt composer.lock ] || wp-env run --config=.wp-env.tests.json cli --env-cwd=wp-content/plugins/$(basename \"$PWD\") -- sh -c 'composer install --no-interaction && touch vendor/autoload.php')", "test:php": "wp-env run --config=.wp-env.tests.json cli --env-cwd=wp-content/plugins/$(basename \"$PWD\") -- vendor/bin/phpunit -c phpunit.xml.dist", + "pretest:php:multisite": "npm run pretest:php", + "test:php:multisite": "wp-env run --config=.wp-env.tests.json cli --env-cwd=wp-content/plugins/$(basename \"$PWD\") -- env WP_MULTISITE=1 vendor/bin/phpunit -c phpunit.xml.dist --exclude-group=ms-excluded", "pretest:php:coverage": "echo \"\\e[1m\\e[32mMake sure you have run npm run wp-env start -- --config=.wp-env.tests.json --xdebug=coverage before using this command\\e[0m\" && wp-env run --config=.wp-env.tests.json cli --env-cwd=wp-content/plugins/$(basename \"$PWD\") -- sh -c 'test -f vendor/autoload.php || composer install --no-interaction'", "test:php:coverage": "wp-env run --config=.wp-env.tests.json cli --env-cwd=wp-content/plugins/$(basename \"$PWD\") -- vendor/bin/phpunit -c phpunit.xml.dist --coverage-html coverage", "posttest:php:coverage": "echo \"\\e[1m\\e[32mIf you have run this command with xdbug coverage enabled, you can view the coverage report at /coverage path\\e[0m\"",