Skip to content

Commit 4d19bbd

Browse files
committed
test[faustwp]: stop AuthCallbacksTests leaking REQUEST_URI to other test classes
phpunit.xml.dist sets backupGlobals="false", so anything mutated on $_SERVER and $_GET inside one test class persists to the next. Our tearDown was doing 'unset($_SERVER[REQUEST_URI])' as cleanup, which poisoned the cron path that runs during TelemetryCallbacksTests::setUp() (do_action('muplugins_loaded') -> wp-cron -> reads REQUEST_URI). With convertNoticesToExceptions=true, the missing key turned into 9 hard errors on the next test class. Local --filter=AuthCallbacks didn't surface this because TelemetryCallbacks was excluded. CI runs the full suite and caught it on WP 6.5 and Nightly. Fix: snapshot $_SERVER['REQUEST_URI'] and $_GET in setUp; restore them in tearDown. The world is left as we found it, regardless of what the WP test bootstrap or earlier test classes had configured. Verified locally: - Full suite (composer test, single-site + multisite): 126 tests, 291 assertions, all pass. - Regression guard preserved: reverting callbacks.php to site_url() still fails the Bedrock + WP-in-subdirectory tests cleanly. - Without this fix, the same full suite errors 9 times in TelemetryCallbacksTests with 'Undefined array key REQUEST_URI' -- matching the CI failure exactly.
1 parent 47c9f7e commit 4d19bbd

1 file changed

Lines changed: 31 additions & 1 deletion

File tree

plugins/faustwp/tests/integration/AuthCallbacksTests.php

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,31 @@ class AuthCallbacksTests extends \WP_UnitTestCase {
4242
*/
4343
private $original_siteurl = '';
4444

45+
/**
46+
* Snapshots of superglobal values taken in setUp and restored in tearDown.
47+
*
48+
* `phpunit.xml.dist` sets backupGlobals="false" so anything we mutate on
49+
* $_SERVER / $_GET persists across test classes. The WP test bootstrap and
50+
* other test classes downstream of this one (e.g. TelemetryCallbacksTests,
51+
* which triggers wp-cron) depend on REQUEST_URI being defined. Snapshot it
52+
* here so our tearDown leaves the world exactly as we found it.
53+
*
54+
* @var array{request_uri: string|null, get: array<string, mixed>}
55+
*/
56+
private $original_globals = array(
57+
'request_uri' => null,
58+
'get' => array(),
59+
);
60+
4561
public function setUp(): void {
4662
parent::setUp();
4763

4864
self::$captured_redirect = null;
4965
$this->original_siteurl = get_option( 'siteurl' );
66+
$this->original_globals = array(
67+
'request_uri' => isset( $_SERVER['REQUEST_URI'] ) ? (string) $_SERVER['REQUEST_URI'] : null,
68+
'get' => $_GET,
69+
);
5070

5171
// handle_generate_endpoint() calls wp_safe_redirect() and then a bare exit;.
5272
// Redefine wp_safe_redirect via Patchwork to throw a dedicated exception,
@@ -65,7 +85,17 @@ static function ( $location ) {
6585
public function tearDown(): void {
6686
\Patchwork\restoreAll();
6787
update_option( 'siteurl', $this->original_siteurl );
68-
unset( $_SERVER['REQUEST_URI'], $_GET['redirect_uri'] );
88+
89+
// Restore superglobals to whatever the WP test bootstrap (or a prior test
90+
// class) had them at. Unsetting REQUEST_URI here would break the cron path
91+
// in subsequent test classes -- it leaked into TelemetryCallbacksTests on CI.
92+
if ( null === $this->original_globals['request_uri'] ) {
93+
unset( $_SERVER['REQUEST_URI'] );
94+
} else {
95+
$_SERVER['REQUEST_URI'] = $this->original_globals['request_uri'];
96+
}
97+
$_GET = $this->original_globals['get'];
98+
6999
self::$captured_redirect = null;
70100
parent::tearDown();
71101
}

0 commit comments

Comments
 (0)