Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
9 changes: 5 additions & 4 deletions src/WpClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
4 changes: 2 additions & 2 deletions tests/WpHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -58,7 +58,7 @@ public function testHandle()
{
$statusCode = 201;
$statusReason = 'Created';
$responseHeaders = new Requests_Utility_CaseInsensitiveDictionary([
$responseHeaders = new CaseInsensitiveDictionary([
'Sam' => 'Eggs, Ham',
'Cat' => 'Hat',
]);
Expand Down
25 changes: 20 additions & 5 deletions tests/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
}
}
Loading