public function setUp() { global $testconfig; $this->api = new WPAPI($testconfig['url'], $testconfig['username'], $testconfig['password']); // Set up the schema retriever. This should be included instead, // once finalised. $schema_data = Requests::get(self::SCHEMA_BASE); $arrayretriever = new WPAPI_Test_SchemaRetriever(array(self::SCHEMA_BASE => $schema_data->body)); $this->retriever = new UriRetriever(); $this->retriever->setUriRetriever($arrayretriever); }
/** * @param string $string * @param string[] Predefined schemas: $defs name => schema. * * @return object */ public static function loadSchema($string, $defs = []) { $uri = static::$uriPrefix . 'loadedschema.json'; $schemas = [$uri => $string]; foreach ($defs as $defName => $def) { $schemas[static::$uriPrefix . $defName] = $def; } $uriRetriever = new UriRetriever(); $uriRetriever->setUriRetriever(new PredefinedArray($schemas)); $uriResolver = new UriResolver(); $refResolver = new RefResolver($uriRetriever, $uriResolver); return $refResolver->resolve($uri); }
/** * Returns the JSON validator. * * @return JsonValidator The JSON validator. */ public function getJsonValidator() { if (!$this->jsonValidator) { $uriRetriever = new UriRetriever(); // Load puli.io schemas from the schema/ directory $uriRetriever->setUriRetriever(new LocalUriRetriever()); $this->jsonValidator = new JsonValidator(null, $uriRetriever); } return $this->jsonValidator; }
public function testValidateFailsIfValidationFailsWithExternalReferences() { $uriRetriever = new UriRetriever(); $uriRetriever->setUriRetriever(new PredefinedArray(array('http://webmozart.io/fixtures/schema-refs' => file_get_contents(__DIR__ . '/Fixtures/schema-refs.json'), 'file://' . $this->fixturesDir . '/schema-external-refs.json' => file_get_contents(__DIR__ . '/Fixtures/schema-external-refs.json')))); $this->validator = new JsonValidator(null, $uriRetriever); $errors = $this->validator->validate((object) array('name' => 'Bernhard', 'has-coffee' => null), $this->fixturesDir . '/schema-external-refs.json'); $this->assertGreaterThan(1, count($errors)); }