BuildPathsTest.php 1.5 KB

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