Skip to content
This repository was archived by the owner on Dec 20, 2021. It is now read-only.

Commit c595ae6

Browse files
authored
Merge pull request #43 from RETFU/zip-support
feat(format): Add zip support
2 parents 15d0ca5 + 764c0b6 commit c595ae6

File tree

3 files changed

+31
-2
lines changed

3 files changed

+31
-2
lines changed

src/RREST.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ class RREST
2424
'json' => ['application/json', 'application/x-json'],
2525
'xml' => ['text/xml', 'application/xml', 'application/x-xml'],
2626
'csv' => ['text/csv', 'application/csv'],
27+
'zip' => ['application/zip'],
2728
'xlsx' => ['application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'],
2829
];
2930

src/Response.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class Response
4141
/**
4242
* @var string[]
4343
*/
44-
protected $supportedFormat = ['json', 'xml', 'csv', 'xlsx'];
44+
protected $supportedFormat = ['json', 'xml', 'csv', 'zip', 'xlsx'];
4545

4646
/**
4747
* @var RouterInterface
@@ -269,7 +269,7 @@ public function serialize($data, $format)
269269
$data = json_decode(json_encode($data, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE), true);
270270

271271
return $serializer->serialize($data, $format);
272-
} elseif ($format === 'csv' || $format === 'xlsx') {
272+
} elseif ($format === 'csv' || $format === 'xlsx' || $format === 'zip') {
273273
if (!is_string($data)) {
274274
throw new \RuntimeException(
275275
'auto serialization for '.strtoupper($format).' format is not supported'

tests/units/Response.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,34 @@ public function testSerializeForXlsx()
149149
;
150150
}
151151

152+
public function testNoZipSerialize()
153+
{
154+
$this->newTestedInstance($this->router, 'zip', 200);
155+
156+
$this
157+
->given($this->testedInstance)
158+
->exception(
159+
function () {
160+
$this->testedInstance->serialize([], 'zip');
161+
}
162+
)
163+
->isInstanceOf('\RuntimeException')
164+
->message->contains('auto serialization for ZIP format is not supported');
165+
}
166+
167+
public function testSerializeForZip()
168+
{
169+
$this->newTestedInstance($this->router, 'zip', 200);
170+
171+
$zip = "Placeholder for binary content";
172+
173+
$this
174+
->given($this->testedInstance)
175+
->string($this->testedInstance->serialize($zip, 'zip'))
176+
->isEqualTo($zip);
177+
;
178+
}
179+
152180
public function testAssertReponseSchema()
153181
{
154182
$this->newTestedInstance($this->router, 'json', 200);

0 commit comments

Comments
 (0)