ContactTest.php 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <?php
  2. /**
  3. * File ContactTest.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\Tests\Mixin\SerializerContextTrait;
  10. /**
  11. * Class ContactTest
  12. *
  13. * @package Epfremme\Swagger
  14. * @subpackage Tests\Entity
  15. */
  16. class ContactTest extends \PHPUnit_Framework_TestCase
  17. {
  18. use SerializerContextTrait;
  19. /**
  20. * @var Contact
  21. */
  22. protected $contact;
  23. /**
  24. * {@inheritdoc}
  25. */
  26. protected function setUp()
  27. {
  28. $this->contact = new Contact();
  29. }
  30. /**
  31. * @covers Epfremme\Swagger\Entity\Contact::getName
  32. * @covers Epfremme\Swagger\Entity\Contact::setName
  33. */
  34. public function testName()
  35. {
  36. $this->assertClassHasAttribute('name', Contact::class);
  37. $this->assertInstanceOf(Contact::class, $this->contact->setName('foo'));
  38. $this->assertAttributeEquals('foo', 'name', $this->contact);
  39. $this->assertEquals('foo', $this->contact->getName());
  40. }
  41. /**
  42. * @covers Epfremme\Swagger\Entity\Contact::getUrl
  43. * @covers Epfremme\Swagger\Entity\Contact::setUrl
  44. */
  45. public function testUrl()
  46. {
  47. $this->assertClassHasAttribute('url', Contact::class);
  48. $this->assertInstanceOf(Contact::class, $this->contact->setUrl('foo'));
  49. $this->assertAttributeEquals('foo', 'url', $this->contact);
  50. $this->assertEquals('foo', $this->contact->getUrl());
  51. }
  52. /**
  53. * @covers Epfremme\Swagger\Entity\Contact::getEmail
  54. * @covers Epfremme\Swagger\Entity\Contact::setEmail
  55. */
  56. public function testEmail()
  57. {
  58. $this->assertClassHasAttribute('email', Contact::class);
  59. $this->assertInstanceOf(Contact::class, $this->contact->setEmail('foo'));
  60. $this->assertAttributeEquals('foo', 'email', $this->contact);
  61. $this->assertEquals('foo', $this->contact->getEmail());
  62. }
  63. /**
  64. * @covers Epfremme\Swagger\Entity\Contact
  65. */
  66. public function testSerialize()
  67. {
  68. $data = json_encode([
  69. 'name' => 'foo',
  70. 'url' => 'bar',
  71. 'email' => 'baz',
  72. ]);
  73. $contact = $this->getSerializer()->deserialize($data, Contact::class, 'json');
  74. $this->assertInstanceOf(Contact::class, $contact);
  75. $this->assertAttributeEquals('foo', 'name', $contact);
  76. $this->assertAttributeEquals('bar', 'url', $contact);
  77. $this->assertAttributeEquals('baz', 'email', $contact);
  78. $json = $this->getSerializer()->serialize($contact, 'json');
  79. $this->assertJson($json);
  80. $this->assertJsonStringEqualsJsonString($data, $json);
  81. }
  82. }