Skip to content

Commit

Permalink
Merge pull request #41 from tinect/fix/issue-39
Browse files Browse the repository at this point in the history
fix: always download file content without jsonDecoding
  • Loading branch information
sifex authored Nov 12, 2022
2 parents 9bf9e09 + c58b2e7 commit 5efc060
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/BunnyCDNClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,13 @@ public function list(string $path): array
public function download(string $path): string
{
try {
return $this->request($path.'?download');
$content = $this->request($path.'?download');

if (\is_array($content)) {
return \json_encode($content);
}

return $content;
// @codeCoverageIgnoreStart
} catch (GuzzleException $e) {
throw match ($e->getCode()) {
Expand Down
26 changes: 26 additions & 0 deletions tests/FlysystemTestSuite.php
Original file line number Diff line number Diff line change
Expand Up @@ -515,4 +515,30 @@ public function test_regression_issue_29()
// The fact that PHPUnit makes me do this is 🤬
$this->assertEquals(3, $exception_count);
}

/**
* Github Issue - 39
* https://github.com/PlatformCommunity/flysystem-bunnycdn/issues/39
*
* Can't request file containing json
*
* @throws FilesystemException
*/
public function test_regression_issue_39()
{
$client = new MockClient(self::STORAGE_ZONE, 'api-key');

$client->add_response(
new Response(200, [], json_encode(
[
'test' => 123,
]
))
);

$adapter = new Filesystem(new BunnyCDNAdapter($client));
$response = $adapter->read('/test.json');

$this->assertIsString($response);
}
}

0 comments on commit 5efc060

Please sign in to comment.