This repository was archived by the owner on Jan 29, 2020. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +34
-0
lines changed Expand file tree Collapse file tree 2 files changed +34
-0
lines changed Original file line number Diff line number Diff 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
Original file line number Diff line number Diff 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 ' );
You can’t perform that action at this time.
0 commit comments