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 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
|
<?php
declare(strict_types=1);
/*
* This file is part of the JsonSchema package.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace JsonSchema\Tests\Constraints;
use PHPUnit\Framework\TestCase;
use Prophecy\Argument;
/**
* @package JsonSchema\Tests\Constraints
*/
abstract class VeryBaseTestCase extends TestCase
{
/** @var object */
private $jsonSchemaDraft03;
/** @var object */
private $jsonSchemaDraft04;
protected function getUriRetrieverMock(?object $schema): object
{
$relativeTestsRoot = realpath(__DIR__ . '/../../vendor/json-schema/json-schema-test-suite/remotes');
$jsonSchemaDraft03 = $this->getJsonSchemaDraft03();
$jsonSchemaDraft04 = $this->getJsonSchemaDraft04();
$uriRetriever = $this->prophesize('JsonSchema\UriRetrieverInterface');
$uriRetriever->retrieve('http://www.my-domain.com/schema.json')
->willReturn($schema)
->shouldBeCalled();
$uriRetriever->retrieve(Argument::any())
->will(function ($args) use ($jsonSchemaDraft03, $jsonSchemaDraft04, $relativeTestsRoot) {
if ('http://json-schema.org/draft-03/schema' === $args[0]) {
return $jsonSchemaDraft03;
} elseif ('http://json-schema.org/draft-04/schema' === $args[0]) {
return $jsonSchemaDraft04;
} elseif (0 === strpos($args[0], 'http://localhost:1234')) {
$urlParts = parse_url($args[0]);
return json_decode(file_get_contents($relativeTestsRoot . $urlParts['path']));
} elseif (0 === strpos($args[0], 'http://www.my-domain.com')) {
$urlParts = parse_url($args[0]);
return json_decode(file_get_contents($relativeTestsRoot . '/folder' . $urlParts['path']));
}
});
return $uriRetriever->reveal();
}
private function getJsonSchemaDraft03(): object
{
if (!$this->jsonSchemaDraft03) {
$this->jsonSchemaDraft03 = json_decode(
file_get_contents(__DIR__ . '/../../dist/schema/json-schema-draft-03.json')
);
}
return $this->jsonSchemaDraft03;
}
private function getJsonSchemaDraft04(): object
{
if (!$this->jsonSchemaDraft04) {
$this->jsonSchemaDraft04 = json_decode(
file_get_contents(__DIR__ . '/../../dist/schema/json-schema-draft-04.json')
);
}
return $this->jsonSchemaDraft04;
}
}
|