1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
|
<?php
namespace JsonSchema\Tests\Uri\Retrievers;
use JsonSchema\Uri\Retrievers\FileGetContents;
use PHPUnit\Framework\TestCase;
/**
* @group FileGetContents
*/
class FileGetContentsTest extends TestCase
{
public function testFetchMissingFile(): void
{
$res = new FileGetContents();
$this->expectException(\JsonSchema\Exception\ResourceNotFoundException::class);
$res->retrieve(__DIR__ . '/Fixture/missing.json');
}
public function testFetchFile(): void
{
$res = new FileGetContents();
$result = $res->retrieve(__DIR__ . '/../Fixture/child.json');
$this->assertNotEmpty($result);
}
public function testContentType(): void
{
$res = new FileGetContents();
$reflector = new \ReflectionObject($res);
$fetchContentType = $reflector->getMethod('fetchContentType');
$fetchContentType->setAccessible(true);
$this->assertTrue($fetchContentType->invoke($res, ['Content-Type: application/json']));
$this->assertFalse($fetchContentType->invoke($res, ['X-Some-Header: whateverValue']));
}
public function testCanHandleHttp301PermanentRedirect(): void
{
$res = new FileGetContents();
$res->retrieve('http://asyncapi.com/definitions/2.0.0/asyncapi.json');
$this->assertSame('application/schema+json', $res->getContentType());
}
}
|