From 662dca6de3f223381d244f7298068fcbedf58e34 Mon Sep 17 00:00:00 2001 From: Tomasz Grochowski Date: Tue, 21 Dec 2021 13:35:44 +0100 Subject: [PATCH 1/3] Implement format filters method logic --- .../Context/GraphqlApiPlatformContext.php | 12 ++++++++++ src/Behat/Model/OperationRequest.php | 24 ++++++++++++++++++- 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/src/Behat/Context/GraphqlApiPlatformContext.php b/src/Behat/Context/GraphqlApiPlatformContext.php index 1c33cb66..6bf3ced1 100644 --- a/src/Behat/Context/GraphqlApiPlatformContext.php +++ b/src/Behat/Context/GraphqlApiPlatformContext.php @@ -235,4 +235,16 @@ private function getJsonFromResponse(string $response): ?array return null; } + + /** + * @Then I add :filterName filter to this operation with :value value + * + * @param mixed $value + */ + public function iAddFilterToThisOperation(string $filterName, $value): void + { + $operation = $this->client->getLastOperationRequest(); + Assert::isInstanceOf($operation, OperationRequestInterface::class); + $operation->addFilter($filterName, $value); + } } diff --git a/src/Behat/Model/OperationRequest.php b/src/Behat/Model/OperationRequest.php index 0df402ee..b281a6c8 100644 --- a/src/Behat/Model/OperationRequest.php +++ b/src/Behat/Model/OperationRequest.php @@ -107,7 +107,29 @@ public function getFormatted(): array private function formatFilters(): string { - return ''; + $filters = $this->getFilters(); + + if (count($filters) <= 0) { + return ''; + } + + $filtersData = ''; + + /** + * @var string $filterName + * @var mixed $filterValue + */ + foreach ($filters as $filterName => $filterValue) { + $filtersData .= sprintf( + "%s: %s,\n", + $filterName, + (string) $filterValue + ); + } + + return sprintf('( + %s + )', $filtersData); } private function addFiltersToQuery(): void From cd9c47a642e41955db25a1f7d5dc649b543237aa Mon Sep 17 00:00:00 2001 From: Tomasz Grochowski Date: Tue, 21 Dec 2021 17:16:43 +0100 Subject: [PATCH 2/3] Modify order of variables to get more meaningull error message --- src/Behat/Context/GraphqlApiPlatformContext.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Behat/Context/GraphqlApiPlatformContext.php b/src/Behat/Context/GraphqlApiPlatformContext.php index 6bf3ced1..00909bc7 100644 --- a/src/Behat/Context/GraphqlApiPlatformContext.php +++ b/src/Behat/Context/GraphqlApiPlatformContext.php @@ -152,7 +152,7 @@ public function thatResponseShouldContainKeyWithValue(string $key, $value): void { /** @psalm-suppress MixedAssignment */ $responseValueAtKey = $this->client->getValueAtKey($key); - Assert::same($value, $responseValueAtKey); + Assert::same($responseValueAtKey,$value); } /** @@ -238,13 +238,15 @@ private function getJsonFromResponse(string $response): ?array /** * @Then I add :filterName filter to this operation with :value value + * @Then I add :filterName filter to this operation with :type value :value * * @param mixed $value */ - public function iAddFilterToThisOperation(string $filterName, $value): void + public function iAddFilterToThisOperation(string $filterName, $value, string $type = null): void { $operation = $this->client->getLastOperationRequest(); Assert::isInstanceOf($operation, OperationRequestInterface::class); + $value = $this->castToType($value, $type); $operation->addFilter($filterName, $value); } } From 18eaced5da12c1f680727d3d1747773a7d70c40b Mon Sep 17 00:00:00 2001 From: Tomasz Grochowski Date: Tue, 21 Dec 2021 17:17:28 +0100 Subject: [PATCH 3/3] Code fixer --- src/Behat/Context/GraphqlApiPlatformContext.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Behat/Context/GraphqlApiPlatformContext.php b/src/Behat/Context/GraphqlApiPlatformContext.php index 00909bc7..cbbb6e2c 100644 --- a/src/Behat/Context/GraphqlApiPlatformContext.php +++ b/src/Behat/Context/GraphqlApiPlatformContext.php @@ -152,7 +152,7 @@ public function thatResponseShouldContainKeyWithValue(string $key, $value): void { /** @psalm-suppress MixedAssignment */ $responseValueAtKey = $this->client->getValueAtKey($key); - Assert::same($responseValueAtKey,$value); + Assert::same($responseValueAtKey, $value); } /** @@ -238,7 +238,7 @@ private function getJsonFromResponse(string $response): ?array /** * @Then I add :filterName filter to this operation with :value value - * @Then I add :filterName filter to this operation with :type value :value + * @Then I add :filterName filter to this operation with :type value :value * * @param mixed $value */