Skip to content

Commit

Permalink
Merge pull request #159 from akeneo/add-changelog
Browse files Browse the repository at this point in the history
Return response instead of the body
  • Loading branch information
ahocquard authored Feb 15, 2019
2 parents 10bc8c7 + 7490db6 commit d878710
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 9 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 1 addition & 3 deletions spec/Api/ProductMediaFileApiSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
5 changes: 3 additions & 2 deletions src/Api/Operation/DownloadableResourceInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand All @@ -21,7 +22,7 @@ interface DownloadableResourceInterface
*
* @throws HttpException
*
* @return StreamInterface
* @return ResponseInterface
*/
public function download(string $code): StreamInterface;
public function download(string $code): ResponseInterface;
}
4 changes: 2 additions & 2 deletions src/Api/ProductMediaFileApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
}

/**
Expand Down
5 changes: 3 additions & 2 deletions tests/Api/DownloadProductMediaFileTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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());
}
}

0 comments on commit d878710

Please sign in to comment.