NullSchemaTest.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. /**
  3. * File NullSchemaTest.php
  4. *
  5. * @author Edward Pfremmer <epfremme@nerdery.com>
  6. */
  7. namespace Epfremme\Swagger\Tests\Entity\Schemas;
  8. use Epfremme\Swagger\Entity\ExternalDocumentation;
  9. use Epfremme\Swagger\Entity\Schemas\AbstractSchema;
  10. use Epfremme\Swagger\Entity\Schemas\NullSchema;
  11. use Epfremme\Swagger\Tests\Mixin\SerializerContextTrait;
  12. /**
  13. * Class NullSchemaTest
  14. *
  15. * @package Epfremme\Swagger
  16. * @subpackage Tests\Entity\Schemas
  17. */
  18. class NullSchemaTest extends \PHPUnit_Framework_TestCase
  19. {
  20. use SerializerContextTrait;
  21. /**
  22. * @var NullSchema
  23. */
  24. protected $nullSchema;
  25. /**
  26. * {@inheritdoc}
  27. */
  28. protected function setUp()
  29. {
  30. $this->nullSchema = new NullSchema();
  31. }
  32. /**
  33. * @covers Epfremme\Swagger\Entity\Schemas\NullSchema::getType
  34. */
  35. public function testType()
  36. {
  37. $this->assertNotEmpty($this->nullSchema->getType());
  38. $this->assertEquals(AbstractSchema::NULL_TYPE, $this->nullSchema->getType());
  39. }
  40. /**
  41. * @covers Epfremme\Swagger\Entity\Schemas\NullSchema
  42. */
  43. public function testSerialization()
  44. {
  45. $data = json_encode([
  46. 'type' => AbstractSchema::NULL_TYPE,
  47. 'format' => 'foo',
  48. 'title' => 'bar',
  49. 'description' => 'baz',
  50. 'example' => 'qux',
  51. 'externalDocs' => (object)[],
  52. ]);
  53. $schema = $this->getSerializer()->deserialize($data, AbstractSchema::class, 'json');
  54. $this->assertInstanceOf(NullSchema::class, $schema);
  55. $this->assertAttributeEquals('foo', 'format', $schema);
  56. $this->assertAttributeEquals('bar', 'title', $schema);
  57. $this->assertAttributeEquals('baz', 'description', $schema);
  58. $this->assertAttributeEquals('qux', 'example', $schema);
  59. $this->assertAttributeInstanceOf(ExternalDocumentation::class, 'externalDocs', $schema);
  60. $json = $this->getSerializer()->serialize($schema, 'json');
  61. $this->assertJson($json);
  62. $this->assertJsonStringEqualsJsonString($data, $json);
  63. }
  64. }