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" 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; } 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 + ); + } }