diff --git a/examples/bench-plugin/bench-plugin.php b/examples/bench-plugin/bench-plugin.php index e907a99..a3a595c 100644 --- a/examples/bench-plugin/bench-plugin.php +++ b/examples/bench-plugin/bench-plugin.php @@ -10,3 +10,18 @@ function wp_codebox_bench_plugin_value(): int { return 7; } + +add_action( + 'rest_api_init', + static function (): void { + register_rest_route( + 'wp-codebox-bench/v1', + '/value', + array( + 'methods' => 'GET', + 'callback' => static fn (): array => array( 'value' => wp_codebox_bench_plugin_value() ), + 'permission_callback' => '__return_true', + ) + ); + } +); diff --git a/examples/bench-plugin/tests/bench/noop.php b/examples/bench-plugin/tests/bench/noop.php index b28105d..3c5d2bc 100644 --- a/examples/bench-plugin/tests/bench/noop.php +++ b/examples/bench-plugin/tests/bench/noop.php @@ -1,9 +1,13 @@ response_to_data( $response, false ); + return array( 'metrics' => array( - 'fixture_value' => wp_codebox_bench_plugin_value(), + 'fixture_value' => wp_codebox_bench_plugin_value(), + 'rest_route_visible' => isset( $data['value'] ) && 7 === (int) $data['value'] ? 1 : 0, ), 'metadata' => array( 'fixture' => 'bench-plugin', diff --git a/packages/runtime-playground/src/bench-command-handlers.ts b/packages/runtime-playground/src/bench-command-handlers.ts index dfa50bf..bfce4c0 100644 --- a/packages/runtime-playground/src/bench-command-handlers.ts +++ b/packages/runtime-playground/src/bench-command-handlers.ts @@ -155,6 +155,14 @@ foreach ($plugins_to_activate as $plugin_to_activate) { throw new RuntimeException($activation->get_error_message()); } } +if (!empty($plugins_to_activate)) { + do_action('plugins_loaded'); + do_action('init'); +} +if (did_action('rest_api_init')) { + $GLOBALS['wp_rest_server'] = null; + do_action('rest_api_init', rest_get_server()); +} function wp_codebox_bench_run_configured_workload(array $workload, string $plugin_path) { $steps = isset($workload['run']) && is_array($workload['run']) ? $workload['run'] : array($workload); diff --git a/scripts/recipe-bench-smoke.ts b/scripts/recipe-bench-smoke.ts index df01d1c..26af69a 100644 --- a/scripts/recipe-bench-smoke.ts +++ b/scripts/recipe-bench-smoke.ts @@ -87,6 +87,7 @@ assert.equal(scenario.id, "noop") assert.equal(scenario.file, "tests/bench/noop.php") assert.equal(scenario.iterations, 2) assert.equal(scenario.metrics.fixture_value_mean, 7) +assert.equal(scenario.metrics.rest_route_visible_mean, 1) assert.equal(scenario.metadata.fixture, "bench-plugin") const configured = output.benchResults.scenarios[1] assert.equal(configured.id, "configured-env")