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