From 15ce6bfeadc7d5e083192809760afe583ebbddca Mon Sep 17 00:00:00 2001 From: Alec Sammon Date: Thu, 28 May 2015 20:47:19 +0100 Subject: [PATCH] Fix warning on file_get_contents Fixes #153 --- .../Uri/Retrievers/FileGetContents.php | 7 ++++- tests/JsonSchema/Tests/Uri/Fixture/child.json | 11 ++++++++ .../Uri/Retrievers/FileGetContentsTest.php | 27 +++++++++++++++++++ 3 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 tests/JsonSchema/Tests/Uri/Fixture/child.json create mode 100644 tests/JsonSchema/Tests/Uri/Retrievers/FileGetContentsTest.php 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); + } +}