1
|
|
|
<?php declare(strict_types = 1); |
2
|
|
|
/* |
3
|
|
|
* This file is part of the KleijnWeb\SwaggerBundle package. |
4
|
|
|
* |
5
|
|
|
* For the full copyright and license information, please view the LICENSE |
6
|
|
|
* file that was distributed with this source code. |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
namespace KleijnWeb\SwaggerBundle\Tests\Serialize\Serializer; |
10
|
|
|
|
11
|
|
|
use KleijnWeb\SwaggerBundle\Document\Specification; |
12
|
|
|
use KleijnWeb\SwaggerBundle\Tests\Serialize\Serializer\Stubs\Bar; |
13
|
|
|
use KleijnWeb\SwaggerBundle\Tests\Serialize\Serializer\Stubs\Foo; |
14
|
|
|
use KleijnWeb\SwaggerBundle\Tests\Serialize\Serializer\Stubs\Meh; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* @author John Kleijn <[email protected]> |
18
|
|
|
*/ |
19
|
|
|
class ObjectSerializationTest extends ObjectSerializerTest |
20
|
|
|
{ |
21
|
|
|
/** |
22
|
|
|
* @test |
23
|
|
|
* |
24
|
|
|
* @param Foo $data |
25
|
|
|
* @param string $expected |
26
|
|
|
* |
27
|
|
|
* @dataProvider serializationProvider |
28
|
|
|
*/ |
29
|
|
|
public function canSerialize(Foo $data, string $expected) |
30
|
|
|
{ |
31
|
|
|
$actual = $this->serializer->serialize($data, $this->specification); |
32
|
|
|
$this->assertSame($expected, $actual); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @return array |
37
|
|
|
*/ |
38
|
|
|
public function serializationProvider(): array |
39
|
|
|
{ |
40
|
|
|
return [ |
41
|
|
|
[ |
42
|
|
|
new Foo('5', new Bar(6, new Meh(1), new Meh(2), new Meh(3))), |
43
|
|
|
json_encode([ |
44
|
|
|
'a' => '5', |
45
|
|
|
'bar' => [ |
46
|
|
|
'b' => 6, |
47
|
|
|
'meh' => ['c' => 1], |
48
|
|
|
'mehs' => [ |
49
|
|
|
['c' => 2], |
50
|
|
|
['c' => 3], |
51
|
|
|
] |
52
|
|
|
] |
53
|
|
|
]) |
54
|
|
|
], |
55
|
|
|
[ |
56
|
|
|
// Since this will not pass validation, were going to allow it |
57
|
|
|
new Foo('5', new Bar(6, new Meh([1]), new Meh(2), new Meh(3))), |
58
|
|
|
json_encode([ |
59
|
|
|
'a' => '5', |
60
|
|
|
'bar' => [ |
61
|
|
|
'b' => 6, |
62
|
|
|
'meh' => ['c' => [1]], |
63
|
|
|
'mehs' => [ |
64
|
|
|
['c' => 2], |
65
|
|
|
['c' => 3], |
66
|
|
|
] |
67
|
|
|
] |
68
|
|
|
]) |
69
|
|
|
], |
70
|
|
|
[ |
71
|
|
|
new Foo( |
72
|
|
|
'5', |
73
|
|
|
new Bar(6, new Meh([1]), new Meh(2), new Meh(3)), |
74
|
|
|
new \DateTime('midnight'), |
75
|
|
|
new \DateTime() |
76
|
|
|
), |
77
|
|
|
json_encode([ |
78
|
|
|
'a' => '5', |
79
|
|
|
'bar' => [ |
80
|
|
|
'b' => 6, |
81
|
|
|
'meh' => ['c' => [1]], |
82
|
|
|
'mehs' => [ |
83
|
|
|
['c' => 2], |
84
|
|
|
['c' => 3], |
85
|
|
|
] |
86
|
|
|
], |
87
|
|
|
'aDate' => (new \DateTime('midnight'))->format('Y-m-d'), |
88
|
|
|
'aDateTime' => (new \DateTime())->format(\DateTime::ISO8601), |
89
|
|
|
]), |
90
|
|
|
], |
91
|
|
|
]; |
92
|
|
|
} |
93
|
|
|
} |
94
|
|
|
|