|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace MaxBeckers\AmazonAlexa\Test\Response\Directives\APL\Document; |
|
6
|
|
|
|
|
7
|
|
|
use MaxBeckers\AmazonAlexa\Response\Directives\APL\Component\APLBaseComponent; |
|
8
|
|
|
use MaxBeckers\AmazonAlexa\Response\Directives\APL\Document\Bind; |
|
9
|
|
|
use MaxBeckers\AmazonAlexa\Response\Directives\APL\Document\Layout; |
|
10
|
|
|
use MaxBeckers\AmazonAlexa\Response\Directives\APL\Document\LayoutParameter; |
|
11
|
|
|
use PHPUnit\Framework\TestCase; |
|
12
|
|
|
|
|
13
|
|
|
class LayoutTest extends TestCase |
|
14
|
|
|
{ |
|
15
|
|
|
public function testConstructorWithAllParameters(): void |
|
16
|
|
|
{ |
|
17
|
|
|
$bind = [$this->createMock(Bind::class)]; |
|
18
|
|
|
$description = 'Test layout'; |
|
19
|
|
|
$item = $this->createMock(APLBaseComponent::class); |
|
20
|
|
|
$items = [ |
|
21
|
|
|
$this->createMock(APLBaseComponent::class), |
|
22
|
|
|
$this->createMock(APLBaseComponent::class), |
|
23
|
|
|
]; |
|
24
|
|
|
$parameters = [$this->createMock(LayoutParameter::class)]; |
|
25
|
|
|
|
|
26
|
|
|
$layout = new Layout($bind, $description, $item, $items, $parameters); |
|
27
|
|
|
|
|
28
|
|
|
$this->assertSame($bind, $layout->bind); |
|
29
|
|
|
$this->assertSame($description, $layout->description); |
|
30
|
|
|
$this->assertSame($item, $layout->item); |
|
31
|
|
|
$this->assertSame($items, $layout->items); |
|
32
|
|
|
$this->assertSame($parameters, $layout->parameters); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
public function testConstructorWithDefaultParameters(): void |
|
36
|
|
|
{ |
|
37
|
|
|
$layout = new Layout(); |
|
38
|
|
|
|
|
39
|
|
|
$this->assertNull($layout->bind); |
|
40
|
|
|
$this->assertNull($layout->description); |
|
41
|
|
|
$this->assertNull($layout->item); |
|
42
|
|
|
$this->assertNull($layout->items); |
|
43
|
|
|
$this->assertNull($layout->parameters); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
public function testJsonSerializeWithAllProperties(): void |
|
47
|
|
|
{ |
|
48
|
|
|
$bind = [ |
|
49
|
|
|
$this->createMock(Bind::class), |
|
50
|
|
|
$this->createMock(Bind::class), |
|
51
|
|
|
]; |
|
52
|
|
|
$description = 'Complex layout'; |
|
53
|
|
|
$item = $this->createMock(APLBaseComponent::class); |
|
54
|
|
|
$items = [$this->createMock(APLBaseComponent::class)]; |
|
55
|
|
|
$parameters = [ |
|
56
|
|
|
$this->createMock(LayoutParameter::class), |
|
57
|
|
|
$this->createMock(LayoutParameter::class), |
|
58
|
|
|
]; |
|
59
|
|
|
|
|
60
|
|
|
$layout = new Layout($bind, $description, $item, $items, $parameters); |
|
61
|
|
|
$result = $layout->jsonSerialize(); |
|
62
|
|
|
|
|
63
|
|
|
$this->assertSame($bind, $result['bind']); |
|
64
|
|
|
$this->assertSame($description, $result['description']); |
|
65
|
|
|
$this->assertSame($item, $result['item']); |
|
66
|
|
|
$this->assertSame($items, $result['items']); |
|
67
|
|
|
$this->assertSame($parameters, $result['parameters']); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
public function testJsonSerializeWithNullValues(): void |
|
71
|
|
|
{ |
|
72
|
|
|
$layout = new Layout(); |
|
73
|
|
|
$result = $layout->jsonSerialize(); |
|
74
|
|
|
|
|
75
|
|
|
$this->assertEmpty($result); |
|
76
|
|
|
$this->assertArrayNotHasKey('bind', $result); |
|
77
|
|
|
$this->assertArrayNotHasKey('description', $result); |
|
78
|
|
|
$this->assertArrayNotHasKey('item', $result); |
|
79
|
|
|
$this->assertArrayNotHasKey('items', $result); |
|
80
|
|
|
$this->assertArrayNotHasKey('parameters', $result); |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
public function testJsonSerializeWithPartialProperties(): void |
|
84
|
|
|
{ |
|
85
|
|
|
$description = 'Partial layout'; |
|
86
|
|
|
$item = $this->createMock(APLBaseComponent::class); |
|
87
|
|
|
|
|
88
|
|
|
$layout = new Layout(null, $description, $item); |
|
89
|
|
|
$result = $layout->jsonSerialize(); |
|
90
|
|
|
|
|
91
|
|
|
$this->assertSame($description, $result['description']); |
|
92
|
|
|
$this->assertSame($item, $result['item']); |
|
93
|
|
|
$this->assertArrayNotHasKey('bind', $result); |
|
94
|
|
|
$this->assertArrayNotHasKey('items', $result); |
|
95
|
|
|
$this->assertArrayNotHasKey('parameters', $result); |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
public function testJsonSerializeWithOnlyBind(): void |
|
99
|
|
|
{ |
|
100
|
|
|
$bind = [$this->createMock(Bind::class)]; |
|
101
|
|
|
$layout = new Layout($bind); |
|
102
|
|
|
$result = $layout->jsonSerialize(); |
|
103
|
|
|
|
|
104
|
|
|
$this->assertSame($bind, $result['bind']); |
|
105
|
|
|
$this->assertArrayNotHasKey('description', $result); |
|
106
|
|
|
$this->assertArrayNotHasKey('item', $result); |
|
107
|
|
|
$this->assertArrayNotHasKey('items', $result); |
|
108
|
|
|
$this->assertArrayNotHasKey('parameters', $result); |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
public function testJsonSerializeWithOnlyItems(): void |
|
112
|
|
|
{ |
|
113
|
|
|
$items = [ |
|
114
|
|
|
$this->createMock(APLBaseComponent::class), |
|
115
|
|
|
$this->createMock(APLBaseComponent::class), |
|
116
|
|
|
]; |
|
117
|
|
|
$layout = new Layout(null, null, null, $items); |
|
118
|
|
|
$result = $layout->jsonSerialize(); |
|
119
|
|
|
|
|
120
|
|
|
$this->assertSame($items, $result['items']); |
|
121
|
|
|
$this->assertArrayNotHasKey('bind', $result); |
|
122
|
|
|
$this->assertArrayNotHasKey('description', $result); |
|
123
|
|
|
$this->assertArrayNotHasKey('item', $result); |
|
124
|
|
|
$this->assertArrayNotHasKey('parameters', $result); |
|
125
|
|
|
} |
|
126
|
|
|
|
|
127
|
|
|
public function testJsonSerializeWithOnlyParameters(): void |
|
128
|
|
|
{ |
|
129
|
|
|
$parameters = [ |
|
130
|
|
|
$this->createMock(LayoutParameter::class), |
|
131
|
|
|
$this->createMock(LayoutParameter::class), |
|
132
|
|
|
]; |
|
133
|
|
|
$layout = new Layout(null, null, null, null, $parameters); |
|
134
|
|
|
$result = $layout->jsonSerialize(); |
|
135
|
|
|
|
|
136
|
|
|
$this->assertSame($parameters, $result['parameters']); |
|
137
|
|
|
$this->assertArrayNotHasKey('bind', $result); |
|
138
|
|
|
$this->assertArrayNotHasKey('description', $result); |
|
139
|
|
|
$this->assertArrayNotHasKey('item', $result); |
|
140
|
|
|
$this->assertArrayNotHasKey('items', $result); |
|
141
|
|
|
} |
|
142
|
|
|
|
|
143
|
|
|
public function testJsonSerializeFiltersNullValues(): void |
|
144
|
|
|
{ |
|
145
|
|
|
$layout = new Layout(null, 'description', null, null, null); |
|
146
|
|
|
$result = $layout->jsonSerialize(); |
|
147
|
|
|
|
|
148
|
|
|
$this->assertCount(1, $result); |
|
149
|
|
|
$this->assertArrayHasKey('description', $result); |
|
150
|
|
|
$this->assertSame('description', $result['description']); |
|
151
|
|
|
} |
|
152
|
|
|
|
|
153
|
|
|
public function testImplementsJsonSerializable(): void |
|
154
|
|
|
{ |
|
155
|
|
|
$layout = new Layout(); |
|
156
|
|
|
|
|
157
|
|
|
$this->assertInstanceOf(\JsonSerializable::class, $layout); |
|
158
|
|
|
} |
|
159
|
|
|
} |
|
160
|
|
|
|