AugmentOperationTest.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435
  1. <?php declare(strict_types=1);
  2. /**
  3. * @license Apache 2.0
  4. */
  5. namespace OpenApiTests;
  6. use OpenApi\Annotations\Operation;
  7. use OpenApi\Processors\AugmentOperations;
  8. use OpenApi\StaticAnalyser;
  9. use const OpenApi\UNDEFINED;
  10. class AugmentOperationTest extends OpenApiTestCase
  11. {
  12. public function testAugmentOperation()
  13. {
  14. $analyser = new StaticAnalyser();
  15. $analysis = $analyser->fromFile(__DIR__.'/Fixtures/UsingPhpDoc.php');
  16. $analysis->process(
  17. [
  18. new AugmentOperations(),
  19. ]
  20. );
  21. $operations = $analysis->getAnnotationsOfType(Operation::class);
  22. $this->assertSame('api/test1', $operations[0]->path);
  23. $this->assertSame('Example summary', $operations[0]->summary, 'Operation summary should be taken from phpDoc');
  24. $this->assertSame("Example description...\nMore description...", $operations[0]->description, 'Operation description should be taken from phpDoc');
  25. $this->assertSame('api/test2', $operations[1]->path);
  26. $this->assertSame('Example summary', $operations[1]->summary, 'Operation summary should be taken from phpDoc');
  27. $this->assertSame(UNDEFINED, $operations[1]->description, 'This operation only has summary in the phpDoc, no description');
  28. }
  29. }