public function evaluate(Json $json, $expression) { if ($this->evaluationMode === 'javascript') { $expression = str_replace('->', '.', $expression); } try { return $json->read($expression, $this->propertyAccessor); } catch (\Exception $e) { throw new \Exception(sprintf('Failed to evaluate expression "%s"', $expression), 0, $e); } }
public function validate(Json $json, Validator $validator, RefResolver $refResolver) { $schema = $refResolver->resolve('file://' . realpath($this->filename)); $validator->check($json->getRawContent(), $schema); if (!$validator->isValid()) { $msg = "JSON does not validate. Violations:" . PHP_EOL; foreach ($validator->getErrors() as $error) { $msg .= sprintf(" - [%s] %s" . PHP_EOL, $error['property'], $error['message']); } throw new \Exception($msg); } return true; }
public function validate(Json $json, Validator $validator) { if ($this->hasUri()) { $this->resolve(new RefResolver(new UriRetriever())); } $validator->check($json->getRawContent(), $this->getRawContent()); if (!$validator->isValid()) { $msg = "JSON does not validate. Violations:" . PHP_EOL; foreach ($validator->getErrors() as $error) { $msg .= sprintf(" - [%s] %s" . PHP_EOL, $error['property'], $error['message']); } throw new \Exception($msg); } return true; }
public function test_should_read_valid_expression() { $this->given($accessor = PropertyAccess::createPropertyAccessor(), $sut = new SUT('{"foo":"bar"}'))->when($result = $sut->read('foo', $accessor))->phpString($result)->isEqualTo('bar'); }
/** * @Then the JSON path expression :pathExpression should be equal to json :expectedJson */ public function theJsonPathExpressionShouldBeEqualToJson($pathExpression, $expectedJson) { $expectedJson = new Json($expectedJson); $actualJson = Json::fromRawContent($this->jsonInspector->searchJsonPath($pathExpression)); $this->asserter->castToString($actualJson)->isEqualTo((string) $expectedJson); }