diff --git a/src/Utility/HttpRequest.php b/src/Utility/HttpRequest.php index 6c3584ee..94ffae1d 100644 --- a/src/Utility/HttpRequest.php +++ b/src/Utility/HttpRequest.php @@ -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 diff --git a/tests/Unit/Utility/HttpClientTest.php b/tests/Unit/Utility/HttpClientTest.php index 127329b1..4b25fbf9 100644 --- a/tests/Unit/Utility/HttpClientTest.php +++ b/tests/Unit/Utility/HttpClientTest.php @@ -51,7 +51,7 @@ } $response = $this->client->method('get') - ->addPath(['client']) + ->addPath(['client']) ->call(); expect(HttpResponse::getStatusCode($response))->toEqual(429); @@ -75,7 +75,7 @@ } $response = $this->client->method('get') - ->addPath(['client']) + ->addPath(['client']) ->call(); $requestCount = $this->client->getLastRequest()->getRequestCount(); @@ -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); @@ -160,7 +160,7 @@ ]); $response = $this->client->method('get') - ->addPath(['client']) + ->addPath(['client']) ->call(); expect(HttpResponse::getStatusCode($response))->toEqual(200); @@ -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); +});