Skip to content

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

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

softglazee wants to merge 1 commit 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: missing paths now follow the configured application routing behavior when an entry point is present, while missing files return a not-found response when it is absent. This helps ensure server responses match the application’s setup.

…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

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ 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: a33dcc08-68de-4eb9-94c7-802ee8196360
📥 Commits

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

📒 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.

📝 Walkthrough

The PHP built-in server setup now looks up the router only when the served directory contains index.php. Two Behat scenarios cover requests for missing paths 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() sets the router to null when the served directory lacks index.php. Behat scenarios check that a missing path returns 404 without router output in that case, and returns 200 with router and index.php output when the file is present.

Priority: ➖ Normal

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

Change: Bug fix

Suggested reviewers: swissspidy

Merge Risk: ⚪ Minimal · up to 4f4c0

No actionable merge-blocking issue is established; the change appears mergeable after normal checks.

Pre-merge checks: Passed 5
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely describes the main change: using the server-command router only when the served directory contains index.php.
Docstring Coverage Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 1 files. (1 skipped: 1 …
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: Docstring Coverage

Explanation

Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 1 files. (1 skipped: 1 unsupported.)

✨ Finishing Touches: 💡 1
🛠️ Fix failing CI checks: 💡
  • Commit to this branch
  • Create a new PR
🧪 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

Comment @coderabbitai help to get the list of available commands.

@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!

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.

1 participant