|
1 | 1 | <?php |
2 | 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 |
| 3 | +namespace JsonSchema\Tests\Uri\Retrievers |
11 | 4 | { |
| 5 | + use JsonSchema\Uri\Retrievers\FileGetContents; |
| 6 | + |
12 | 7 | /** |
13 | | - * @expectedException \JsonSchema\Exception\ResourceNotFoundException |
| 8 | + * @group FileGetContents |
14 | 9 | */ |
15 | | - public function testFetchMissingFile() |
| 10 | + class FileGetContentsTest extends \PHPUnit_Framework_TestCase |
16 | 11 | { |
17 | | - $res = new FileGetContents(); |
18 | | - $res->retrieve(__DIR__ . '/Fixture/missing.json'); |
| 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 | + |
| 28 | + public function testFalseReturn() |
| 29 | + { |
| 30 | + $res = new FileGetContents(); |
| 31 | + |
| 32 | + $this->setExpectedException( |
| 33 | + '\JsonSchema\Exception\ResourceNotFoundException', |
| 34 | + 'JSON schema not found at http://example.com/false' |
| 35 | + ); |
| 36 | + $res->retrieve('http://example.com/false'); |
| 37 | + } |
| 38 | + |
| 39 | + public function testFetchDirectory() |
| 40 | + { |
| 41 | + $res = new FileGetContents(); |
| 42 | + |
| 43 | + $this->setExpectedException( |
| 44 | + '\JsonSchema\Exception\ResourceNotFoundException', |
| 45 | + 'JSON schema not found at file:///this/is/a/directory/' |
| 46 | + ); |
| 47 | + $res->retrieve('file:///this/is/a/directory/'); |
| 48 | + } |
| 49 | + |
| 50 | + public function testContentType() |
| 51 | + { |
| 52 | + $res = new FileGetContents(); |
| 53 | + |
| 54 | + $reflector = new \ReflectionObject($res); |
| 55 | + $fetchContentType = $reflector->getMethod('fetchContentType'); |
| 56 | + $fetchContentType->setAccessible(true); |
| 57 | + |
| 58 | + $this->assertTrue($fetchContentType->invoke($res, array('Content-Type: application/json'))); |
| 59 | + $this->assertFalse($fetchContentType->invoke($res, array('X-Some-Header: whateverValue'))); |
| 60 | + } |
19 | 61 | } |
| 62 | +} |
20 | 63 |
|
21 | | - public function testFetchFile() |
| 64 | +namespace JsonSchema\Uri\Retrievers |
| 65 | +{ |
| 66 | + function file_get_contents($uri) |
22 | 67 | { |
23 | | - $res = new FileGetContents(); |
24 | | - $result = $res->retrieve(__DIR__ . '/../Fixture/child.json'); |
25 | | - $this->assertNotEmpty($result); |
| 68 | + switch ($uri) { |
| 69 | + case 'http://example.com/false': return false; |
| 70 | + case 'file:///this/is/a/directory/': return ''; |
| 71 | + default: return \file_get_contents($uri); |
| 72 | + } |
26 | 73 | } |
27 | 74 | } |
0 commit comments