From b310a671e055918999fffae8cdedf78e1bb66d38 Mon Sep 17 00:00:00 2001 From: aaa2000 Date: Mon, 9 Oct 2023 22:36:29 +0200 Subject: [PATCH] Fix not display response body if option is false --- .../Bundle/LogBridgeBundle/Formatter/DefaultFormatter.php | 5 +++-- .../Tests/Units/Formatter/DefaultFormatter.php | 3 +++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/M6Web/Bundle/LogBridgeBundle/Formatter/DefaultFormatter.php b/src/M6Web/Bundle/LogBridgeBundle/Formatter/DefaultFormatter.php index fbc9c55..238d4f8 100644 --- a/src/M6Web/Bundle/LogBridgeBundle/Formatter/DefaultFormatter.php +++ b/src/M6Web/Bundle/LogBridgeBundle/Formatter/DefaultFormatter.php @@ -77,14 +77,15 @@ public function getLogContent(Request $request, Response $response, array $optio // Render post parameters if (array_key_exists('post_parameters', $options) - && $options['post_parameters'] == true + && $options['post_parameters'] === true && in_array($request->getMethod(), ['POST', 'PUT', 'PATCH'])) { $responseContent .= "Post parameters\n"; $responseContent .= $this->formatParameters($request->request->all()); } // Render response body content - if (isset($options['response_body'])) { + if (array_key_exists('response_body', $options) + && $options['response_body'] === true) { $responseContent .= "Response body\n------------------------\n"; $responseContent .= $response->getContent()."\n"; } diff --git a/src/M6Web/Bundle/LogBridgeBundle/Tests/Units/Formatter/DefaultFormatter.php b/src/M6Web/Bundle/LogBridgeBundle/Tests/Units/Formatter/DefaultFormatter.php index f45f3d4..c078719 100644 --- a/src/M6Web/Bundle/LogBridgeBundle/Tests/Units/Formatter/DefaultFormatter.php +++ b/src/M6Web/Bundle/LogBridgeBundle/Tests/Units/Formatter/DefaultFormatter.php @@ -83,6 +83,9 @@ public function testProvider(): void ->string($provider->getLogContent($request, $response, ['response_body' => true])) ->contains("Response body\n") ->contains($response->getContent()) + ->string($provider->getLogContent($request, $response, ['response_body' => false])) + ->notContains("Response body\n") + ->notContains($response->getContent()) ->array($logContext = $provider->getLogContext($request, $response, [])) ->hasSize(7) ->hasKeys(['environment', 'route', 'method', 'status', 'user', 'key', 'uri'])