@@ -246,10 +246,11 @@ public function responseStatusCodeShouldBe(string $httpStatus): void
246246 public function responseIsJson (): void
247247 {
248248 $ response = $ this ->getResponse ();
249- $ data = json_decode ($ response ->getContent (), true , 512 , JSON_THROW_ON_ERROR );
249+ $ body = $ this ->getResponseBody ($ response );
250+ $ data = json_decode ($ body , true , 512 , JSON_THROW_ON_ERROR );
250251
251252 if (empty ($ data )) {
252- throw new RuntimeException ("Response was not JSON \n" . $ response -> getContent () );
253+ throw new RuntimeException ("Response was not JSON \n" . $ body );
253254 }
254255 }
255256
@@ -258,7 +259,7 @@ public function responseIsJson(): void
258259 */
259260 public function responseEmpty (): void
260261 {
261- if (! empty ( $ this ->getResponse ()-> getContent ())) {
262+ if ($ this ->getResponseBody ( $ this -> getResponse ()) !== '' ) {
262263 throw new RuntimeException ('Content not empty ' );
263264 }
264265 }
@@ -271,7 +272,7 @@ public function responseEmpty(): void
271272 public function responseShouldBeJson (PyStringNode $ string ): void
272273 {
273274 $ expectedResponse = json_decode (trim ($ string ->getRaw ()), true , 512 , JSON_THROW_ON_ERROR );
274- $ actualResponse = json_decode ($ this ->getResponse ()-> getContent ( ), true , 512 , JSON_THROW_ON_ERROR );
275+ $ actualResponse = json_decode ($ this ->getResponseBody ( $ this -> getResponse () ), true , 512 , JSON_THROW_ON_ERROR );
275276
276277 if ($ expectedResponse !== $ actualResponse ) {
277278 $ prettyJSON = json_encode ($ actualResponse , JSON_THROW_ON_ERROR | JSON_PRETTY_PRINT , 512 );
@@ -286,7 +287,7 @@ public function responseShouldBeJson(PyStringNode $string): void
286287 */
287288 public function iGetParamFromJsonResponse (string $ paramPath , string $ valueKey ): void
288289 {
289- $ actualResponse = json_decode ($ this ->getResponse ()-> getContent ( ), true , 512 , JSON_THROW_ON_ERROR );
290+ $ actualResponse = json_decode ($ this ->getResponseBody ( $ this -> getResponse () ), true , 512 , JSON_THROW_ON_ERROR );
290291 $ pathKeys = explode ('. ' , $ paramPath );
291292
292293 foreach ($ pathKeys as $ key ) {
@@ -307,7 +308,7 @@ public function iGetParamFromJsonResponse(string $paramPath, string $valueKey):
307308 */
308309 public function responseShouldBeJsonWithVariableFields (string $ variableFields , PyStringNode $ string ): void
309310 {
310- $ this ->compareStructureResponse ($ variableFields , $ string , $ this ->getResponse ()-> getContent ( ));
311+ $ this ->compareStructureResponse ($ variableFields , $ string , $ this ->getResponseBody ( $ this -> getResponse () ));
311312 }
312313
313314 protected function compareStructureResponse (
@@ -388,6 +389,11 @@ protected function checkResponseHeader(string $headerName, string $headerValue):
388389 }
389390 }
390391
392+ /**
393+ * @param array<string, mixed> $requestParams
394+ *
395+ * @return array<string, mixed>
396+ */
391397 protected function convertRunnableCodeParams (array $ requestParams ): array
392398 {
393399 foreach ($ requestParams as $ key => $ value ) {
@@ -449,8 +455,21 @@ protected function getResponse(): Response
449455 return $ this ->response ;
450456 }
451457
458+ /**
459+ * @return array<string, mixed>
460+ */
452461 public function geRequestParams (): array
453462 {
454463 return $ this ->requestParams ;
455464 }
465+
466+ private function getResponseBody (Response $ response ): string
467+ {
468+ $ content = $ response ->getContent ();
469+ if ($ content === false ) {
470+ throw new RuntimeException ('The response body is not available. ' );
471+ }
472+
473+ return $ content ;
474+ }
456475}
0 commit comments