Skip to content
Merged
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
10 changes: 7 additions & 3 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,11 @@ jobs:
matrix:
os: [ ubuntu-latest, windows-latest ]
php: [ 8.2, 8.3, 8.4, 8.5 ]
stability: [ prefer-lowest, prefer-stable ]
guzzle:
- { constraint: '^7.6', stability: prefer-lowest }
- { constraint: '^8.0', stability: prefer-stable }

name: P${{ matrix.php }} - ${{ matrix.stability }} - ${{ matrix.os }}
name: P${{ matrix.php }} - Guzzle ${{ matrix.guzzle.constraint }} - ${{ matrix.os }}

steps:
- name: Checkout code
Expand All @@ -47,7 +49,9 @@ jobs:
echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"

- name: Install dependencies
shell: bash
run: |
composer update --${{ matrix.stability }} --prefer-dist --no-interaction
composer require guzzlehttp/guzzle:${{ matrix.guzzle.constraint }} --no-update
composer update --${{ matrix.guzzle.stability }} --prefer-dist --no-interaction
- name: Execute tests
run: vendor/bin/pest -p
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
"homepage": "https://github.com/saloonphp/saloon",
"require": {
"php": "^8.2",
"guzzlehttp/guzzle": "^7.6",
"guzzlehttp/promises": "^1.5 || ^2.0",
"guzzlehttp/psr7": "^2.0",
"guzzlehttp/guzzle": "^7.6 || ^8.0",
"guzzlehttp/promises": "^1.5 || ^2.0 || ^3.0",
"guzzlehttp/psr7": "^2.0 || ^3.0",
"psr/http-factory": "^1.0",
"psr/http-message": "^1.1 || ^2.0"
},
Expand Down
12 changes: 10 additions & 2 deletions src/Http/Senders/GuzzleSender.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ class GuzzleSender implements Sender

/**
* Guzzle's Handler Stack.
*
* @var HandlerStack<callable(RequestInterface, array<array-key, mixed>): PromiseInterface<ResponseInterface, mixed>>
*/
protected HandlerStack $handlerStack;

Expand Down Expand Up @@ -84,6 +86,8 @@ protected function createGuzzleClient(): GuzzleClient

