Skip to content

Commit

Permalink
Implement format filters method logic
Browse files Browse the repository at this point in the history
  • Loading branch information
tbuczen committed Dec 21, 2021
1 parent 516ce88 commit 662dca6
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
12 changes: 12 additions & 0 deletions src/Behat/Context/GraphqlApiPlatformContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
24 changes: 23 additions & 1 deletion src/Behat/Model/OperationRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 662dca6

Please sign in to comment.