Skip to content

Commit 7f55a97

Browse files
committed
Merge pull request #153 from alecsammon/missingFileWarning
Fix warning on file_get_contents
2 parents c76301b + 15ce6bf commit 7f55a97

File tree

3 files changed

+44
-1
lines changed

3 files changed

+44
-1
lines changed

src/JsonSchema/Uri/Retrievers/FileGetContents.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,13 @@ public function retrieve($uri)
3232
'method' => 'GET',
3333
'header' => "Accept: " . Validator::SCHEMA_MEDIA_TYPE
3434
)));
35-
35+
36+
set_error_handler(function() use ($uri) {
37+
throw new ResourceNotFoundException('JSON schema not found at ' . $uri);
38+
});
3639
$response = file_get_contents($uri);
40+
restore_error_handler();
41+
3742
if (false === $response) {
3843
throw new ResourceNotFoundException('JSON schema not found at ' . $uri);
3944
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"type":"object",
3+
"title":"parent",
4+
"properties":
5+
{
6+
"parentProp":
7+
{
8+
"type":"boolean"
9+
}
10+
}
11+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
namespace JsonSchema\Tests\Uri\Retrievers;
4+
5+
use JsonSchema\Uri\Retrievers\FileGetContents;
6+
7+
/**
8+
* @group FileGetContents
9+
*/
10+
class FileGetContentsTest extends \PHPUnit_Framework_TestCase
11+
{
12+
/**
13+
* @expectedException JsonSchema\Exception\ResourceNotFoundException
14+
*/
15+
public function testFetchMissingFile()
16+
{
17+
$res = new FileGetContents();
18+
$res->retrieve(__DIR__.'/Fixture/missing.json');
19+
}
20+
21+
public function testFetchFile()
22+
{
23+
$res = new FileGetContents();
24+
$result = $res->retrieve(__DIR__.'/../Fixture/child.json');
25+
$this->assertNotEmpty($result);
26+
}
27+
}

0 commit comments

Comments
 (0)