Skip to content

Only use the server-command router when there is an index.php to route to - #371

Open
softglazee wants to merge 2 commits into
wp-cli:mainfrom
softglazee:fix/php-server-router-without-index
Open

softglazee wants to merge 2 commits into
wp-cli:mainfrom
softglazee:fix/php-server-router-without-index

Conversation

@softglazee

@softglazee softglazee commented Oct 24, 2026 •

Copy link
Copy Markdown

Problem

Since #363, start_php_server() passes the router of wp-cli/server-command to php -S whenever that package is in the vendor directory of the project under test. The router sends every request for a missing file to index.php. In a plain directory of files without an index.php, that require_once fails, so a request for a missing file gets a fatal error instead of a 404: a 500 when errors are not displayed, or an error page with a 200 when they are.

Each command's own CI does not install wp-cli/server-command, so this does not show there. The automated tests of the bundle do have it, and "Install from a remote zip URL that returns 404" in wp-cli/package-command has failed there since at least 20 September, for example in the run of 23 October:
https://github.com/wp-cli/automated-tests/actions/runs/39875417033

$ wp package install http://localhost:8080/missing.zip
Error: Couldn't download package from 'http://localhost:8080/missing.zip' (HTTP code 500).

Changes

  • start_php_server() only uses the server-command router when the served directory has an index.php, so a WordPress installation still gets pretty permalinks and a plain directory is served as-is.
  • Two new scenarios in behat-steps.feature put a small router in the run directory's vendor/wp-cli/server-command/: without an index.php, a missing file must be a 404; with one, a request for a pretty permalink must go through the router.

Testing

  • With wp-cli/server-command in the vendor directory, as in the automated tests: without this change, "returns 404 for a missing file" and the new scenario without an index.php fail with the fatal error from the router. With it, all 4 "a PHP built-in web server" scenarios pass. They also pass without wp-cli/server-command installed.
  • wp-cli/package-command with wp-cli/server-command installed and the released wp-cli-tests: "Install from a remote zip URL that returns 404" fails. With this change in the vendored copy, it passes, together with the other 3 remote zip scenarios.
  • composer phpcs, composer phpstan (including the PHP blocks in feature files), composer lint and gherkin-lint pass.

Summary by CodeRabbit

  • Bug Fixes
    • Improved request handling in the PHP built-in server: requests to missing paths now follow application routing when an entry point is present, while missing files return a not-found response when it is absent.
    • Static-file directories continue to be served without application routing. This makes responses more consistent with the contents and setup of the directory being served.

…e 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.
@softglazee
softglazee requested a review from a team as a code owner October 24, 2026 00:23
@github-actions

Copy link
Copy Markdown
Contributor

Hello! 👋

Thanks for opening this pull request! Please check out our contributing guidelines. We appreciate you taking the initiative to contribute to this project.

Contributing isn't limited to just code. We encourage you to contribute in the way that best fits your abilities, by writing tutorials, giving a demo at your local meetup, helping other users with their support questions, or revising our documentation.

Here are some useful Composer commands to get you started:

  • composer install: Install dependencies.
  • composer test: Run the full test suite.
  • composer phpcs: Check for code style violations.
  • composer phpcbf: Automatically fix code style violations.
  • composer phpunit: Run unit tests.
  • composer behat: Run behavior-driven tests.

To run a single Behat test, you can use the following command:

# Run all tests in a single file
composer behat features/some-feature.feature

# Run only a specific scenario (where 123 is the line number of the "Scenario:" title)
composer behat features/some-feature.feature:123

You can find a list of all available Behat steps in our handbook.

@coderabbitai

coderabbitai Bot commented Oct 24, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The PHP built-in server setup looks up a router only when the served directory contains index.php. Two Behat scenarios check missing-path requests with and without that file.

Changes: PHP built-in server router selection

Layer / File(s) Summary
Router selection and scenario coverage
src/Context/FeatureContext.php, features/behat-steps.feature
start_php_server() selects a router only when the served directory contains index.php. The scenarios check for a 404 without router output when the file is absent, and a 200 response with router and index output when it is present.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Suggested reviewers: swissspidy

Merge Risk: Minimal · up to 8edd1

The change makes the test PHP server use the WordPress router only when there is an index.php to route to. This avoids a fatal error on requests for missing files in plain directories. It affects test infrastructure only, and I found no remaining merge-blocking risk.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title states the main change: the server-command router is now used only when index.php exists to route to. The raw summary confirms that FeatureContext::start_php_server() selects the router only…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title states the main change: the server-command router is now used only when index.php exists to route to. The raw summary confirms that FeatureContext::start_php_server() selects the router only when the served directory contains index.php, and that two scenarios cover the 404 and index.php cases. The title is specific and matches the changeset.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: f86e8f05-7b4b-464e-864c-ba4e6690db7a
Commits

Reviewing files that changed from the base of the PR and between 4f4c0d2 and 8edd1fc.

Files selected for processing: 2

  • features/behat-steps.feature
  • src/Context/FeatureContext.php

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

@github-actions github-actions Bot added bug Something isn't working scope:testing Related to testing labels Oct 24, 2026
@codecov

codecov Bot commented Oct 24, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/Context/FeatureContext.php 0.00% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@swissspidy swissspidy added this to the 5.5.3 milestone Nov 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working scope:testing Related to testing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants