Skip to content

Inline references broken #301

@thewilkybarkid

Description

@thewilkybarkid

When passing a schema object, rather than a reference to a schema as the README now suggests, #277 now causes inline references to break.

Failing test case:

<?php

namespace JsonSchema\Tests;

use JsonSchema\Validator;

class ValidatorTest extends \PHPUnit_Framework_TestCase
{
    /** @var Validator */
    private $validator;

    /**
     * @before
     */
    final protected function setUpValidator()
    {
        $this->validator = new Validator();
    }

    /**
     * @dataProvider schemaProvider
     */
    public function testValidatesSchema(array $data, $schema)
    {
        $this->validator->check((object) $data, $schema);
    }

    public function schemaProvider()
    {
        $schema = realpath(__DIR__.'/fixtures/json-schema-draft-04.json');

        return array(
            'reference to schema' => array(array('foo' => 'bar'), (object) array('$ref' => 'file://'.$schema)),
            'decoded schema' => array(array('foo' => 'bar'), json_decode(file_get_contents($schema))),
        );
    }
}

causes:

JsonSchema\Tests\ValidatorTest::testValidatesSchema with data set "decoded schema" (array('bar'), stdClass Object (...))
JsonSchema\Exception\ResourceNotFoundException: file_get_contents(): Filename cannot be empty

/path/to/json-schema/src/JsonSchema/Uri/Retrievers/FileGetContents.php:38
/path/to/json-schema/src/JsonSchema/Uri/UriRetriever.php:173
/path/to/json-schema/src/JsonSchema/Uri/UriRetriever.php:146
/path/to/json-schema/src/JsonSchema/SchemaStorage.php:48
/path/to/json-schema/src/JsonSchema/SchemaStorage.php:67
/path/to/json-schema/src/JsonSchema/SchemaStorage.php:76
/path/to/json-schema/src/JsonSchema/SchemaStorage.php:102
/path/to/json-schema/src/JsonSchema/Constraints/Constraint.php:234
/path/to/json-schema/src/JsonSchema/Constraints/ObjectConstraint.php:130
/path/to/json-schema/src/JsonSchema/Constraints/ObjectConstraint.php:38
/path/to/json-schema/src/JsonSchema/Constraints/Constraint.php:202
/path/to/json-schema/src/JsonSchema/Constraints/UndefinedConstraint.php:66
/path/to/json-schema/src/JsonSchema/Constraints/UndefinedConstraint.php:41
/path/to/json-schema/src/JsonSchema/Constraints/Constraint.php:234
/path/to/json-schema/src/JsonSchema/Constraints/SchemaConstraint.php:30
/path/to/json-schema/src/JsonSchema/Validator.php:37
/path/to/json-schema/tests/ValidatorTest.php:25

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions