forked from loafle/openapi-generator-original
* Add testcase which reproduces issue #6770 * Pass debug option if needed * Update samples * bin/php-petstore.sh * bin/security/php-petstore.sh * Api throws exception when failed to open debug file * Pass debug option if needed (Async) * Extract instance method * Update samples * bin/php-petstore.sh * bin/security/php-petstore.sh
This commit is contained in:
@@ -32,6 +32,7 @@ use GuzzleHttp\ClientInterface;
|
||||
use GuzzleHttp\Exception\RequestException;
|
||||
use GuzzleHttp\Psr7\MultipartStream;
|
||||
use GuzzleHttp\Psr7\Request;
|
||||
use GuzzleHttp\RequestOptions;
|
||||
use Swagger\Client\ApiException;
|
||||
use Swagger\Client\Configuration;
|
||||
use Swagger\Client\HeaderSelector;
|
||||
@@ -113,9 +114,9 @@ class FakeApi
|
||||
$request = $this->testCodeInjectEndRnNRRequest($test_code_inject____end____rn_n_r);
|
||||
|
||||
try {
|
||||
|
||||
$options = $this->createHttpClientOption();
|
||||
try {
|
||||
$response = $this->client->send($request);
|
||||
$response = $this->client->send($request, $options);
|
||||
} catch (RequestException $e) {
|
||||
throw new ApiException(
|
||||
"[{$e->getCode()}] {$e->getMessage()}",
|
||||
@@ -184,7 +185,7 @@ class FakeApi
|
||||
$request = $this->testCodeInjectEndRnNRRequest($test_code_inject____end____rn_n_r);
|
||||
|
||||
return $this->client
|
||||
->sendAsync($request)
|
||||
->sendAsync($request, $this->createHttpClientOption())
|
||||
->then(
|
||||
function ($response) use ($returnType) {
|
||||
return [null, $response->getStatusCode(), $response->getHeaders()];
|
||||
@@ -294,4 +295,22 @@ class FakeApi
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create http client option
|
||||
*
|
||||
* @throws \RuntimeException on file opening failure
|
||||
* @return array of http client options
|
||||
*/
|
||||
protected function createHttpClientOption()
|
||||
{
|
||||
$options = [];
|
||||
if ($this->config->getDebug()) {
|
||||
$options[RequestOptions::DEBUG] = fopen($this->config->getDebugFile(), 'a');
|
||||
if (!$options[RequestOptions::DEBUG]) {
|
||||
throw new \RuntimeException('Failed to open the debug file: ' . $this->config->getDebugFile());
|
||||
}
|
||||
}
|
||||
|
||||
return $options;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user