diff --git a/CHANGELOG.md b/CHANGELOG.md index 8d11362e..6ec0f4af 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,8 @@ Drop support for PHP 5.6, PHP 7.0 and PHP 7.1 +Change the response type from `StreamInterface` to `Response` for `\Akeneo\Pim\ApiClient\Api\MediaFileApiInterface::download` + # 3.0.0 (2018-06-26) # 2.0.1 (2018-05-03) diff --git a/spec/Api/ProductMediaFileApiSpec.php b/spec/Api/ProductMediaFileApiSpec.php index c401b2f1..d0152efb 100644 --- a/spec/Api/ProductMediaFileApiSpec.php +++ b/spec/Api/ProductMediaFileApiSpec.php @@ -285,8 +285,6 @@ function it_downloads_a_media_file($resourceClient, ResponseInterface $response, ->getStreamedResource(ProductMediaFileApi::MEDIA_FILE_DOWNLOAD_URI, ['42.jpg']) ->willReturn($response); - $response->getBody()->willReturn($streamBody); - - $this->download('42.jpg')->shouldReturn($streamBody); + $this->download('42.jpg')->shouldReturn($response); } } diff --git a/src/Api/Operation/DownloadableResourceInterface.php b/src/Api/Operation/DownloadableResourceInterface.php index ca1a888d..916c62dd 100644 --- a/src/Api/Operation/DownloadableResourceInterface.php +++ b/src/Api/Operation/DownloadableResourceInterface.php @@ -3,6 +3,7 @@ namespace Akeneo\Pim\ApiClient\Api\Operation; use Akeneo\Pim\ApiClient\Exception\HttpException; +use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\StreamInterface; /** @@ -21,7 +22,7 @@ interface DownloadableResourceInterface * * @throws HttpException * - * @return StreamInterface + * @return ResponseInterface */ - public function download(string $code): StreamInterface; + public function download(string $code): ResponseInterface; } diff --git a/src/Api/ProductMediaFileApi.php b/src/Api/ProductMediaFileApi.php index b0c4954f..e092ecdc 100644 --- a/src/Api/ProductMediaFileApi.php +++ b/src/Api/ProductMediaFileApi.php @@ -114,9 +114,9 @@ public function create($mediaFile, array $data): string /** * {@inheritdoc} */ - public function download(string $code): StreamInterface + public function download(string $code): ResponseInterface { - return $this->resourceClient->getStreamedResource(static::MEDIA_FILE_DOWNLOAD_URI, [$code])->getBody(); + return $this->resourceClient->getStreamedResource(static::MEDIA_FILE_DOWNLOAD_URI, [$code]); } /** diff --git a/tests/Api/DownloadProductMediaFileTest.php b/tests/Api/DownloadProductMediaFileTest.php index 2b13d1b7..9e57fe50 100644 --- a/tests/Api/DownloadProductMediaFileTest.php +++ b/tests/Api/DownloadProductMediaFileTest.php @@ -7,6 +7,7 @@ use donatj\MockWebServer\Response; use donatj\MockWebServer\ResponseStack; use PHPUnit\Framework\Assert; +use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\StreamInterface; class DownloadProductMediaFileTest extends ApiTestCase @@ -26,7 +27,7 @@ public function test_download_media_file() $mediaFile = $api->download('/f/b/0/6/fb068ccc9e3c5609d73c28d852812ba5faeeab28_akeneo.png'); Assert::assertSame($this->server->getLastRequest()->jsonSerialize()[RequestInfo::JSON_KEY_METHOD], 'GET'); - Assert::assertInstanceOf(StreamInterface::class, $mediaFile); - Assert::assertSame(file_get_contents($expectedMediaFilePath), $mediaFile->getContents()); + Assert::assertInstanceOf(ResponseInterface::class, $mediaFile); + Assert::assertSame(file_get_contents($expectedMediaFilePath), $mediaFile->getBody()->getContents()); } }