LicenseTest.php 2.1 KB

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