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
13 changes: 13 additions & 0 deletions src/Lib/HttpClient/HttpClientInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,19 @@ public function get(string $url, array $headers = []): HttpResponse;
*/
public function post(string $url, array $headers = [], ?string $body = null): HttpResponse;

/**
* Send a request with the specified HTTP method.
*
* @param string $method The HTTP method (GET, POST, PUT, PATCH, DELETE, etc.)
* @param string $url The URL to request
* @param array<string, string> $headers Optional request headers
* @param string|null $body Optional request body
* @return HttpResponse The response object
*
* @throws HttpException If the request fails
*/
public function request(string $method, string $url, array $headers = [], ?string $body = null): HttpResponse;

/**
* Send a request to the specified URL and follow redirects if needed
*
Expand Down
13 changes: 1 addition & 12 deletions src/Lib/HttpClient/Psr18Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,18 +52,7 @@ public function getWithRedirects(string $url, array $headers = []): HttpResponse
}
}

/**
* Send a request with the specified method to the URL
*
* @param string $method The HTTP method
* @param string $url The URL to request
* @param array<string, string> $headers Optional request headers
* @param string|null $body Optional request body (for POST, PUT, etc.)
* @return HttpResponse The response object
*
* @throws HttpException If the request fails
*/
private function request(string $method, string $url, array $headers = [], ?string $body = null): HttpResponse
public function request(string $method, string $url, array $headers = [], ?string $body = null): HttpResponse
{
$request = $this->requestFactory->createRequest($method, $url);

Expand Down
11 changes: 11 additions & 0 deletions tests/src/Feature/Console/GenerateCommand/MockHttpClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,17 @@ public function getWithRedirects(string $url, array $headers = []): HttpResponse
return $this->get($url, $headers);
}

public function request(string $method, string $url, array $headers = [], ?string $body = null): HttpResponse
{
$this->requestHeaders[$url] = $headers;

return $this->responses[$url] ?? new HttpResponse(
statusCode: 200,
body: "Mock {$method} response for {$url}",
headers: [],
);
}

public function addResponse(string $url, HttpResponse $response): void
{
$this->responses[$url] = $response;
Expand Down
Loading