/**
* The default handler stack used by the underlying Guzzle client
*
* @return HandlerStack<callable(RequestInterface, array<array-key, mixed>): PromiseInterface<ResponseInterface, mixed>>
*/
protected function defaultHandlerStack(): HandlerStack
{
Expand Down Expand Up @@ -118,7 +122,7 @@ public function send(PendingRequest $pendingRequest): Response
// Sometimes, Guzzle will throw a RequestException without a response. This
// means that it was fatal, so we should still throw a fatal request exception.

$guzzleResponse = $exception->getResponse();
$guzzleResponse = method_exists($exception, 'getResponse') ? $exception->getResponse() : null;

if (is_null($guzzleResponse)) {
throw new FatalRequestException($exception, $pendingRequest);
Expand Down Expand Up @@ -166,7 +170,7 @@ function (TransferException $guzzleException) use ($pendingRequest, $psrRequest)
// Sometimes, Guzzle will throw a RequestException without a response. This
// means that it was fatal, so we should still throw a fatal request exception.

$guzzleResponse = $guzzleException->getResponse();
$guzzleResponse = method_exists($guzzleException, 'getResponse') ? $guzzleException->getResponse() : null;

if (is_null($guzzleResponse)) {
throw new FatalRequestException($guzzleException, $pendingRequest);
Expand Down Expand Up @@ -211,6 +215,8 @@ public function addMiddleware(callable $callable, string $name = ''): static
/**
* Overwrite the entire handler stack.
*
* @param HandlerStack<callable(RequestInterface, array<array-key, mixed>): PromiseInterface<ResponseInterface, mixed>> $handlerStack
*
* @return $this
*/
public function setHandlerStack(HandlerStack $handlerStack): static
Expand All @@ -222,6 +228,8 @@ public function setHandlerStack(HandlerStack $handlerStack): static

/**
* Get the handler stack.
*
* @return HandlerStack<callable(RequestInterface, array<array-key, mixed>): PromiseInterface<ResponseInterface, mixed>>
*/
public function getHandlerStack(): HandlerStack
{
Expand Down
2 changes: 0 additions & 2 deletions tests/Feature/Body/HasMultipartBodyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@
expect((string)$guzzleRequest->getBody())->toContain(
'X-Saloon: Yee-haw!',
'Content-Disposition: form-data; name="nickname"; filename="user.txt"',
'Content-Length: 3',
'Sam',
);

Expand Down Expand Up @@ -135,7 +134,6 @@
expect($guzzleRequest->getBody()->getContents())->toContain(
'X-Saloon: Yee-haw!',
'Content-Disposition: form-data; name="nickname"; filename="user.txt"',
'Content-Length: 3',
'Sam',
'Alfie',
'Tom',
Expand Down
4 changes: 2 additions & 2 deletions tests/Feature/GuzzleSenderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
$saloonStack = invade($handlerStack)->stack;
$defaultStack = invade(HandlerStack::create())->stack;

expect($saloonStack)->toHaveSameSize($defaultStack)->toHaveCount(4);
expect($saloonStack)->toHaveSameSize($defaultStack);

expect($saloonStack[0][1])->toBe($defaultStack[0][1]);
expect($saloonStack[1][1])->toBe($defaultStack[1][1]);
Expand Down Expand Up @@ -116,7 +116,7 @@
$saloonStack = invade($saloonConfig['handler'])->stack;
$defaultStack = invade($defaultConfig['handler'])->stack;

expect($saloonStack)->toHaveSameSize($defaultStack)->toHaveCount(4);
expect($saloonStack)->toHaveSameSize($defaultStack);
});

test('you can set a custom handler stack on the guzzle sender', function () {
Expand Down
4 changes: 2 additions & 2 deletions tests/Feature/RetryConnectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@
$connector = new RetryConnector(5, handleRetry: function (Exception $exception, Request $request) use (&$index) {
$index++;

$request->headers()->add('X-Test-Index', $index);
$request->headers()->add('X-Test-Index', (string) $index);

return true;
});
Expand All @@ -230,7 +230,7 @@
$requestCount = 0;

$connector = new RetryConnector(6, handleRetry: function (Exception $exception, Request $request) use (&$exceptions, &$index) {
$request->headers()->add('X-Yee-Haw', $index++);
$request->headers()->add('X-Yee-Haw', (string) $index++);

return true;
});
Expand Down
4 changes: 2 additions & 2 deletions tests/Feature/RetryRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@
$response = $connector->send(new RetryUserRequest(5, handleRetry: function (Exception $exception, Request $request) use (&$index) {
$index++;

$request->headers()->add('X-Test-Index', $index);
$request->headers()->add('X-Test-Index', (string) $index);

return true;
}));
Expand All @@ -234,7 +234,7 @@
});

$request = new HeaderErrorRetryRequest(6, handleRetry: function (Exception $exception, Request $request) use (&$exceptions, &$index) {
$request->headers()->add('X-Yee-Haw', $index++);
$request->headers()->add('X-Yee-Haw', (string) $index++);

return true;
});
Expand Down
4 changes: 2 additions & 2 deletions tests/Feature/SendAndRetryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@
$response = $connector->sendAndRetry(new UserRequest, 5, 0, function (Exception $exception, Request $request) use (&$index) {
$index++;

$request->headers()->add('X-Test-Index', $index);
$request->headers()->add('X-Test-Index', (string) $index);

return true;
});
Expand All @@ -258,7 +258,7 @@
$index = 0;

$response = $connector->sendAndRetry($request, 6, 0, function (Exception $exception, Request $request) use (&$exceptions, &$index) {
$request->headers()->add('X-Yee-Haw', $index++);
$request->headers()->add('X-Yee-Haw', (string) $index++);

return true;
});
Expand Down
2 changes: 1 addition & 1 deletion tests/Fixtures/Senders/ArraySender.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function send(PendingRequest $pendingRequest): \Saloon\Http\Response
/** @var class-string<\Saloon\Http\Response> $responseClass */
$responseClass = $pendingRequest->getResponseClass();

return $responseClass::fromPsrResponse(new GuzzleResponse(200, ['X-Fake' => true], 'Default'), $pendingRequest, $pendingRequest->createPsrRequest());
return $responseClass::fromPsrResponse(new GuzzleResponse(200, ['X-Fake' => 'true'], 'Default'), $pendingRequest, $pendingRequest->createPsrRequest());
}

/**
Expand Down
Loading