From 1079caa2ea257dde74a5541b32084e3925b281ee Mon Sep 17 00:00:00 2001 From: Jean Galea <1651502+jgalea@users.noreply.github.com> Date: Thu, 28 May 2026 21:51:34 +0200 Subject: [PATCH 1/3] fix: make handler parameter nullable in WpClient constructor Allows php-http/discovery's ClassDiscovery to instantiate WpClient without arguments. When null is passed, the constructor falls back to HandlerStack::createDefault(). Closes #1 --- src/WpClient.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/WpClient.php b/src/WpClient.php index a6253f6..bc3961d 100644 --- a/src/WpClient.php +++ b/src/WpClient.php @@ -27,14 +27,15 @@ class WpClient implements ClientInterface /** * Constructor. * - * @param HandlerInterface $handler The handler to use for dispatching requests and receiving responses. - * @param UriInterface|null $baseUri Optional base URI for all relative requests sent using this client. + * @param HandlerInterface|null $handler The handler to use for dispatching requests and receiving responses. + * Defaults to {@link HandlerStack::createDefault()} when null. + * @param UriInterface|null $baseUri Optional base URI for all relative requests sent using this client. * * @throws InvalidArgumentException If the "base_uri" option is present and is not a valid URI. */ - public function __construct(HandlerInterface $handler, ?UriInterface $baseUri = null) + public function __construct(?HandlerInterface $handler = null, ?UriInterface $baseUri = null) { - $this->handler = $handler; + $this->handler = $handler ?? HandlerStack::createDefault(); $this->baseUri = $baseUri; } From db7aa4bbcd7454883b05f179eb265ed470bb5295 Mon Sep 17 00:00:00 2001 From: Jean Galea <1651502+jgalea@users.noreply.github.com> Date: Fri, 26 Jun 2026 11:33:50 +0200 Subject: [PATCH 2/3] ci: declare allow-plugins so composer update stops failing composer.json didn't declare allow-plugins, so the non-interactive composer update in CI aborted on the phpcodesniffer-installer and package-versions-deprecated plugins. Allow-list both. --- composer.json | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/composer.json b/composer.json index 1e09dc9..1f54edd 100644 --- a/composer.json +++ b/composer.json @@ -28,6 +28,12 @@ "johnpbloch/wordpress-core": ">=5.5", "humanmade/psalm-plugin-wordpress": "^2.0" }, + "config": { + "allow-plugins": { + "dealerdirect/phpcodesniffer-composer-installer": true, + "composer/package-versions-deprecated": true + } + }, "autoload": { "psr-4": { "RebelCode\\WordPress\\Http\\": "src" From d225c40631733e8c37ec16bdd2fe3132dfd3d5ac Mon Sep 17 00:00:00 2001 From: Jean Galea <1651502+jgalea@users.noreply.github.com> Date: Fri, 26 Jun 2026 13:36:36 +0200 Subject: [PATCH 3/3] test: load WordPress' Requests 2.0 layout in the test bootstrap WordPress 6.2 moved the bundled Requests library to wp-includes/Requests/src and renamed the classes to the WpOrg\Requests namespace. The bootstrap hardcoded the old wp-includes/Requests/Utility paths, so PhpUnit fatally errored on any WP core that Composer resolved at 6.2+. Load the new autoloader when present, fall back to the legacy files otherwise, and reference the modern class name in the WpHandler test. --- tests/WpHandlerTest.php | 4 ++-- tests/bootstrap.php | 25 ++++++++++++++++++++----- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/tests/WpHandlerTest.php b/tests/WpHandlerTest.php index 310ec31..59d9f32 100644 --- a/tests/WpHandlerTest.php +++ b/tests/WpHandlerTest.php @@ -11,7 +11,7 @@ use RebelCode\Psr7\Uri; use RebelCode\WordPress\Http\HandlerInterface; use RebelCode\WordPress\Http\WpHandler; -use Requests_Utility_CaseInsensitiveDictionary; +use WpOrg\Requests\Utility\CaseInsensitiveDictionary; use WP_Error; use WP_Mock; @@ -58,7 +58,7 @@ public function testHandle() { $statusCode = 201; $statusReason = 'Created'; - $responseHeaders = new Requests_Utility_CaseInsensitiveDictionary([ + $responseHeaders = new CaseInsensitiveDictionary([ 'Sam' => 'Eggs, Ham', 'Cat' => 'Hat', ]); diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 3c681cf..913f750 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -7,10 +7,25 @@ WP_Mock::bootstrap(); -if (!class_exists('Requests_Utility_CaseInsensitiveDictionary')) { - require WORDPRESS_DIR . '/wp-includes/Requests/Utility/CaseInsensitiveDictionary.php'; -} +/* + * Load the Requests HTTP library bundled with WordPress. WordPress 6.2 shipped Requests 2.0, + * which moved the library under wp-includes/Requests/src and renamed the classes from the flat + * Requests_* names to the WpOrg\Requests namespace. Support both layouts so the suite runs + * against whichever WordPress version Composer resolves across the PHP matrix. + */ +$newAutoload = WORDPRESS_DIR . '/wp-includes/Requests/src/Autoload.php'; + +if (file_exists($newAutoload)) { + require_once $newAutoload; + WpOrg\Requests\Autoload::register(); +} else { + require_once WORDPRESS_DIR . '/wp-includes/Requests/Utility/CaseInsensitiveDictionary.php'; -if (!class_exists('Requests_Exception')) { - require WORDPRESS_DIR . '/wp-includes/Requests/Exception.php'; + // Pre-6.2 WordPress only defines the legacy class name; alias it to the modern one the tests use. + if (!class_exists(WpOrg\Requests\Utility\CaseInsensitiveDictionary::class)) { + class_alias( + 'Requests_Utility_CaseInsensitiveDictionary', + WpOrg\Requests\Utility\CaseInsensitiveDictionary::class + ); + } }