diff --git a/CHANGELOG.md b/CHANGELOG.md index 71d0c8a7f20..068a3b69b3f 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased](https://github.com/Pollora/pollora/compare/v13.45.2...main) +### Changed +- `tests/TestCase.php` uses `Pollora\Testing\IsolatesWordPressHooks`, so the WordPress hooks of one feature test no longer reach the next one ([framework#741](https://github.com/Pollora/framework/issues/741)), and `tests/Feature/WordPressHookIsolationTest.php` checks it. A hook added by a file first included during a test is removed with the test. An existing project adds the `use` line to its own `tests/TestCase.php` +- Requires `pollora/framework` ^13.45.2, the first release with the trait + ## [v13.45.2](https://github.com/Pollora/pollora/compare/v13.45.1...v13.45.2) - 2026-12-04 ### Changed diff --git a/composer.json b/composer.json index cef3b701397..678743ebcc0 100755 --- a/composer.json +++ b/composer.json @@ -28,7 +28,7 @@ "laravel/framework": "^13.45", "laravel/sanctum": "^4.3 || ^5.0", "laravel/tinker": "^3.0", - "pollora/framework": "^13.45.1" + "pollora/framework": "^13.45.2" }, "require-dev": { "fakerphp/faker": "^1.23", diff --git a/composer.lock b/composer.lock index 16407470bf2..0660016dc26 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "f0876a234f3c5cceb64b52f3efcd0ebc", + "content-hash": "f4bdbcc7bb1e0afa9d8e802b776ac044", "packages": [ { "name": "barryvdh/laravel-ide-helper", diff --git a/tests/Feature/WordPressHookIsolationTest.php b/tests/Feature/WordPressHookIsolationTest.php new file mode 100644 index 00000000000..2ef01ba9335 --- /dev/null +++ b/tests/Feature/WordPressHookIsolationTest.php @@ -0,0 +1,71 @@ +environment())->toBe('testing'); + + $nextApplication = function (): void { + $this->tearDown(); + $this->setUp(); + }; + + $countCallbacks = fn (): int => array_sum(array_map( + fn (WP_Hook $hook): int => array_sum(array_map(count(...), $hook->callbacks)), + $GLOBALS['wp_filter'], + )); + + $runFooter = function (): void { + // Otherwise theme.json may come from a cache and its filters not run. + wp_clean_theme_json_cache(); + + ob_start(); + + try { + do_action('wp_footer'); + } finally { + ob_end_clean(); + } + }; + + $expectThemeViews = function (): void { + $views = realpath(base_path('themes/'.get_stylesheet().'/resources/views')); + + // A project without a theme in themes/ has no theme views to find. + if ($views !== false) { + expect(array_map(realpath(...), view()->getFinder()->getPaths()))->toContain($views); + } + }; + + add_action('pollora_isolation_probe', '__return_true'); + Action::add('pollora_isolation_probe_facade', '__return_true'); + + expect(has_action('pollora_isolation_probe'))->toBeTrue() + ->and(has_action('pollora_isolation_probe_facade'))->toBeTrue(); + + $nextApplication(); + + // The first application may be the one that loaded WordPress: callbacks are + // compared between the two that follow it. + $callbacks = $countCallbacks(); + + expect(has_action('pollora_isolation_probe'))->toBeFalse() + ->and(has_action('pollora_isolation_probe_facade'))->toBeFalse(); + + // A callback left by a flushed application would fail to resolve here. + $runFooter(); + $expectThemeViews(); + + $nextApplication(); + + expect($countCallbacks())->toBe($callbacks); + + $runFooter(); + $expectThemeViews(); +}); diff --git a/tests/TestCase.php b/tests/TestCase.php index c5195662f30..b2b37250163 100755 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -5,5 +5,11 @@ namespace Tests; use Illuminate\Foundation\Testing\TestCase as BaseTestCase; - -abstract class TestCase extends BaseTestCase {} +use Pollora\Testing\IsolatesWordPressHooks; + +abstract class TestCase extends BaseTestCase +{ + // WordPress is loaded once per test process, an application is built for + // each test: without this, the hooks of one test reach the next ones. + use IsolatesWordPressHooks; +}