Skip to content

Fix test global state mutation for $_REQUEST['meta-box-loader']#484

Merged
galbus merged 7 commits intos-7904-el-libero-wordpress-issues-since-updatefrom
copilot/sub-pr-483
Feb 8, 2026
Merged

Fix test global state mutation for $_REQUEST['meta-box-loader']#484
galbus merged 7 commits intos-7904-el-libero-wordpress-issues-since-updatefrom
copilot/sub-pr-483

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Feb 8, 2026

Two test methods were mutating $_REQUEST['meta-box-loader'] and using unset() for cleanup, which could cause cross-test interference if the key was set by other tests or the WordPress test bootstrap.

Changes

  • Wrapped test logic in try/finally blocks with proper state restoration
  • Use isset() to track whether $_REQUEST['meta-box-loader'] existed before modification
  • Restore original value if key was set, or ensure it remains unset if it wasn't

Implementation

// Save the original state to restore later
$hadMetaBoxLoader = isset($_REQUEST['meta-box-loader']);
$originalMetaBoxLoader = $hadMetaBoxLoader ? $_REQUEST['meta-box-loader'] : null;

try {
    // Test logic that mutates $_REQUEST['meta-box-loader']
    $_REQUEST['meta-box-loader'] = '1';
    $result = Core::onAddOrUpdatePost($postId);
    $this->assertFalse($result);
} finally {
    // Restore original state
    if ($hadMetaBoxLoader) {
        $_REQUEST['meta-box-loader'] = $originalMetaBoxLoader;
    } else {
        unset($_REQUEST['meta-box-loader']);
    }
}

Applied to:

  • onAddOrUpdatePostSkipsMetaBoxLoaderRequest
  • onAddOrUpdatePostRunsWithoutMetaBoxLoader

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 6 commits February 8, 2026 22:04
…effects

Co-authored-by: galbus <665537+galbus@users.noreply.github.com>
Co-authored-by: galbus <665537+galbus@users.noreply.github.com>
Co-authored-by: galbus <665537+galbus@users.noreply.github.com>
Co-authored-by: galbus <665537+galbus@users.noreply.github.com>
Co-authored-by: galbus <665537+galbus@users.noreply.github.com>
Co-authored-by: galbus <665537+galbus@users.noreply.github.com>
Copilot AI changed the title [WIP] WIP address feedback on REST API 404 responses investigation PR Fix test global state mutation for $_REQUEST['meta-box-loader'] Feb 8, 2026
Copilot AI requested a review from galbus February 8, 2026 22:09
@galbus galbus marked this pull request as ready for review February 8, 2026 22:24
@galbus galbus merged commit 3fb4ab8 into s-7904-el-libero-wordpress-issues-since-update Feb 8, 2026
@galbus galbus deleted the copilot/sub-pr-483 branch February 8, 2026 22:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants