Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

71 changes: 71 additions & 0 deletions tests/Feature/WordPressHookIsolationTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?php

declare(strict_types=1);

use Pollora\Support\Facades\Action;

// Guards the isolation `Tests\TestCase` gets from `IsolatesWordPressHooks`.
// The whole scenario is one test that builds its applications itself, so it
// holds when run alone, filtered or after any other test.
it('does not leak WordPress hooks from one application to the next', function (): void {
// The load of WordPress is only recorded in this environment (phpunit.xml).
expect(app()->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();
});
10 changes: 8 additions & 2 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Loading