Skip to content

Commit 433009f

Browse files
authored
Merge branch 'main' into claude/clever-lamport-8md283
2 parents c5e051b + db43a80 commit 433009f

6 files changed

Lines changed: 114 additions & 30 deletions

File tree

‎.github/workflows/copilot-setup-steps.yml‎

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,12 @@ jobs:
4646
id: check_behat_file
4747
run: echo "files_exists=$(test -f behat.yml && echo true || echo false)" >> "$GITHUB_OUTPUT"
4848

49-
# Downloading and starting the database server is the slowest part of the
50-
# setup and it is independent of PHP and Composer, so it runs in the
51-
# background and is waited for right before the test database is prepared.
49+
# Not run in the background: Copilot code review builds its workflow from
50+
# these steps and failed validation while they used `background` and
51+
# `wait-all`. Also, the action unpacks its binaries with the system `tar`,
52+
# which fails to load libpcre2 while setup-php upgrades it with apt.
5253
- name: Setup MySQL Server
5354
if: steps.check_behat_file.outputs.files_exists == 'true'
54-
background: true
5555
uses: shogo82148/actions-setup-mysql@13a38f2af408e58a0c80168fc620a63a15357339 # v1
5656
with:
5757
mysql-version: '8.0' # Standard MySQL version for these tests
@@ -77,9 +77,6 @@ jobs:
7777
env:
7878
COMPOSER_ROOT_VERSION: dev-${{ github.event.repository.default_branch }}
7979

80-
- name: Wait for the MySQL server
81-
wait-all:
82-
8380
- name: Remove system MySQL binary
8481
if: steps.check_behat_file.outputs.files_exists == 'true'
8582
run: sudo rm -f /usr/bin/mysql /usr/bin/mysqldump
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
---
2+
name: Milestone Merged Pull Requests
3+
4+
'on':
5+
pull_request_target:
6+
types: [closed]
7+
branches:
8+
- main
9+
- master
10+
11+
permissions:
12+
issues: write
13+
pull-requests: write
14+
15+
jobs:
16+
milestone:
17+
uses: wp-cli/.github/.github/workflows/reusable-milestone-merged-prs.yml@main

‎features/behat-steps.feature‎

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

‎phpcs.xml.dist‎

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -114,15 +114,8 @@
114114

115115
<!-- These are stand-alone files that are copied into the test run directory and
116116
executed by the child WP-CLI process, not loaded as part of this package.
117-
They declare a class once per supported Requests major version, and their
118-
method signatures are dictated by the transport interface they implement,
117+
Their method signatures are dictated by the transport interface they implement,
119118
so unused parameters cannot be dropped. -->
120-
<rule ref="Generic.Files.OneObjectStructurePerFile">
121-
<exclude-pattern>*/src/Context/templates/*</exclude-pattern>
122-
</rule>
123-
<rule ref="Generic.Classes.DuplicateClassName">
124-
<exclude-pattern>*/src/Context/templates/*</exclude-pattern>
125-
</rule>
126119
<rule ref="Generic.CodeAnalysis.UnusedFunctionParameter">
127120
<exclude-pattern>*/src/Context/templates/*</exclude-pattern>
128121
</rule>

‎src/Context/FeatureContext.php‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2548,10 +2548,12 @@ public function start_php_server( $subdir = '' ): void {
25482548

25492549
// Route requests through the router script of wp-cli/server-command when
25502550
// it is available, so that a WordPress installation gets pretty permalinks.
2551-
// Without a router, PHP's built-in web server serves the directory as-is,
2552-
// which is what a plain directory of static files needs. Passing a router
2553-
// path that does not exist would make every request fail with a fatal error.
2554-
$router = $this->get_php_server_router();
2551+
// The router sends every request for a missing file to index.php, so it is
2552+
// only used when the directory has one. Without a router, PHP's built-in
2553+
// web server serves the directory as-is, which is what a plain directory of
2554+
// static files needs, and a missing file is a 404. Passing a router path
2555+
// that does not exist would make every request fail with a fatal error.
2556+
$router = is_file( $dir . 'index.php' ) ? $this->get_php_server_router() : null;
25552557
if ( null !== $router ) {
25562558
$cmd .= ' ' . escapeshellarg( $router );
25572559
}

‎src/Context/templates/mock-requests.php‎

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -46,20 +46,23 @@ public static function test( $capabilities = array() ) {
4646
}
4747
}
4848

49-
if ( interface_exists( '\WpOrg\Requests\Transport' ) ) {
50-
class WP_CLI_Tests_Mock_Requests_Transport implements \WpOrg\Requests\Transport {
51-
use WP_CLI_Tests_Mock_Requests_Trait;
52-
}
53-
} else {
54-
class WP_CLI_Tests_Mock_Requests_Transport implements \Requests_Transport {
55-
use WP_CLI_Tests_Mock_Requests_Trait;
56-
}
57-
}
58-
5949
WP_CLI::add_hook(
6050
'http_request_options',
6151
static function ( $options ) {
62-
$options['transport'] = new WP_CLI_Tests_Mock_Requests_Transport();
52+
if ( class_exists( '\WP_CLI\RequestsLibrary' ) && method_exists( '\WP_CLI\RequestsLibrary', 'register_autoloader' ) ) {
53+
\WP_CLI\RequestsLibrary::register_autoloader();
54+
}
55+
56+
if ( interface_exists( '\WpOrg\Requests\Transport' ) ) {
57+
$options['transport'] = new class() implements \WpOrg\Requests\Transport {
58+
use WP_CLI_Tests_Mock_Requests_Trait;
59+
};
60+
} else {
61+
$options['transport'] = new class() implements \Requests_Transport {
62+
use WP_CLI_Tests_Mock_Requests_Trait;
63+
};
64+
}
65+
6366
return $options;
6467
}
6568
);

0 commit comments

Comments
 (0)