ExamplesTest.php 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <?php
  2. /**
  3. * File ExamplesTest.php
  4. *
  5. * @author Edward Pfremmer <epfremme@nerdery.com>
  6. */
  7. namespace Epfremme\Swagger\Tests\Entity;
  8. use Doctrine\Common\Collections\ArrayCollection;
  9. use Epfremme\Swagger\Entity\Examples;
  10. use Epfremme\Swagger\Tests\Mixin\SerializerContextTrait;
  11. /**
  12. * Class ExamplesTest
  13. *
  14. * @package Epfremme\Swagger
  15. * @subpackage Tests\Entity
  16. */
  17. class ExamplesTest extends \PHPUnit_Framework_TestCase
  18. {
  19. use SerializerContextTrait;
  20. /**
  21. * @var Examples
  22. */
  23. protected $examples;
  24. /**
  25. * {@inheritdoc}
  26. */
  27. protected function setUp()
  28. {
  29. $this->examples = new Examples();
  30. }
  31. /**
  32. * @covers Epfremme\Swagger\Entity\Examples::getExamples
  33. * @covers Epfremme\Swagger\Entity\Examples::setExamples
  34. */
  35. public function testExamples()
  36. {
  37. $examples = new ArrayCollection([
  38. 'text/plain' => [
  39. 'foo' => 'bar',
  40. 'baz' => 'foo'
  41. ],
  42. 'application/json' => [
  43. 'key' => 'any'
  44. ],
  45. ]);
  46. $this->assertClassHasAttribute('examples', Examples::class);
  47. $this->assertInstanceOf(Examples::class, $this->examples->setExamples($examples));
  48. $this->assertAttributeInstanceOf(ArrayCollection::class, 'examples', $this->examples);
  49. $this->assertAttributeEquals($examples, 'examples', $this->examples);
  50. $this->assertEquals($examples, $this->examples->getExamples());
  51. $this->assertContainsOnly('array', $this->examples->getExamples());
  52. $this->assertCount(2, $this->examples->getExamples());
  53. }
  54. /**
  55. * @covers Epfremme\Swagger\Entity\Examples
  56. */
  57. public function testSerialize()
  58. {
  59. $data = json_encode([
  60. 'text/plain' => [
  61. 'foo' => 'bar',
  62. 'baz' => 'foo'
  63. ],
  64. 'application/json' => [
  65. 'key' => 'any'
  66. ],
  67. ]);
  68. $examples = $this->getSerializer()->deserialize($data, Examples::class, 'json');
  69. $this->assertInstanceOf(Examples::class, $examples);
  70. $this->assertAttributeInstanceOf(ArrayCollection::class, 'examples', $examples);
  71. $this->assertContainsOnly('array', $examples->getExamples());
  72. $this->assertCount(2, $examples->getExamples());
  73. $json = $this->getSerializer()->serialize($examples, 'json');
  74. $this->assertJson($json);
  75. $this->assertJsonStringEqualsJsonString($data, $json);
  76. }
  77. }