Skip to content

Commit

Permalink
Merge branch 'main' into sw_update_co_file
Browse files Browse the repository at this point in the history
  • Loading branch information
arpit-jn authored Aug 5, 2024
2 parents 3039ca1 + 96c4f34 commit a8aa11b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/Utility/HttpRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ public function call(): ResponseInterface

// Used for unit testing: if we're mocking responses and have a callback assigned, invoke that callback with our request and response.
// @codeCoverageIgnoreStart
if ($mockedResponse && method_exists($mockedResponse, 'callback') && is_callable($mockedResponse->callback)) { // @phpstan-ignore-line
if ($mockedResponse && property_exists($mockedResponse, 'callback') && is_callable($mockedResponse->callback)) { // @phpstan-ignore-line
($mockedResponse->callback)($httpRequest, $httpResponse);
}
// @codeCoverageIgnoreEnd
Expand Down
25 changes: 21 additions & 4 deletions tests/Unit/Utility/HttpClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
}

$response = $this->client->method('get')
->addPath(['client'])
->addPath(['client'])
->call();

expect(HttpResponse::getStatusCode($response))->toEqual(429);
Expand All @@ -75,7 +75,7 @@
}

$response = $this->client->method('get')
->addPath(['client'])
->addPath(['client'])
->call();

$requestCount = $this->client->getLastRequest()->getRequestCount();
Expand Down Expand Up @@ -142,7 +142,7 @@
$this->client->mockResponse(clone $this->httpResponse200);

$response = $this->client->method('get')
->addPath(['client'])
->addPath(['client'])
->call();

expect(HttpResponse::getStatusCode($response))->toEqual(429);
Expand All @@ -160,7 +160,7 @@
]);

$response = $this->client->method('get')
->addPath(['client'])
->addPath(['client'])
->call();

expect(HttpResponse::getStatusCode($response))->toEqual(200);
Expand All @@ -169,3 +169,20 @@

expect($requestCount)->toEqual(2);
});

test('the callback of a mock response is called', function(): void {
$count = 0;

$this->client->mockResponse(
clone $this->httpResponse200,
function ($request) use (&$count) {
$count++;
}
);

$response = $this->client->method('get')
->addPath(['client'])
->call();

expect($count)->toEqual(1);
});

0 comments on commit a8aa11b

Please sign in to comment.