| @@ 49-67 (lines=19) @@ | ||
| 46 | } |
|
| 47 | ||
| 48 | /** @Then in the json, :path should match: */ |
|
| 49 | public function path_should_match(string $path, PyStringNode $pattern) |
|
| 50 | { |
|
| 51 | $value = $this->getValue($path); |
|
| 52 | $matcher = $this->factory->createMatcher(); |
|
| 53 | ||
| 54 | $json = json_encode($value); |
|
| 55 | ||
| 56 | if ($matcher->match($json, $pattern->getRaw())) { |
|
| 57 | return; |
|
| 58 | } |
|
| 59 | ||
| 60 | throw new InvalidArgumentException( |
|
| 61 | sprintf( |
|
| 62 | 'The json path "%s" does not match with the given pattern (error : %s)', |
|
| 63 | $path, |
|
| 64 | $matcher->getError() |
|
| 65 | ) |
|
| 66 | ); |
|
| 67 | } |
|
| 68 | ||
| 69 | /** @Then in the json, :path should not match: */ |
|
| 70 | public function path_should_not_match(string $path, PyStringNode $pattern) |
|
| @@ 70-88 (lines=19) @@ | ||
| 67 | } |
|
| 68 | ||
| 69 | /** @Then in the json, :path should not match: */ |
|
| 70 | public function path_should_not_match(string $path, PyStringNode $pattern) |
|
| 71 | { |
|
| 72 | $value = $this->getValue($path); |
|
| 73 | $matcher = $this->factory->createMatcher(); |
|
| 74 | ||
| 75 | $json = json_encode($value); |
|
| 76 | ||
| 77 | if (!$matcher->match($json, $pattern->getRaw())) { |
|
| 78 | return; |
|
| 79 | } |
|
| 80 | ||
| 81 | throw new InvalidArgumentException( |
|
| 82 | sprintf( |
|
| 83 | 'The json path "%s" matches with the given pattern (error : %s)', |
|
| 84 | $path, |
|
| 85 | $matcher->getError() |
|
| 86 | ) |
|
| 87 | ); |
|
| 88 | } |
|
| 89 | ||
| 90 | private function getJson(): string |
|
| 91 | { |
|