Merge pull request #153 from alecsammon/missingFileWarning

Fix warning on file_get_contents
This commit is contained in:
David Porter 2015-06-14 14:57:49 -05:00
commit 7f55a9727e
3 changed files with 44 additions and 1 deletions

View File

@ -32,8 +32,13 @@ class FileGetContents extends AbstractRetriever
'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);
}

View File

@ -0,0 +1,11 @@
{
"type":"object",
"title":"parent",
"properties":
{
"parentProp":
{
"type":"boolean"
}
}
}

View File

@ -0,0 +1,27 @@
<?php
namespace JsonSchema\Tests\Uri\Retrievers;
use JsonSchema\Uri\Retrievers\FileGetContents;
/**
* @group FileGetContents
*/
class FileGetContentsTest extends \PHPUnit_Framework_TestCase
{
/**
* @expectedException JsonSchema\Exception\ResourceNotFoundException
*/
public function testFetchMissingFile()
{
$res = new FileGetContents();
$res->retrieve(__DIR__.'/Fixture/missing.json');
}
public function testFetchFile()
{
$res = new FileGetContents();
$result = $res->retrieve(__DIR__.'/../Fixture/child.json');
$this->assertNotEmpty($result);
}
}