Skip to content
This repository was archived by the owner on Jan 29, 2020. It is now read-only.

Commit e643101

Browse files
committed
Merge branch 'hotfix/20'
Close #20
2 parents 1cad43e + 5560c9d commit e643101

File tree

3 files changed

+59
-0
lines changed

3 files changed

+59
-0
lines changed

CHANGELOG.md

+25
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,31 @@ All notable changes to this project will be documented in this file, in reverse
44

55
Versions 0.3.0 and prior were released as "weierophinney/problem-details".
66

7+
## 0.5.1 - 2017-12-07
8+
9+
### Added
10+
11+
- Nothing.
12+
13+
### Changed
14+
15+
- Nothing.
16+
17+
### Deprecated
18+
19+
- Nothing.
20+
21+
### Removed
22+
23+
- Nothing.
24+
25+
### Fixed
26+
27+
- [#20](https://github.com/zendframework/zend-problem-details/pull/20) fixes an
28+
issue with serialization when PHP resources are within the `$additional`
29+
aspect of the payload. When these values are encountered, the response factory
30+
now will instead return `Resource of type {resource type}`.
31+
732
## 0.5.0 - 2017-10-09
833

934
### Added

src/ProblemDetailsResponseFactory.php

+6
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,12 @@ public function createResponse(
229229
];
230230

231231
if ($additional) {
232+
// ensure payload can be json_encoded
233+
array_walk_recursive($additional, function (&$value) {
234+
if (is_resource($value)) {
235+
$value = print_r($value, true) . ' of type ' . get_resource_type($value);
236+
}
237+
});
232238
$payload = array_merge($additional, $payload);
233239
}
234240

test/ProblemDetailsResponseFactoryTest.php

+28
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,34 @@ public function testCreateResponseFromThrowableWillPullDetailsFromProblemDetails
135135
$this->assertSame('bar', $payload['foo']);
136136
}
137137

138+
/**
139+
* @dataProvider acceptHeaders
140+
*/
141+
public function testCreateResponseRemovesResourcesFromInputData(string $header, string $expectedType) : void
142+
{
143+
$this->request->getHeaderLine('Accept')->willReturn($header);
144+
145+
$fh = fopen(__FILE__, 'r');
146+
$response = $this->factory->createResponse(
147+
$this->request->reveal(),
148+
500,
149+
'Unknown error occurred',
150+
'Title',
151+
'Type',
152+
[
153+
'args' => [
154+
'resource' => $fh,
155+
]
156+
]
157+
);
158+
fclose($fh);
159+
160+
$this->assertInstanceOf(ResponseInterface::class, $response);
161+
$this->assertEquals($expectedType, $response->getHeaderLine('Content-Type'));
162+
163+
$this->assertNotEmpty((string)$response->getBody(), 'Body is missing');
164+
}
165+
138166
public function testFactoryRaisesExceptionIfBodyFactoryDoesNotReturnStream() : void
139167
{
140168
$this->request->getHeaderLine('Accept')->willReturn('application/json');

0 commit comments

Comments
 (0)