* @license http://www.apache.org/licenses/LICENSE-2.0 * @link http://phpsx.org */ class ResourceConversionTest extends ApiManagerTestCase { public function testClientPhp() { $specification = $this->getSpecification(); $generator = new Generator\Client\Php('http://api.phpsx.org'); $actual = (string) $generator->generate($specification->get('/pets')); $actual = str_replace(date('Y-m-d'), '0000-00-00', $actual); $expect = file_get_contents(__DIR__ . '/Resource/petstore/client_php.php'); $expect = str_replace(array("\r\n", "\r"), "\n", $expect); $this->assertEquals($expect, $actual, $actual); } public function testClientTypescript() { $specification = $this->getSpecification(); $generator = new Generator\Client\Typescript('http://api.phpsx.org'); $actual = (string) $generator->generate($specification->get('/pets')); $actual = str_replace(date('Y-m-d'), '0000-00-00', $actual); $expect = file_get_contents(__DIR__ . '/Resource/petstore/client_typescript.ts'); $expect = str_replace(array("\r\n", "\r"), "\n", $expect); $this->assertEquals($expect, $actual, $actual); } public function testClientGo() { $specification = $this->getSpecification(); $generator = new Generator\Client\Go('http://api.phpsx.org'); $actual = (string) $generator->generate($specification->get('/pets')); $actual = str_replace(date('Y-m-d'), '0000-00-00', $actual); $expect = file_get_contents(__DIR__ . '/Resource/petstore/client_go.go'); $expect = str_replace(array("\r\n", "\r"), "\n", $expect); $this->assertEquals($expect, $actual, $actual); } public function testMarkupHtml() { $specification = $this->getSpecification(); $generator = new Generator\Markup\Html(); $actual = $generator->generate($specification->get('/pets')); $expect = file_get_contents(__DIR__ . '/Resource/petstore/markup_html.htm'); $this->assertXmlStringEqualsXmlString('
' . $expect . '
', '
' . $actual . '
', $actual); } public function testMarkupMarkdown() { $specification = $this->getSpecification(); $generator = new Generator\Markup\Markdown(); $actual = $generator->generate($specification->get('/pets')); $expect = file_get_contents(__DIR__ . '/Resource/petstore/markup_markdown.md'); $expect = str_replace(array("\r\n", "\r"), "\n", $expect); $this->assertEquals($expect, $actual, $actual); } public function testSpecOpenAPI() { $reader = new SimpleAnnotationReader(); $reader->addNamespace('PSX\\Api\\Annotation'); $reader->addNamespace('PSX\\Schema\\Annotation'); $specification = $this->getSpecification(); $generator = new Generator\Spec\OpenAPI($reader, 1, '/', 'urn:schema.phpsx.org#'); $actual = $generator->generate($specification); $expect = file_get_contents(__DIR__ . '/Resource/petstore/spec_openapi.json'); $this->assertJsonStringEqualsJsonString($expect, $actual, $actual); } public function testSpecRaml() { $specification = $this->getSpecification(); $generator = new Generator\Spec\Raml(1, 'http://api.phpsx.org', 'urn:schema.phpsx.org#'); $actual = $generator->generate($specification); $actual = json_encode(Yaml::parse($actual)); $expect = file_get_contents(__DIR__ . '/Resource/petstore/spec_raml.yaml'); $expect = json_encode(Yaml::parse($expect)); $this->assertJsonStringEqualsJsonString($expect, $actual, $actual); } private function getSpecification(): SpecificationInterface { $reader = new SimpleAnnotationReader(); $reader->addNamespace('PSX\\Api\\Annotation'); $reader->addNamespace('PSX\\Schema\\Annotation'); $parser = new Parser\OpenAPI($reader, __DIR__ . '/Resource'); return $parser->parse(json_encode(Yaml::parse($this->getOpenAPI()))); } private function getOpenAPI() { return file_get_contents(__DIR__ . '/Resource/petstore.yaml'); } } __halt_compiler();----SIGNATURE:----XnWZS65MjFDsoPh7aTsngqnKKXFrrmCV/iuAjMWk2OfNcW2R91eA+WstavzcjqV8NBMZ066+Xc6OP5caGUF1NLBMcejq0CldFM63n3Vxj1QWqMAE+nQkYljDsj9/IfzlGQDDZEvyWq3srVSCZGubGLuzO08fxFQbYky5jcj5QLLPcVVul7sX1dVn7PsP1mmwZON6vDoRTSCfVOs6iqbvqD8Z4b5+xPKR7Gin9HHDeU1jZtremxr+ECCPtNf2gfVUNtLInoi300sfPVnajhMx/SfyvOnXZKljP4Jj8aAi66+XzIqkYuj3SPZmlROJ1vZmO3f/RpRtK4pPJtYvpZxjHX9VXGwamDIK7kSvkazv79fFeVMSENjC25waLhzm9GVgLmelxzUJU5aLuLcr8ZSu3QTeUctbQDbCY9oI9i7IhuAIZ+U+/ApirGEsnoL3OKgcTPdsOfFw5fHkdmLnD0Hst7j7CE/PHrtb6fZ5ajxUC+inJy6JpJSU0GT7n274b9IxBb5PH+SvtWXRpub2GZJ8THAMpXjl4H8zihLySwJ5EtxknqH9Vj1EckEMzWgn3ZPiVLPwFLz8BhQYHgytVwz7FEJSjAzbiAU3dgPZ1xcqo2rlq5QGlGAamReGsXAfcqywO3Bs8dBzvlRdaikqtmOBLSS/cPAiD9WKYpVcYh+G3jg=----ATTACHMENT:----NDUxNjA3MjI0ODkxMjEwNCAyNzA0NzIwNDI5NTI5MzQzIDg4NDI5NjcyMzE0MTYxNDQ=