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