4
0

BuildPathsTest.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php declare(strict_types=1);
  2. /**
  3. * @license Apache 2.0
  4. */
  5. namespace OpenApiTests;
  6. use OpenApi\Analysis;
  7. use OpenApi\Annotations\Get;
  8. use OpenApi\Annotations\OpenApi;
  9. use OpenApi\Annotations\PathItem;
  10. use OpenApi\Annotations\Post;
  11. use OpenApi\Processors\BuildPaths;
  12. use OpenApi\Processors\MergeIntoOpenApi;
  13. use const OpenApi\UNDEFINED;
  14. class BuildPathsTest extends OpenApiTestCase
  15. {
  16. public function testMergePathsWithSamePath()
  17. {
  18. $openapi = new OpenApi([]);
  19. $openapi->paths = [
  20. new PathItem(['path' => '/comments']),
  21. new PathItem(['path' => '/comments']),
  22. ];
  23. $analysis = new Analysis([$openapi]);
  24. $analysis->openapi = $openapi;
  25. $analysis->process(new BuildPaths());
  26. $this->assertCount(1, $openapi->paths);
  27. $this->assertSame('/comments', $openapi->paths[0]->path);
  28. }
  29. public function testMergeOperationsWithSamePath()
  30. {
  31. $openapi = new OpenApi([]);
  32. $analysis = new Analysis(
  33. [
  34. $openapi,
  35. new Get(['path' => '/comments']),
  36. new Post(['path' => '/comments']),
  37. ]
  38. );
  39. $analysis->process(new MergeIntoOpenApi());
  40. $analysis->process(new BuildPaths());
  41. $this->assertCount(1, $openapi->paths);
  42. $path = $openapi->paths[0];
  43. $this->assertSame('/comments', $path->path);
  44. $this->assertInstanceOf(PathItem::class, $path);
  45. $this->assertInstanceOf(Get::class, $path->get);
  46. $this->assertInstanceOf(Post::class, $path->post);
  47. $this->assertSame(UNDEFINED, $path->put);
  48. }
  49. }