Compare commits

...

2 Commits

Author SHA1 Message Date
eai04191
0522270c1c 引数のheaderとstatusを使用する 2019-08-22 17:46:37 +09:00
eai04191
9bd6b23c05 複数のresponseを受けられるように 2019-08-22 17:43:19 +09:00

View File

@ -22,12 +22,12 @@ trait CreateMockedResolver
/**
* @param string $resolverClass
* @param string $responseText
* @param string|array $response
* @param array $headers
* @param int $status
* @return Resolver
*/
protected function createResolver(string $resolverClass, string $responseText, array $headers = [], int $status = 200)
protected function createResolver(string $resolverClass, $response, array $headers = [], int $status = 200)
{
if (!$this->shouldUseMock()) {
$this->resolver = app()->make($resolverClass);
@ -39,8 +39,26 @@ trait CreateMockedResolver
'content-type' => 'text/html',
];
$mockResponse = new Response($status, $headers, $responseText);
$this->handler = new MockHandler([$mockResponse]);
if (is_array($response)) {
$responses = $response;
$mockResponses = [];
foreach ($responses as $response) {
if (is_array($response)) {
$response += [
1 => $headers,
2 => $status
];
array_push($mockResponses, new Response($response[2], $response[1], $response[0]));
} else {
array_push($mockResponses, new Response($status, $headers, $response));
}
}
$this->handler = new MockHandler($mockResponses);
} else {
$mockResponse = new Response($status, $headers, $response);
$this->handler = new MockHandler([$mockResponse]);
}
$client = new Client(['handler' => $this->handler]);
$this->resolver = app()->make($resolverClass, ['client' => $client]);