Skip to content

Managed PHPUnit bootstrap drops init callbacks added during deferred init replay #2007

Description

@chubes4

Problem

The managed wordpress.phpunit bootstrap replays deferred init callbacks from a fixed snapshot. When a plugin's early init callback registers callbacks at later init priorities, those callbacks never execute.

Data Machine Events exposes the normal WordPress pattern:

add_action( 'init', [ $plugin, 'init' ], 0 );
// During init():
add_action( 'init', [ $plugin, 'register_blocks' ], 15 );
add_action( 'init', [ $plugin, 'register_taxonomies' ], 20 );

Under a normal WordPress hook dispatch, the priority-15 and priority-20 callbacks run in the same init action. Under WP Codebox managed PHPUnit, did_action( 'init' ) > 0 but the blocks and taxonomies are absent.

The relevant bootstrap path snapshots/defer-replays callbacks in packages/runtime-playground/src/phpunit-command-handlers.ts around the managed bootstrap's pg_run_deferred_wordpress_hook_callbacks(..., 'init') call.

Expected

Managed PHPUnit replay must preserve normal WP_Hook behavior for callbacks added at later priorities during the same action. It must still execute each deferred callback exactly once and must not rerun callbacks WordPress already dispatched.

Acceptance

  • Add a fixture callback at init priority 0 that registers another callback at priority 15.
  • Prove both callbacks run once in priority order during managed bootstrap.
  • Preserve existing dependency/component plugins_loaded, abilities, and duplicate-bootstrap guarantees.
  • Do not require consumers to preload classes or invoke plugin methods directly.

Discovered while fixing Extra-Chill/data-machine-events#546.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions