diff --git a/src/JsonSchema/Uri/Retrievers/FileGetContents.php b/src/JsonSchema/Uri/Retrievers/FileGetContents.php index 60e13d1e..bc43de6d 100644 --- a/src/JsonSchema/Uri/Retrievers/FileGetContents.php +++ b/src/JsonSchema/Uri/Retrievers/FileGetContents.php @@ -32,8 +32,13 @@ public function retrieve($uri) 'method' => 'GET', 'header' => "Accept: " . Validator::SCHEMA_MEDIA_TYPE ))); - + + set_error_handler(function() use ($uri) { + throw new ResourceNotFoundException('JSON schema not found at ' . $uri); + }); $response = file_get_contents($uri); + restore_error_handler(); + if (false === $response) { throw new ResourceNotFoundException('JSON schema not found at ' . $uri); } diff --git a/tests/JsonSchema/Tests/Uri/Fixture/child.json b/tests/JsonSchema/Tests/Uri/Fixture/child.json new file mode 100644 index 00000000..ce7d7404 --- /dev/null +++ b/tests/JsonSchema/Tests/Uri/Fixture/child.json @@ -0,0 +1,11 @@ +{ + "type":"object", + "title":"parent", + "properties": + { + "parentProp": + { + "type":"boolean" + } + } +} \ No newline at end of file diff --git a/tests/JsonSchema/Tests/Uri/Retrievers/FileGetContentsTest.php b/tests/JsonSchema/Tests/Uri/Retrievers/FileGetContentsTest.php new file mode 100644 index 00000000..93fc7d6f --- /dev/null +++ b/tests/JsonSchema/Tests/Uri/Retrievers/FileGetContentsTest.php @@ -0,0 +1,27 @@ +retrieve(__DIR__.'/Fixture/missing.json'); + } + + public function testFetchFile() + { + $res = new FileGetContents(); + $result = $res->retrieve(__DIR__.'/../Fixture/child.json'); + $this->assertNotEmpty($result); + } +}