| @@ 45-63 (lines=19) @@ | ||
| 42 | } |
|
| 43 | ||
| 44 | /** @Then in the json, :path should match: */ |
|
| 45 | public function path_should_match(string $path, PyStringNode $pattern) |
|
| 46 | { |
|
| 47 | $value = $this->getValue($path); |
|
| 48 | $matcher = $this->factory->createMatcher(); |
|
| 49 | ||
| 50 | $json = json_encode($value); |
|
| 51 | ||
| 52 | if ($matcher->match($value, $pattern->getRaw())) { |
|
| 53 | return; |
|
| 54 | } |
|
| 55 | ||
| 56 | throw new InvalidArgumentException( |
|
| 57 | sprintf( |
|
| 58 | 'The json path "%s" does not match with the given pattern (error : %s)', |
|
| 59 | $path, |
|
| 60 | $matcher->getError() |
|
| 61 | ) |
|
| 62 | ); |
|
| 63 | } |
|
| 64 | ||
| 65 | /** @Then in the json, :path should not match: */ |
|
| 66 | public function path_should_not_match(string $path, PyStringNode $pattern) |
|
| @@ 66-84 (lines=19) @@ | ||
| 63 | } |
|
| 64 | ||
| 65 | /** @Then in the json, :path should not match: */ |
|
| 66 | public function path_should_not_match(string $path, PyStringNode $pattern) |
|
| 67 | { |
|
| 68 | $value = $this->getValue($path); |
|
| 69 | $matcher = $this->factory->createMatcher(); |
|
| 70 | ||
| 71 | $json = json_encode($value); |
|
| 72 | ||
| 73 | if (!$matcher->match($value, $pattern->getRaw())) { |
|
| 74 | return; |
|
| 75 | } |
|
| 76 | ||
| 77 | throw new InvalidArgumentException( |
|
| 78 | sprintf( |
|
| 79 | 'The json path "%s" matches with the given pattern (error : %s)', |
|
| 80 | $path, |
|
| 81 | $matcher->getError() |
|
| 82 | ) |
|
| 83 | ); |
|
| 84 | } |
|
| 85 | ||
| 86 | /** @Then in the json, :path should match :pattern */ |
|
| 87 | public function path_should_match_pattern(string $path, string $pattern) |
|
| @@ 87-106 (lines=20) @@ | ||
| 84 | } |
|
| 85 | ||
| 86 | /** @Then in the json, :path should match :pattern */ |
|
| 87 | public function path_should_match_pattern(string $path, string $pattern) |
|
| 88 | { |
|
| 89 | $value = $this->getValue($path); |
|
| 90 | $matcher = $this->factory->createMatcher(); |
|
| 91 | ||
| 92 | $json = json_encode($value); |
|
| 93 | ||
| 94 | if ($matcher->match($value, $pattern)) { |
|
| 95 | return; |
|
| 96 | } |
|
| 97 | ||
| 98 | throw new InvalidArgumentException( |
|
| 99 | sprintf( |
|
| 100 | 'The json path "%s" does not match with the pattern "%s" (error : %s)', |
|
| 101 | $path, |
|
| 102 | $pattern, |
|
| 103 | $matcher->getError() |
|
| 104 | ) |
|
| 105 | ); |
|
| 106 | } |
|
| 107 | ||
| 108 | /** @Then in the json, :path should not match :pattern */ |
|
| 109 | public function path_should_not_match_pattern(string $path, PyStringNode $pattern) |
|
| @@ 109-128 (lines=20) @@ | ||
| 106 | } |
|
| 107 | ||
| 108 | /** @Then in the json, :path should not match :pattern */ |
|
| 109 | public function path_should_not_match_pattern(string $path, PyStringNode $pattern) |
|
| 110 | { |
|
| 111 | $value = $this->getValue($path); |
|
| 112 | $matcher = $this->factory->createMatcher(); |
|
| 113 | ||
| 114 | $json = json_encode($value); |
|
| 115 | ||
| 116 | if (!$matcher->match($value, $pattern)) { |
|
| 117 | return; |
|
| 118 | } |
|
| 119 | ||
| 120 | throw new InvalidArgumentException( |
|
| 121 | sprintf( |
|
| 122 | 'The json path "%s" matches with the pattern "%s" (error : %s)', |
|
| 123 | $path, |
|
| 124 | $pattern, |
|
| 125 | $matcher->getError() |
|
| 126 | ) |
|
| 127 | ); |
|
| 128 | } |
|
| 129 | } |
|
| 130 | ||