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