From 4f4c0d2be7aad10aa75af4bc350cdabb49e9625e Mon Sep 17 00:00:00 2001 From: softglazee Date: Sat, 24 Oct 2026 05:17:39 +0500 Subject: [PATCH] Only use the server-command router when there is an index.php to route to The router of wp-cli/server-command sends every request for a missing file to index.php. When the project under test has wp-cli/server-command in its vendor directory, as in the automated tests of the bundle, the "a PHP built-in web server" step also used the router for a plain directory of files without an index.php. A request for a missing file then failed with a fatal error (a 500, or an error page with a 200 when errors are displayed) instead of a 404. That is why "Install from a remote zip URL that returns 404" in wp-cli/package-command fails in the automated tests. --- features/behat-steps.feature | 72 ++++++++++++++++++++++++++++++++++ src/Context/FeatureContext.php | 10 +++-- 2 files changed, 78 insertions(+), 4 deletions(-) diff --git a/features/behat-steps.feature b/features/behat-steps.feature index 1620e011..e6bcea87 100644 --- a/features/behat-steps.feature +++ b/features/behat-steps.feature @@ -462,6 +462,78 @@ Feature: Test that WP-CLI Behat steps work as expected 404 Not Found """ + Scenario: Test "a PHP built-in web server" step without an index.php does not use the server-command router + Given an empty directory + And a vendor/wp-cli/server-command/router.php file: + """ + get_php_server_router(); + // The router sends every request for a missing file to index.php, so it is + // only used when the directory has one. Without a router, PHP's built-in + // web server serves the directory as-is, which is what a plain directory of + // static files needs, and a missing file is a 404. Passing a router path + // that does not exist would make every request fail with a fatal error. + $router = is_file( $dir . 'index.php' ) ? $this->get_php_server_router() : null; if ( null !== $router ) { $cmd .= ' ' . escapeshellarg( $router ); }