* @license http://www.apache.org/licenses/LICENSE-2.0 * @link http://phpsx.org */ class TypeSchemaTest extends ParserTestCase { public function testParse() { $schema = TypeSchema::fromFile(__DIR__ . '/TypeSchema/test_schema.json'); $this->assertSchema($this->getSchema(), $schema); } public function testParseTypeSchema() { $schema = TypeSchema::fromFile(__DIR__ . '/TypeSchema/typeschema.json'); $type = $schema->getType(); $this->assertInstanceOf(TypeInterface::class, $type); } public function testDiscriminator() { $schema = TypeSchema::fromFile(__DIR__ . '/TypeSchema/form_container.json'); $this->assertDiscriminator($schema); } public function testParseExternalResource() { $mock = new MockHandler([ new Response(200, [], file_get_contents(__DIR__ . '/TypeSchema/test_schema.json')), ]); $container = []; $history = Middleware::history($container); $stack = HandlerStack::create($mock); $stack->push($history); $client = new Client\Client(['handler' => $stack]); $resolver = TypeSchema\ImportResolver::createDefault($client); $parser = new TypeSchema($resolver); $schema = $parser->parse(file_get_contents(__DIR__ . '/TypeSchema/test_schema_external.json')); /** @var StructType $type */ $type = $schema->getType(); $this->assertInstanceOf(StructType::class, $type); $reference = $type->getProperty('user'); $this->assertInstanceOf(ReferenceType::class, $reference); $type = $schema->getDefinitions()->getType($reference->getRef()); $this->assertInstanceOf(StructType::class, $type); $this->assertEquals(1, count($container)); $transaction = array_shift($container); $this->assertEquals('GET', $transaction['request']->getMethod()); $this->assertEquals(['acme.com'], $transaction['request']->getHeader('Host')); } public function testParseInvalidFile() { $this->expectException(\RuntimeException::class); $this->expectExceptionMessageMatches('/^Could not load json schema (.*)$/'); TypeSchema::fromFile(__DIR__ . '/TypeSchema/foo.json'); } } __halt_compiler();----SIGNATURE:----bNnDJXjXAeqmsADDmNtA9xp3iZhFtyLCPlTu9TSU1q35LVzNz5Bi8Ju3GlNNG7d1DyQGq+lTyUhRRFWAcMD2dvjY/4SDeZDSd914EkOGtcKrP3Bb6O9S6EFy9vBKsnCnwFwKXw+4+4qc/vapxcSs5a2PPITsimCAqNKrCHrJxAFAsxlmMK7O781pvztG//e0bcxRoYjsWXGrSPljoTY0Ae7N31wU8q+9r0GTNjXC5jE7nq4KbMSp3aRxMExKuReYpOB6p51znk2ZBQTgq4Q321Knh2lfvd7tM7Cozngp/Prpz7FqRvxXggfuPED12ZZVx6QmU3Pu3X6UmNR5quebHf91NYmD6a0ByfPNvXpdixo0mjhxvQe/YxO4Fq2MOdVt27wjepiHKXXB7fRTMppRn17GcDFbT2+hHCsee05Oi0ed7gGX1adOLsEJUs2VDH+S/VnlDXDQKCKNWP+XXIqi4tIdEpMPUEkRnkoWs8jkmrcUCW6/llploHN0Fz/wTAhtEV1VNAH/DGiM4kpaZJKVfaqCvje+Ti++QiK9DLvj4UlOf9Gtk+oFEjOMjoO2JI6JZ7GcslF1CcuMRcB6S8FIRLhlGs5l+H8PlPyTzqSweMgFjIxRnoPgy2RdnM0HWLVwxtecI/lTXUfgKSBYj1NEwun8nE1WxDGQEAap2xnHeYc=----ATTACHMENT:----MzQwNTgwMjEwNDYyMTgwMiAzNTIzNzE5NDMxMzA0MzU4IDg3MTUzNjE4OTMyNzc=