@@ -492,6 +492,78 @@ Feature: Test that WP-CLI Behat steps work as expected
492492 404 Not Found
493493 """
494494
495+ Scenario : Test "a PHP built-in web server" step without an index.php does not use the server-command router
496+ Given an empty directory
497+ And a vendor/wp-cli/server-command/router.php file:
498+ """
499+ <?php
500+ // Like the router of wp-cli/server-command, send requests for missing files to index.php.
501+ $root = (string) ( $_SERVER['DOCUMENT_ROOT'] ?? '' );
502+ $path = (string) parse_url( (string) ( $_SERVER['REQUEST_URI'] ?? '/' ), PHP_URL_PATH );
503+ if ( is_file( $root . $path ) ) {
504+ return false;
505+ }
506+ echo 'Routed by router.php: ';
507+ require $root . '/index.php';
508+ """
509+ And a fetch.php file:
510+ """
511+ <?php
512+ $url = (string) ( $_SERVER['argv'][1] ?? '' );
513+ $headers = @get_headers( $url );
514+ echo is_array( $headers ) ? $headers[0] : 'no response', PHP_EOL, (string) @file_get_contents( $url );
515+ """
516+ And a PHP built-in web server
517+
518+ # The router would require a missing index.php, so the directory is served as-is.
519+ When I run `php fetch.php http://localhost:8080/missing.html`
520+ Then STDOUT should contain:
521+ """
522+ 404 Not Found
523+ """
524+ And STDOUT should not contain:
525+ """
526+ Routed by router.php
527+ """
528+
529+ Scenario : Test "a PHP built-in web server" step with an index.php uses the server-command router
530+ Given an empty directory
531+ And a vendor/wp-cli/server-command/router.php file:
532+ """
533+ <?php
534+ // Like the router of wp-cli/server-command, send requests for missing files to index.php.
535+ $root = (string) ( $_SERVER['DOCUMENT_ROOT'] ?? '' );
536+ $path = (string) parse_url( (string) ( $_SERVER['REQUEST_URI'] ?? '/' ), PHP_URL_PATH );
537+ if ( is_file( $root . $path ) ) {
538+ return false;
539+ }
540+ echo 'Routed by router.php: ';
541+ require $root . '/index.php';
542+ """
543+ And an index.php file:
544+ """
545+ <?php
546+ echo 'Hello from index.php';
547+ """
548+ And a fetch.php file:
549+ """
550+ <?php
551+ $url = (string) ( $_SERVER['argv'][1] ?? '' );
552+ $headers = @get_headers( $url );
553+ echo is_array( $headers ) ? $headers[0] : 'no response', PHP_EOL, (string) @file_get_contents( $url );
554+ """
555+ And a PHP built-in web server
556+
557+ When I run `php fetch.php http://localhost:8080/hello-world/`
558+ Then STDOUT should contain:
559+ """
560+ 200 OK
561+ """
562+ And STDOUT should contain:
563+ """
564+ Routed by router.php: Hello from index.php
565+ """
566+
495567 @require-wp
496568 Scenario : Test background process launch
497569 Given a WP installation
0 commit comments