InfoTest.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. <?php
  2. /**
  3. * File InfoTest.php
  4. *
  5. * @author Edward Pfremmer <epfremme@nerdery.com>
  6. */
  7. namespace Epfremme\Swagger\Tests\Entity;
  8. use Epfremme\Swagger\Entity\Contact;
  9. use Epfremme\Swagger\Entity\Info;
  10. use Epfremme\Swagger\Entity\License;
  11. use Epfremme\Swagger\Tests\Mixin\SerializerContextTrait;
  12. /**
  13. * Class InfoTest
  14. *
  15. * @package Epfremme\Swagger
  16. * @subpackage Tests\Entity
  17. */
  18. class InfoTest extends \PHPUnit_Framework_TestCase
  19. {
  20. use SerializerContextTrait;
  21. /**
  22. * @var Info
  23. */
  24. protected $info;
  25. /**
  26. * {@inheritdoc}
  27. */
  28. protected function setUp()
  29. {
  30. $this->info = new Info();
  31. }
  32. /**
  33. * @covers Epfremme\Swagger\Entity\Info::getTitle
  34. * @covers Epfremme\Swagger\Entity\Info::setTitle
  35. */
  36. public function testTitle()
  37. {
  38. $this->assertClassHasAttribute('title', Info::class);
  39. $this->assertInstanceOf(Info::class, $this->info->setTitle('foo'));
  40. $this->assertAttributeEquals('foo', 'title', $this->info);
  41. $this->assertEquals('foo', $this->info->getTitle());
  42. }
  43. /**
  44. * @covers Epfremme\Swagger\Entity\Info::getDescription
  45. * @covers Epfremme\Swagger\Entity\Info::setDescription
  46. */
  47. public function testDescription()
  48. {
  49. $this->assertClassHasAttribute('description', Info::class);
  50. $this->assertInstanceOf(Info::class, $this->info->setDescription('foo'));
  51. $this->assertAttributeEquals('foo', 'description', $this->info);
  52. $this->assertEquals('foo', $this->info->getDescription());
  53. }
  54. /**
  55. * @covers Epfremme\Swagger\Entity\Info::getTermsOfService
  56. * @covers Epfremme\Swagger\Entity\Info::setTermsOfService
  57. */
  58. public function testTermsOfService()
  59. {
  60. $this->assertClassHasAttribute('termsOfService', Info::class);
  61. $this->assertInstanceOf(Info::class, $this->info->setTermsOfService('foo'));
  62. $this->assertAttributeEquals('foo', 'termsOfService', $this->info);
  63. $this->assertEquals('foo', $this->info->getTermsOfService());
  64. }
  65. /**
  66. * @covers Epfremme\Swagger\Entity\Info::getContact
  67. * @covers Epfremme\Swagger\Entity\Info::setContact
  68. */
  69. public function testContact()
  70. {
  71. $contact = new Contact();
  72. $this->assertClassHasAttribute('contact', Info::class);
  73. $this->assertInstanceOf(Info::class, $this->info->setContact($contact));
  74. $this->assertAttributeInstanceOf(Contact::class, 'contact', $this->info);
  75. $this->assertAttributeEquals($contact, 'contact', $this->info);
  76. $this->assertEquals($contact, $this->info->getContact());
  77. }
  78. /**
  79. * @covers Epfremme\Swagger\Entity\Info::getLicense
  80. * @covers Epfremme\Swagger\Entity\Info::setLicense
  81. */
  82. public function testLicense()
  83. {
  84. $license = new License();
  85. $this->assertClassHasAttribute('license', Info::class);
  86. $this->assertInstanceOf(Info::class, $this->info->setLicense($license));
  87. $this->assertAttributeInstanceOf(License::class, 'license', $this->info);
  88. $this->assertAttributeEquals($license, 'license', $this->info);
  89. $this->assertEquals($license, $this->info->getLicense());
  90. }
  91. /**
  92. * @covers Epfremme\Swagger\Entity\Info::getVersion
  93. * @covers Epfremme\Swagger\Entity\Info::setVersion
  94. */
  95. public function testVersion()
  96. {
  97. $this->assertClassHasAttribute('version', Info::class);
  98. $this->assertInstanceOf(Info::class, $this->info->setVersion('1.0.0'));
  99. $this->assertAttributeEquals('1.0.0', 'version', $this->info);
  100. $this->assertEquals('1.0.0', $this->info->getVersion());
  101. }
  102. /**
  103. * @covers Epfremme\Swagger\Entity\Info
  104. */
  105. public function testSerialize()
  106. {
  107. $data = json_encode([
  108. 'title' => 'foo',
  109. 'description' => 'bar',
  110. 'termsOfService' => 'baz',
  111. 'contact' => (object)[],
  112. 'license' => (object)[],
  113. 'version' => '1.0.0'
  114. ]);
  115. $info = $this->getSerializer()->deserialize($data, Info::class, 'json');
  116. $this->assertInstanceOf(Info::class, $info);
  117. $this->assertAttributeEquals('foo', 'title', $info);
  118. $this->assertAttributeEquals('bar', 'description', $info);
  119. $this->assertAttributeEquals('baz', 'termsOfService', $info);
  120. $this->assertAttributeInstanceOf(Contact::class, 'contact', $info);
  121. $this->assertAttributeInstanceOf(License::class, 'license', $info);
  122. $this->assertAttributeEquals('1.0.0', 'version', $info);
  123. $json = $this->getSerializer()->serialize($info, 'json');
  124. $this->assertJson($json);
  125. $this->assertJsonStringEqualsJsonString($data, $json);
  126. }
  127. }