* @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:----hvPtLydaYGD9AAESJfUyTix0Dn/A7qm4JP5TwskrSRHqzUwN0VZe8JZ/AKWfWEwyhL8tVB0gnKwAIYowYRXcX4ug66f9A77HUTz6uURZRcnSjgMCrioZ59yoM27hpa/1aBde2YzdH/GQ1skQgPHnWRmzQ8wLI8a/dve8H+dwTrsjEuFgjJdU7A8QoIuykGgVdugcKsyG+o1kO3xk8w+CHAkOVaTvpNsK/OdHXjf4sv/dpwDzgZ/Ko+wQ56DMANWsQlB/JgmxGWGLxL2R6xZNkgMT4RBHCllsG8sb89C/MpU3CjrDW/dHCmt4dq0YI3Uzny9/3lCdYHNAMM3plFHmpu6CDS41bXefcdbV66SJ156QLIaUorZDR2MYcqfLBfYUHQFqe0PxcCjo5fxTJ4dCoBOHVFyIpaCsPYWISLdFEUMkKQEaxb5xtkia1trSid+0tMdWjWx0G+KewD+UosouzQrqFmqu6k95KKqricB7N+U9zzlEyi/yB8PdAaWlo1Wu3HYFpeTj9RywxyW9vGTIob8jVvJ1dJ5gcQZXv5H+pweKZSpEUKtsk8tEw3PVS2hmh0QElB6QT75fdfKIYmaz5E4Tpc6yr/cZw/oe2xMzo9Mh5+EIHvpmWOZUijc9T1DvfUeoYlUpGtXXaw4ce2/o6Ax9G+aHtg7z0qhdNV7xRR0=----ATTACHMENT:----NjExMTA2MjUxNTU0NTg3NSA5MTkxMTk1Mjk2Nzk1MDQgNDkzNTY1Nzk0NTY1MzA4