Skip to content

Commit d3c45b4

Browse files
committed
Return the response instead of its body for a streamed resource
1 parent 3cef601 commit d3c45b4

File tree

5 files changed

+9
-10
lines changed

5 files changed

+9
-10
lines changed

spec/Api/ProductMediaFileApiSpec.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -279,11 +279,13 @@ function it_throws_an_exception_if_the_uri_of_the_created_media_file_is_invalid(
279279
->during('create', [$fileResource, $product]);
280280
}
281281

282-
function it_downloads_a_media_file($resourceClient, StreamInterface $streamBody)
282+
function it_downloads_a_media_file($resourceClient, ResponseInterface $response, StreamInterface $streamBody)
283283
{
284284
$resourceClient
285285
->getStreamedResource(ProductMediaFileApi::MEDIA_FILE_DOWNLOAD_URI, ['42.jpg'])
286-
->willReturn($streamBody);
286+
->willReturn($response);
287+
288+
$response->getBody()->willReturn($streamBody);
287289

288290
$this->download('42.jpg')->shouldReturn($streamBody);
289291
}

spec/Client/ResourceClientSpec.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -469,8 +469,7 @@ function it_deletes_a_resource(
469469
function it_gets_a_streamed_resource(
470470
$httpClient,
471471
$uriGenerator,
472-
ResponseInterface $response,
473-
StreamInterface $responseBody
472+
ResponseInterface $response
474473
) {
475474
$uri = 'http://akeneo.com/api/rest/v1/media-files/42.jpg/download';
476475

@@ -480,9 +479,7 @@ function it_gets_a_streamed_resource(
480479

481480
$httpClient->sendRequest('GET', $uri, ['Accept' => '*/*'])->willReturn($response);
482481

483-
$response->getBody()->willReturn($responseBody);
484-
485-
$this->getStreamedResource('api/rest/v1/media-files/%s/download', ['42.jpg'])->shouldReturn($responseBody);
482+
$this->getStreamedResource('api/rest/v1/media-files/%s/download', ['42.jpg'])->shouldReturn($response);
486483
}
487484

488485
protected function getSampleOfResources()

src/Api/ProductMediaFileApi.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ public function create($mediaFile, array $data)
113113
*/
114114
public function download($code)
115115
{
116-
return $this->resourceClient->getStreamedResource(static::MEDIA_FILE_DOWNLOAD_URI, [$code]);
116+
return $this->resourceClient->getStreamedResource(static::MEDIA_FILE_DOWNLOAD_URI, [$code])->getBody();
117117
}
118118

119119
/**

src/Client/ResourceClient.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,6 @@ public function getStreamedResource($uri, array $uriParameters = [])
226226
$uri = $this->uriGenerator->generate($uri, $uriParameters);
227227
$response = $this->httpClient->sendRequest('GET', $uri, ['Accept' => '*/*']);
228228

229-
return $response->getBody();
229+
return $response;
230230
}
231231
}

src/Client/ResourceClientInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ public function deleteResource($uri, array $uriParameters = []);
140140
*
141141
* @throws HttpException If the request failed
142142
*
143-
* @return StreamInterface
143+
* @return ResponseInterface The response of the streamed resource request
144144
*/
145145
public function getStreamedResource($uri, array $uriParameters = []);
146146
}

0 commit comments

Comments
 (0)