* @license http://www.apache.org/licenses/LICENSE-2.0 * @link http://phpsx.org */ class OpenAPITest extends ParserTestCase { /** * @inheritDoc */ protected function getSpecification(): SpecificationInterface { return $this->apiManager->getApi(__DIR__ . '/openapi/simple.json', '/foo', ApiManager::TYPE_OPENAPI); } public function testParseComplex() { $specification = OpenAPI::fromFile(__DIR__ . '/openapi/complex.json', '/foo'); $resource = $specification->getResourceCollection()->get('/foo'); $definitions = $specification->getDefinitions(); $this->assertEquals('/foo', $resource->getPath()); $this->assertEquals('Test', $resource->getTitle()); $this->assertEquals('Test description', $resource->getDescription()); $path = $definitions->getType($resource->getPathParameters()); $this->assertInstanceOf(StructType::class, $path); $this->assertInstanceOf(TypeInterface::class, $path->getProperty('fooId')); $methods = $resource->getMethods(); $this->assertEquals(['GET'], array_keys($methods)); $this->assertEquals('A long **Test** description', $methods['GET']->getDescription()); $query = $definitions->getType($methods['GET']->getQueryParameters()); $this->assertInstanceOf(StructType::class, $query); $this->assertInstanceOf(TypeInterface::class, $query->getProperty('bar')); $request = $definitions->getType($methods['GET']->getRequest()); $this->assertInstanceOf(StructType::class, $request); $this->assertInstanceOf(TypeInterface::class, $request->getProperty('artist')); $response = $definitions->getType($methods['GET']->getResponse(200)); $this->assertInstanceOf(StructType::class, $response); $this->assertInstanceOf(TypeInterface::class, $response->getProperty('artist')); $response = $definitions->getType($methods['GET']->getResponse(500)); $this->assertInstanceOf(StructType::class, $response); $this->assertInstanceOf(TypeInterface::class, $response->getProperty('success')); } public function testParsePath() { $specification = OpenAPI::fromFile(__DIR__ . '/openapi/test.json', '/foo/:fooId'); $this->assertInstanceOf(Resource::class, $specification->getResourceCollection()->get('/foo/:fooId')); } public function testParseInvalidPath() { $specification = OpenAPI::fromFile(__DIR__ . '/openapi/test.json', '/test'); $this->assertEquals(0, count($specification->getResourceCollection())); } public function testParseAll() { $reader = new SimpleAnnotationReader(); $reader->addNamespace('PSX\\Schema\\Annotation'); $parser = new OpenAPI($reader, __DIR__ . '/openapi'); $specification = $parser->parse(file_get_contents(__DIR__ . '/openapi/simple.json')); $this->assertInstanceOf(ResourceCollection::class, $specification->getResourceCollection()); $this->assertEquals(['/foo'], array_keys($specification->getResourceCollection()->getArrayCopy())); } } __halt_compiler();----SIGNATURE:----WlfYVatT00K2T4D0QXq/0bOfvEMiOg4V5451/sQV8HrkZsszMEoT7/9HbvWkqdYGY1p6tnDCzRvrpIzCn+qUmmyoex5VIsw3p0Z067bYURtOhAs/si41MYvNZ7udQyKzufC/o4SeRPwvT1Xf0CdHGZkWpP3wvTq5/ejp4eHQQ5NDGTzCWShFbszeYmL0g6NlCXWVaVjWR77UVvH5TZb86ehTaDhU46XkTuGiJVPMNs6VS533hTrv8SCTDbMs6CQUlRXs9imX3bCSmyyTbvng/PezGV07B6Bxs1Cd+ON/sGLqgizv7l2fmS142x6OymBe45DdBvVH0HKvV7guDpCQjosxxkzEXO24KauhT4/poI79NkuQvTrrpW/dWMMmEieZgO2wxuNMflviWm2fI4SV5H0xXABe4lm8SvJ3RhYUGQNICZWAiEqjEb8/zItLVpwUYx6AaiomzfiC3U6Ha0o06gmbemcvjo+8nuIrHMDHl7R8kNsCPE5vIkv56xvpXzsQ6yDUaKu3XtoC0LVigEoizyqJoMgLrO5iqDq0lvlCbxrurx7sItJmOqI9IVfu0qE8ke5xxESzsrYzHlYw+QuAtDZ0ivFjadI/3/JA9XUIJy4uYd1av/0Oq6wSF+LBY2CsMe0zXfBzGyf6JcwmaaOuyVfw6X1rthh6zMZkeeNBQZo=----ATTACHMENT:----ODAxMDcxMzg0NjA2NDA5IDIwMTY5MjA3NzkyMjU2ODcgNDg2Mjc5OTk0NjQzMjgyNA==