mirror of
https://github.com/justinrainbow/json-schema.git
synced 2025-05-02 12:28:31 +02:00
Merge pull request #153 from alecsammon/missingFileWarning
Fix warning on file_get_contents
This commit is contained in:
commit
7f55a9727e
@ -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);
|
||||
}
|
||||
|
11
tests/JsonSchema/Tests/Uri/Fixture/child.json
Normal file
11
tests/JsonSchema/Tests/Uri/Fixture/child.json
Normal file
@ -0,0 +1,11 @@
|
||||
{
|
||||
"type":"object",
|
||||
"title":"parent",
|
||||
"properties":
|
||||
{
|
||||
"parentProp":
|
||||
{
|
||||
"type":"boolean"
|
||||
}
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user