Skip to content

Fix warning on file_get_contents #153

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 14, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/JsonSchema/Uri/Retrievers/FileGetContents.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
11 changes: 11 additions & 0 deletions tests/JsonSchema/Tests/Uri/Fixture/child.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"type":"object",
"title":"parent",
"properties":
{
"parentProp":
{
"type":"boolean"
}
}
}
27 changes: 27 additions & 0 deletions tests/JsonSchema/Tests/Uri/Retrievers/FileGetContentsTest.php
Original file line number Diff line number Diff line change
@@ -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);
}
}