Skip to content

Commit

Permalink
Merge pull request BitBagCommerce#34 from tgrochowski/feature/behat-f…
Browse files Browse the repository at this point in the history
…ilters-test

Feature/behat filters test
  • Loading branch information
tbuczen authored Dec 21, 2021
2 parents 516ce88 + 18eaced commit 0306d26
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
16 changes: 15 additions & 1 deletion src/Behat/Context/GraphqlApiPlatformContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down Expand Up @@ -235,4 +235,18 @@ private function getJsonFromResponse(string $response): ?array

return null;
}

/**
* @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, string $type = null): void
{
$operation = $this->client->getLastOperationRequest();
Assert::isInstanceOf($operation, OperationRequestInterface::class);
$value = $this->castToType($value, $type);
$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 0306d26

Please sign in to comment.