Skip to content
This repository was archived by the owner on Apr 20, 2021. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions i18n/en.xliff.dist
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,10 @@
<source>the JSON node :node should be equal to :text</source>
<target></target>
</trans-unit>
<trans-unit id="the-json-node-should-match">
<source>the JSON node :node should match :pattern</source>
<target></target>
</trans-unit>
<trans-unit id="the-json-nodes-should-be-equal-to">
<source>the JSON nodes should be equal to:</source>
<target></target>
Expand Down
18 changes: 18 additions & 0 deletions src/Context/JsonContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,24 @@ public function theJsonNodesShouldBeEqualTo(TableNode $nodes)
}
}

/**
* Checks, that given JSON node matches given pattern
*
* @Then the JSON node :node should match :pattern
*/
public function theJsonNodeShouldMatch($node, $pattern)
{
$json = $this->getJson();

$actual = $this->inspector->evaluate($json, $node);

if (preg_match($pattern, $actual) === 0) {
throw new \Exception(
sprintf("The node value is '%s'", json_encode($actual))
);
}
}

/**
* Checks, that given JSON node is null
*
Expand Down
3 changes: 3 additions & 0 deletions tests/features/json.feature
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ Feature: Testing JSONContext
And the JSON node "numbers[3].complexeshizzle" should be equal to "true"
And the JSON node "numbers[3].so[0]" should be equal to "very"
And the JSON node "numbers[3].so[1].complicated" should be equal to "indeed"
And the JSON node "numbers[0]" should match "/o.{1}e/"
And the JSON node "numbers[1]" should match "/.{2}o/"
And the JSON node "numbers[2]" should match "/[a-z]{3}e.+/"

And the JSON nodes should be equal to:
| foo | bar |
Expand Down