ExternalDocumentationTest.php 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <?php
  2. /**
  3. * File ExternalDocumentationTest.php
  4. *
  5. * @author Edward Pfremmer <epfremme@nerdery.com>
  6. */
  7. namespace Epfremme\Swagger\Tests\Entity;
  8. use Epfremme\Swagger\Entity\ExternalDocumentation;
  9. use Epfremme\Swagger\Tests\Mixin\SerializerContextTrait;
  10. /**
  11. * Class ExternalDocumentationTest
  12. *
  13. * @package Epfremme\Swagger
  14. * @subpackage Tests\Entity
  15. */
  16. class ExternalDocumentationTest extends \PHPUnit_Framework_TestCase
  17. {
  18. use SerializerContextTrait;
  19. /**
  20. * @var ExternalDocumentation
  21. */
  22. protected $externalDocumentation;
  23. /**
  24. * {@inheritdoc}
  25. */
  26. protected function setUp()
  27. {
  28. $this->externalDocumentation = new ExternalDocumentation();
  29. }
  30. /**
  31. * @covers Epfremme\Swagger\Entity\ExternalDocumentation::getDescription
  32. * @covers Epfremme\Swagger\Entity\ExternalDocumentation::setDescription
  33. */
  34. public function testDescription()
  35. {
  36. $this->assertClassHasAttribute('description', ExternalDocumentation::class);
  37. $this->assertInstanceOf(ExternalDocumentation::class, $this->externalDocumentation->setDescription('foo'));
  38. $this->assertAttributeEquals('foo', 'description', $this->externalDocumentation);
  39. $this->assertEquals('foo', $this->externalDocumentation->getDescription());
  40. }
  41. /**
  42. * @covers Epfremme\Swagger\Entity\ExternalDocumentation::getUrl
  43. * @covers Epfremme\Swagger\Entity\ExternalDocumentation::setUrl
  44. */
  45. public function testUrl()
  46. {
  47. $this->assertClassHasAttribute('url', ExternalDocumentation::class);
  48. $this->assertInstanceOf(ExternalDocumentation::class, $this->externalDocumentation->setUrl('foo'));
  49. $this->assertAttributeEquals('foo', 'url', $this->externalDocumentation);
  50. $this->assertEquals('foo', $this->externalDocumentation->getUrl());
  51. }
  52. /**
  53. * @covers Epfremme\Swagger\Entity\ExternalDocumentation
  54. */
  55. public function testSerialize()
  56. {
  57. $data = json_encode([
  58. 'description' => 'foo',
  59. 'url' => 'bar',
  60. ]);
  61. $license = $this->getSerializer()->deserialize($data, ExternalDocumentation::class, 'json');
  62. $this->assertInstanceOf(ExternalDocumentation::class, $license);
  63. $this->assertAttributeEquals('foo', 'description', $license);
  64. $this->assertAttributeEquals('bar', 'url', $license);
  65. $json = $this->getSerializer()->serialize($license, 'json');
  66. $this->assertJson($json);
  67. $this->assertJsonStringEqualsJsonString($data, $json);
  68. }
  69. }