|
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\MainTemplate; |
|
9
|
|
|
use PHPUnit\Framework\TestCase; |
|
10
|
|
|
|
|
11
|
|
|
class MainTemplateTest extends TestCase |
|
12
|
|
|
{ |
|
13
|
|
|
public function testConstructorWithAllParameters(): void |
|
14
|
|
|
{ |
|
15
|
|
|
$parameters = ['param1', 'param2', 'param3']; |
|
16
|
|
|
$item = $this->createMock(APLBaseComponent::class); |
|
17
|
|
|
$items = [ |
|
18
|
|
|
$this->createMock(APLBaseComponent::class), |
|
19
|
|
|
$this->createMock(APLBaseComponent::class), |
|
20
|
|
|
]; |
|
21
|
|
|
|
|
22
|
|
|
$template = new MainTemplate($parameters, $item, $items); |
|
23
|
|
|
|
|
24
|
|
|
$this->assertSame($parameters, $template->parameters); |
|
25
|
|
|
$this->assertSame($item, $template->item); |
|
26
|
|
|
$this->assertSame($items, $template->items); |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
public function testConstructorWithDefaultParameters(): void |
|
30
|
|
|
{ |
|
31
|
|
|
$template = new MainTemplate(); |
|
32
|
|
|
|
|
33
|
|
|
$this->assertNull($template->parameters); |
|
34
|
|
|
$this->assertNull($template->item); |
|
35
|
|
|
$this->assertNull($template->items); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
public function testJsonSerializeWithAllProperties(): void |
|
39
|
|
|
{ |
|
40
|
|
|
$parameters = ['width', 'height', 'theme']; |
|
41
|
|
|
$item = $this->createMock(APLBaseComponent::class); |
|
42
|
|
|
$items = [ |
|
43
|
|
|
$this->createMock(APLBaseComponent::class), |
|
44
|
|
|
$this->createMock(APLBaseComponent::class), |
|
45
|
|
|
]; |
|
46
|
|
|
|
|
47
|
|
|
$template = new MainTemplate($parameters, $item, $items); |
|
48
|
|
|
$result = $template->jsonSerialize(); |
|
49
|
|
|
|
|
50
|
|
|
$this->assertSame($parameters, $result['parameters']); |
|
51
|
|
|
$this->assertSame($item, $result['item']); |
|
52
|
|
|
$this->assertSame($items, $result['items']); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
public function testJsonSerializeWithNullValues(): void |
|
56
|
|
|
{ |
|
57
|
|
|
$template = new MainTemplate(); |
|
58
|
|
|
$result = $template->jsonSerialize(); |
|
59
|
|
|
|
|
60
|
|
|
$this->assertEmpty($result); |
|
61
|
|
|
$this->assertArrayNotHasKey('parameters', $result); |
|
62
|
|
|
$this->assertArrayNotHasKey('item', $result); |
|
63
|
|
|
$this->assertArrayNotHasKey('items', $result); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
public function testJsonSerializeWithOnlyParameters(): void |
|
67
|
|
|
{ |
|
68
|
|
|
$parameters = ['color', 'size']; |
|
69
|
|
|
$template = new MainTemplate($parameters); |
|
70
|
|
|
$result = $template->jsonSerialize(); |
|
71
|
|
|
|
|
72
|
|
|
$this->assertSame($parameters, $result['parameters']); |
|
73
|
|
|
$this->assertArrayNotHasKey('item', $result); |
|
74
|
|
|
$this->assertArrayNotHasKey('items', $result); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
public function testJsonSerializeWithOnlyItem(): void |
|
78
|
|
|
{ |
|
79
|
|
|
$item = $this->createMock(APLBaseComponent::class); |
|
80
|
|
|
$template = new MainTemplate(null, $item); |
|
81
|
|
|
$result = $template->jsonSerialize(); |
|
82
|
|
|
|
|
83
|
|
|
$this->assertSame($item, $result['item']); |
|
84
|
|
|
$this->assertArrayNotHasKey('parameters', $result); |
|
85
|
|
|
$this->assertArrayNotHasKey('items', $result); |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
public function testJsonSerializeWithOnlyItems(): void |
|
89
|
|
|
{ |
|
90
|
|
|
$items = [ |
|
91
|
|
|
$this->createMock(APLBaseComponent::class), |
|
92
|
|
|
$this->createMock(APLBaseComponent::class), |
|
93
|
|
|
]; |
|
94
|
|
|
$template = new MainTemplate(null, null, $items); |
|
95
|
|
|
$result = $template->jsonSerialize(); |
|
96
|
|
|
|
|
97
|
|
|
$this->assertSame($items, $result['items']); |
|
98
|
|
|
$this->assertArrayNotHasKey('parameters', $result); |
|
99
|
|
|
$this->assertArrayNotHasKey('item', $result); |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
public function testJsonSerializeWithSingleParameter(): void |
|
103
|
|
|
{ |
|
104
|
|
|
$parameters = ['singleParam']; |
|
105
|
|
|
$template = new MainTemplate($parameters); |
|
106
|
|
|
$result = $template->jsonSerialize(); |
|
107
|
|
|
|
|
108
|
|
|
$this->assertSame($parameters, $result['parameters']); |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
public function testJsonSerializeWithEmptyParametersArray(): void |
|
112
|
|
|
{ |
|
113
|
|
|
$template = new MainTemplate([]); |
|
114
|
|
|
$result = $template->jsonSerialize(); |
|
115
|
|
|
|
|
116
|
|
|
$this->assertSame([], $result['parameters']); |
|
117
|
|
|
} |
|
118
|
|
|
|
|
119
|
|
|
public function testJsonSerializeFiltersNullValues(): void |
|
120
|
|
|
{ |
|
121
|
|
|
$item = $this->createMock(APLBaseComponent::class); |
|
122
|
|
|
$template = new MainTemplate(null, $item, null); |
|
123
|
|
|
$result = $template->jsonSerialize(); |
|
124
|
|
|
|
|
125
|
|
|
$this->assertCount(1, $result); |
|
126
|
|
|
$this->assertArrayHasKey('item', $result); |
|
127
|
|
|
$this->assertSame($item, $result['item']); |
|
128
|
|
|
} |
|
129
|
|
|
|
|
130
|
|
|
public function testJsonSerializeWithMixedContent(): void |
|
131
|
|
|
{ |
|
132
|
|
|
$parameters = ['mixedParam1', 'mixedParam2']; |
|
133
|
|
|
$items = [$this->createMock(APLBaseComponent::class)]; |
|
134
|
|
|
$template = new MainTemplate($parameters, null, $items); |
|
135
|
|
|
$result = $template->jsonSerialize(); |
|
136
|
|
|
|
|
137
|
|
|
$this->assertSame($parameters, $result['parameters']); |
|
138
|
|
|
$this->assertSame($items, $result['items']); |
|
139
|
|
|
$this->assertArrayNotHasKey('item', $result); |
|
140
|
|
|
} |
|
141
|
|
|
|
|
142
|
|
|
public function testImplementsJsonSerializable(): void |
|
143
|
|
|
{ |
|
144
|
|
|
$template = new MainTemplate(); |
|
145
|
|
|
|
|
146
|
|
|
$this->assertInstanceOf(\JsonSerializable::class, $template); |
|
147
|
|
|
} |
|
148
|
|
|
} |
|
149
|
|
|
|