From ca06f790bf29e8bfa2eb5a62ab19a5e34f4d5739 Mon Sep 17 00:00:00 2001 From: Pollora maintainer Date: Fri, 4 Dec 2026 17:08:19 +0100 Subject: [PATCH] docs(testing): the skeleton isolates WordPress hooks after v13.45.2 --- testing.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/testing.md b/testing.md index d692fbc..8c7128f 100644 --- a/testing.md +++ b/testing.md @@ -35,7 +35,7 @@ php artisan test tests/Feature/FrontPageTest.php php artisan test --filter=FrontPageTest ``` -A fresh skeleton ships tests of its own. `tests/Unit` checks that the WordPress core patch and the Composer patches are in place. `tests/Feature/Installation` checks the installation: the `.env` file, the database connection, the WordPress tables and options, and, over HTTP, that `APP_URL` answers. Those need an installed site and a web server serving `APP_URL`. +A fresh skeleton ships tests of its own. `tests/Unit` checks that the WordPress core patch and the Composer patches are in place. `tests/Feature/Installation` checks the installation: the `.env` file, the database connection, the WordPress tables and options, and, over HTTP, that `APP_URL` answers. Those need an installed site and a web server serving `APP_URL`. Skeleton releases after v13.45.2 also ship `tests/Feature/WordPressHookIsolationTest.php`, which checks that [the WordPress hooks of one application do not reach the next one](#hooks-outlive-the-test-that-registered-them); it needs the installed site too. Two other scripts exist for the skeleton's own maintenance: `composer test:integration` (a suite of HTTP checks against a running site, whose URL comes from `POLLORA_TEST_URL`) and `composer test:install`. They are not part of `composer test`. @@ -181,7 +181,7 @@ Before 13.45.2, only the first application of a test process has the theme: on a #### Hooks outlive the test that registered them -WordPress hooks are globals too. Each feature test gets a new application, but WordPress is loaded once per process, and the callbacks that an application registered stay in `$wp_filter` after Laravel has flushed it at the end of its test. When a later test fires the hook, a callback of the first application asks that flushed container for a service. Two feature tests show it: +WordPress hooks are globals too. Each feature test gets a new application, but WordPress is loaded once per process, and, unless the test case isolates them, the callbacks that an application registered stay in `$wp_filter` after Laravel has flushed it at the end of its test. When a later test fires the hook, a callback of the first application asks that flushed container for a service. Skeleton releases after v13.45.2 already [isolate the hooks](#hooks-outlive-the-test-that-registered-them) with the framework's trait, below. In a project whose `tests/TestCase.php` does not, two feature tests show the problem: ```php // tests/Feature/FirstTest.php: any test that boots the application @@ -205,7 +205,7 @@ it('runs the footer hooks', function (): void { There are several ways around it. -**Use the framework's trait** (Pollora 13.45.2 and later). Add it to the base test case; Laravel sets it up and tears it down, under Pest too: +**Use the framework's trait** (Pollora 13.45.2 and later). In a project created from a skeleton release after v13.45.2, `tests/TestCase.php` already uses it. A project created from skeleton v13.45.2 or earlier adds it to its base test case, with `pollora/framework` at 13.45.2 or later; updating the framework does not change the project's own `tests/TestCase.php`. Laravel sets the trait up and tears it down, under Pest too: ```php // tests/TestCase.php @@ -316,7 +316,7 @@ final class FooterTest extends TestCase } ``` -With the skeleton's unchanged `TestCase` and without the two attributes, the second test fails with the error above. `composer test` does not run this directory: add `vendor/bin/phpunit tests/Isolated` to your CI job. To keep Pest syntax, the other option is one `php artisan test ` run per file; tests of the same file still share a process. +With a `TestCase` that does not isolate the hooks and without the two attributes, the second test fails with the error above. `composer test` does not run this directory: add `vendor/bin/phpunit tests/Isolated` to your CI job. To keep Pest syntax, the other option is one `php artisan test ` run per file; tests of the same file still share a process. ## Fakes and helpers