AugmentPropertiesTest.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. /**
  3. * @license Apache 2.0
  4. */
  5. namespace SwaggerTests;
  6. use Swagger\Processors\AugmentDefinitions;
  7. use Swagger\Processors\AugmentProperties;
  8. use Swagger\Processors\MergeIntoSwagger;
  9. use Swagger\StaticAnalyser;
  10. class AugmentPropertiesTest extends SwaggerTestCase
  11. {
  12. public function testAugmentProperties()
  13. {
  14. $analyser = new StaticAnalyser();
  15. $analysis = $analyser->fromFile(__DIR__ . '/Fixtures/Customer.php');
  16. $analysis->process(new MergeIntoSwagger());
  17. $this->assertCount(1, $analysis->swagger->definitions);
  18. $customer = $analysis->swagger->definitions[0];
  19. $this->assertSame(null, $customer->properties, 'Sanity check. @SWG\Property\'s not yet erged ');
  20. $analysis->process(new AugmentDefinitions());
  21. $analysis->process(new AugmentProperties());
  22. $firstname = $customer->properties[0];
  23. $this->assertSame('firstname', $firstname->property, '@SWG\Property()->property based on propertyname');
  24. $this->assertSame('The firstname of the customer.', $firstname->description, '@SWG\Property()->description based on @var description');
  25. $this->assertSame('string', $firstname->type, '@SWG\Property()->type based on @var declaration');
  26. $lastname = $customer->properties[1];
  27. $this->assertSame('lastname', $lastname->property);
  28. $this->assertSame('The lastname of the customer.', $lastname->description);
  29. $this->assertSame('string', $lastname->type);
  30. $tags = $customer->properties[2];
  31. $this->assertSame('tags', $tags->property);
  32. $this->assertSame('array', $tags->type, 'Detect array notation: @var string[]');
  33. $this->assertSame('string', $tags->items->type);
  34. $submittedBy = $customer->properties[3];
  35. $this->assertSame('submittedBy', $submittedBy->property);
  36. $this->assertSame('#/definitions/Customer', $submittedBy->ref);
  37. $friends = $customer->properties[4];
  38. $this->assertSame('friends', $friends->property);
  39. $this->assertSame('array', $friends->type);
  40. $this->assertSame('#/definitions/Customer', $friends->items->ref);
  41. }
  42. }