4
0

MergeXmlContentTest.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php declare(strict_types=1);
  2. /**
  3. * @license Apache 2.0
  4. */
  5. namespace OpenApiTests;
  6. use OpenApi\Analysis;
  7. use OpenApi\Annotations\Response;
  8. use OpenApi\Processors\MergeXmlContent;
  9. use const OpenApi\UNDEFINED;
  10. class MergeXmlContentTest extends OpenApiTestCase
  11. {
  12. public function testXmlContent()
  13. {
  14. $comment = <<<END
  15. @OA\Response(response=200,
  16. @OA\XmlContent(type="array",
  17. @OA\Items(ref="#/components/schemas/repository")
  18. )
  19. )
  20. END;
  21. $analysis = new Analysis($this->parseComment($comment));
  22. $this->assertCount(3, $analysis->annotations);
  23. $response = $analysis->getAnnotationsOfType(Response::class)[0];
  24. $this->assertSame(UNDEFINED, $response->content);
  25. $this->assertCount(1, $response->_unmerged);
  26. $analysis->process(new MergeXmlContent());
  27. $this->assertCount(1, $response->content);
  28. $this->assertCount(0, $response->_unmerged);
  29. $json = json_decode(json_encode($response), true);
  30. $this->assertSame('#/components/schemas/repository', $json['content']['application/xml']['schema']['items']['$ref']);
  31. }
  32. public function testMultipleMediaTypes()
  33. {
  34. $comment = <<<END
  35. @OA\Response(response=200,
  36. @OA\MediaType(mediaType="image/png"),
  37. @OA\XmlContent(type="array",
  38. @OA\Items(ref="#/components/schemas/repository")
  39. )
  40. )
  41. END;
  42. $analysis = new Analysis($this->parseComment($comment));
  43. $response = $analysis->getAnnotationsOfType(Response::class)[0];
  44. $this->assertCount(1, $response->content);
  45. $analysis->process(new MergeXmlContent());
  46. $this->assertCount(2, $response->content);
  47. }
  48. }