From 50d71ffd42e3a2b51b393c77cfc0584f92349e1e Mon Sep 17 00:00:00 2001 From: KEL Date: Wed, 15 Sep 2021 17:12:30 +0800 Subject: [PATCH] fix: responseFile convert empty object to array responseFile convert empty object to array due to `json_decode($content, true)` Example ```json {"foo":{}} ``` convert to ```json {"foo":[]} ``` --- src/Extracting/Strategies/Responses/UseResponseFileTag.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Extracting/Strategies/Responses/UseResponseFileTag.php b/src/Extracting/Strategies/Responses/UseResponseFileTag.php index 007f4fc1..8cf585f3 100644 --- a/src/Extracting/Strategies/Responses/UseResponseFileTag.php +++ b/src/Extracting/Strategies/Responses/UseResponseFileTag.php @@ -62,7 +62,12 @@ protected function getFileResponses(array $tags) } $status = $result[1] ?: 200; $content = $result[2] ? file_get_contents($filePath, true) : '{}'; - $json = ! empty($result[3]) ? str_replace("'", '"', $result[3]) : '{}'; + + if (empty($result[3])) { + return ['content' => $content, 'status' => (int) $status]; + } + + $json = str_replace("'", '"', $result[3]); $merged = array_merge(json_decode($content, true), json_decode($json, true)); return ['content' => json_encode($merged), 'status' => (int) $status];