Skip to content

Commit 7490db6

Browse files
committed
Return response instead of the body
1 parent 27b0029 commit 7490db6

File tree

5 files changed

+11
-9
lines changed

5 files changed

+11
-9
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
Drop support for PHP 5.6, PHP 7.0 and PHP 7.1
66

7+
Change the response type from `StreamInterface` to `Response` for `\Akeneo\Pim\ApiClient\Api\MediaFileApiInterface::download`
8+
79
# 3.0.0 (2018-06-26)
810

911
# 2.0.1 (2018-05-03)

spec/Api/ProductMediaFileApiSpec.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -285,8 +285,6 @@ function it_downloads_a_media_file($resourceClient, ResponseInterface $response,
285285
->getStreamedResource(ProductMediaFileApi::MEDIA_FILE_DOWNLOAD_URI, ['42.jpg'])
286286
->willReturn($response);
287287

288-
$response->getBody()->willReturn($streamBody);
289-
290-
$this->download('42.jpg')->shouldReturn($streamBody);
288+
$this->download('42.jpg')->shouldReturn($response);
291289
}
292290
}

src/Api/Operation/DownloadableResourceInterface.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Akeneo\Pim\ApiClient\Api\Operation;
44

55
use Akeneo\Pim\ApiClient\Exception\HttpException;
6+
use Psr\Http\Message\ResponseInterface;
67
use Psr\Http\Message\StreamInterface;
78

89
/**
@@ -21,7 +22,7 @@ interface DownloadableResourceInterface
2122
*
2223
* @throws HttpException
2324
*
24-
* @return StreamInterface
25+
* @return ResponseInterface
2526
*/
26-
public function download(string $code): StreamInterface;
27+
public function download(string $code): ResponseInterface;
2728
}

src/Api/ProductMediaFileApi.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,9 @@ public function create($mediaFile, array $data): string
114114
/**
115115
* {@inheritdoc}
116116
*/
117-
public function download(string $code): StreamInterface
117+
public function download(string $code): ResponseInterface
118118
{
119-
return $this->resourceClient->getStreamedResource(static::MEDIA_FILE_DOWNLOAD_URI, [$code])->getBody();
119+
return $this->resourceClient->getStreamedResource(static::MEDIA_FILE_DOWNLOAD_URI, [$code]);
120120
}
121121

122122
/**

tests/Api/DownloadProductMediaFileTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use donatj\MockWebServer\Response;
88
use donatj\MockWebServer\ResponseStack;
99
use PHPUnit\Framework\Assert;
10+
use Psr\Http\Message\ResponseInterface;
1011
use Psr\Http\Message\StreamInterface;
1112

1213
class DownloadProductMediaFileTest extends ApiTestCase
@@ -26,7 +27,7 @@ public function test_download_media_file()
2627
$mediaFile = $api->download('/f/b/0/6/fb068ccc9e3c5609d73c28d852812ba5faeeab28_akeneo.png');
2728

2829
Assert::assertSame($this->server->getLastRequest()->jsonSerialize()[RequestInfo::JSON_KEY_METHOD], 'GET');
29-
Assert::assertInstanceOf(StreamInterface::class, $mediaFile);
30-
Assert::assertSame(file_get_contents($expectedMediaFilePath), $mediaFile->getContents());
30+
Assert::assertInstanceOf(ResponseInterface::class, $mediaFile);
31+
Assert::assertSame(file_get_contents($expectedMediaFilePath), $mediaFile->getBody()->getContents());
3132
}
3233
}

0 commit comments

Comments
 (0)