From 4ffa31839acbd4f5b7b1205c3794a83072c6d0d3 Mon Sep 17 00:00:00 2001 From: Offcurve Date: Thu, 6 Jan 2022 14:45:57 +0100 Subject: [PATCH 1/3] Allow to apply filters with bool values in Behat tests --- src/Behat/Model/OperationRequest.php | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/src/Behat/Model/OperationRequest.php b/src/Behat/Model/OperationRequest.php index b281a6c8..d12e9154 100644 --- a/src/Behat/Model/OperationRequest.php +++ b/src/Behat/Model/OperationRequest.php @@ -120,11 +120,7 @@ private function formatFilters(): string * @var mixed $filterValue */ foreach ($filters as $filterName => $filterValue) { - $filtersData .= sprintf( - "%s: %s,\n", - $filterName, - (string) $filterValue - ); + $filtersData .= $this->formatFilter($filterName, $filterValue); } return sprintf('( @@ -132,6 +128,21 @@ private function formatFilters(): string )', $filtersData); } + private function formatFilter(string $filterName, $filterValue): string + { + $processedValue = (string) $filterValue; + + if (is_bool($filterValue)) { + $processedValue = $filterValue ? 'true' : 'false'; + } + + return sprintf( + "%s: %s,\n", + $filterName, + $processedValue + ); + } + private function addFiltersToQuery(): void { $filters = $this->formatFilters(); From d10c32fe8a2f3021033bcfaeb7a794f9aa308579 Mon Sep 17 00:00:00 2001 From: Offcurve Date: Thu, 6 Jan 2022 14:49:47 +0100 Subject: [PATCH 2/3] Modify if statement --- src/Behat/Model/OperationRequest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Behat/Model/OperationRequest.php b/src/Behat/Model/OperationRequest.php index d12e9154..1793ffe0 100644 --- a/src/Behat/Model/OperationRequest.php +++ b/src/Behat/Model/OperationRequest.php @@ -132,7 +132,7 @@ private function formatFilter(string $filterName, $filterValue): string { $processedValue = (string) $filterValue; - if (is_bool($filterValue)) { + if (true === is_bool($filterValue)) { $processedValue = $filterValue ? 'true' : 'false'; } From 2337d637e6d1c335cbcf75588910a6d6bf2128b6 Mon Sep 17 00:00:00 2001 From: Offcurve Date: Thu, 6 Jan 2022 15:02:49 +0100 Subject: [PATCH 3/3] Fix PHPStan issue with no typehint specified --- src/Behat/Model/OperationRequest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Behat/Model/OperationRequest.php b/src/Behat/Model/OperationRequest.php index 1793ffe0..6b319924 100644 --- a/src/Behat/Model/OperationRequest.php +++ b/src/Behat/Model/OperationRequest.php @@ -128,6 +128,7 @@ private function formatFilters(): string )', $filtersData); } + /** @param mixed $filterValue */ private function formatFilter(string $filterName, $filterValue): string { $processedValue = (string) $filterValue;