|
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\Document\LayoutParameter; |
|
8
|
|
|
use MaxBeckers\AmazonAlexa\Response\Directives\APL\Document\LayoutParameterType; |
|
9
|
|
|
use PHPUnit\Framework\TestCase; |
|
10
|
|
|
|
|
11
|
|
|
class LayoutParameterTest extends TestCase |
|
12
|
|
|
{ |
|
13
|
|
|
public function testConstructorWithAllParameters(): void |
|
14
|
|
|
{ |
|
15
|
|
|
$name = 'testParameter'; |
|
16
|
|
|
$default = 'defaultValue'; |
|
17
|
|
|
$description = 'Test parameter description'; |
|
18
|
|
|
$type = LayoutParameterType::STRING; |
|
19
|
|
|
|
|
20
|
|
|
$parameter = new LayoutParameter($name, $default, $description, $type); |
|
21
|
|
|
|
|
22
|
|
|
$this->assertSame($name, $parameter->name); |
|
23
|
|
|
$this->assertSame($default, $parameter->default); |
|
24
|
|
|
$this->assertSame($description, $parameter->description); |
|
25
|
|
|
$this->assertSame($type, $parameter->type); |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
public function testConstructorWithDefaultParameters(): void |
|
29
|
|
|
{ |
|
30
|
|
|
$name = 'myParameter'; |
|
31
|
|
|
|
|
32
|
|
|
$parameter = new LayoutParameter($name); |
|
33
|
|
|
|
|
34
|
|
|
$this->assertSame($name, $parameter->name); |
|
35
|
|
|
$this->assertNull($parameter->default); |
|
36
|
|
|
$this->assertNull($parameter->description); |
|
37
|
|
|
$this->assertSame(LayoutParameterType::ANY, $parameter->type); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
public function testJsonSerializeWithAllProperties(): void |
|
41
|
|
|
{ |
|
42
|
|
|
$name = 'fullParameter'; |
|
43
|
|
|
$default = 42; |
|
44
|
|
|
$description = 'Numeric parameter'; |
|
45
|
|
|
$type = LayoutParameterType::NUMBER; |
|
46
|
|
|
|
|
47
|
|
|
$parameter = new LayoutParameter($name, $default, $description, $type); |
|
48
|
|
|
$result = $parameter->jsonSerialize(); |
|
49
|
|
|
|
|
50
|
|
|
$this->assertSame($name, $result['name']); |
|
51
|
|
|
$this->assertSame($type, $result['type']); |
|
52
|
|
|
$this->assertSame($default, $result['default']); |
|
53
|
|
|
$this->assertSame($description, $result['description']); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
public function testJsonSerializeWithMinimalProperties(): void |
|
57
|
|
|
{ |
|
58
|
|
|
$name = 'minimalParameter'; |
|
59
|
|
|
|
|
60
|
|
|
$parameter = new LayoutParameter($name); |
|
61
|
|
|
$result = $parameter->jsonSerialize(); |
|
62
|
|
|
|
|
63
|
|
|
$this->assertSame($name, $result['name']); |
|
64
|
|
|
$this->assertSame(LayoutParameterType::ANY, $result['type']); |
|
65
|
|
|
$this->assertArrayNotHasKey('default', $result); |
|
66
|
|
|
$this->assertArrayNotHasKey('description', $result); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
public function testJsonSerializeWithNullDefault(): void |
|
70
|
|
|
{ |
|
71
|
|
|
$parameter = new LayoutParameter('test', null, 'description', LayoutParameterType::BOOLEAN); |
|
72
|
|
|
$result = $parameter->jsonSerialize(); |
|
73
|
|
|
|
|
74
|
|
|
$this->assertSame('test', $result['name']); |
|
75
|
|
|
$this->assertSame(LayoutParameterType::BOOLEAN, $result['type']); |
|
76
|
|
|
$this->assertSame('description', $result['description']); |
|
77
|
|
|
$this->assertArrayNotHasKey('default', $result); |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
public function testJsonSerializeWithNullDescription(): void |
|
81
|
|
|
{ |
|
82
|
|
|
$parameter = new LayoutParameter('test', 'value', null, LayoutParameterType::STRING); |
|
83
|
|
|
$result = $parameter->jsonSerialize(); |
|
84
|
|
|
|
|
85
|
|
|
$this->assertSame('test', $result['name']); |
|
86
|
|
|
$this->assertSame(LayoutParameterType::STRING, $result['type']); |
|
87
|
|
|
$this->assertSame('value', $result['default']); |
|
88
|
|
|
$this->assertArrayNotHasKey('description', $result); |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
public function testJsonSerializeWithDifferentDefaultTypes(): void |
|
92
|
|
|
{ |
|
93
|
|
|
$testCases = [ |
|
94
|
|
|
['string value', LayoutParameterType::STRING], |
|
95
|
|
|
[123, LayoutParameterType::NUMBER], |
|
96
|
|
|
[45.67, LayoutParameterType::NUMBER], |
|
97
|
|
|
[true, LayoutParameterType::BOOLEAN], |
|
98
|
|
|
[['array', 'value'], LayoutParameterType::ANY], |
|
99
|
|
|
]; |
|
100
|
|
|
|
|
101
|
|
|
foreach ($testCases as [$default, $type]) { |
|
102
|
|
|
$parameter = new LayoutParameter('test', $default, null, $type); |
|
103
|
|
|
$result = $parameter->jsonSerialize(); |
|
104
|
|
|
|
|
105
|
|
|
$this->assertSame($default, $result['default']); |
|
106
|
|
|
$this->assertSame($type, $result['type']); |
|
107
|
|
|
} |
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
|
public function testJsonSerializeWithDifferentParameterTypes(): void |
|
111
|
|
|
{ |
|
112
|
|
|
$types = [ |
|
113
|
|
|
LayoutParameterType::ANY, |
|
114
|
|
|
LayoutParameterType::STRING, |
|
115
|
|
|
LayoutParameterType::NUMBER, |
|
116
|
|
|
LayoutParameterType::BOOLEAN, |
|
117
|
|
|
]; |
|
118
|
|
|
|
|
119
|
|
|
foreach ($types as $type) { |
|
120
|
|
|
$parameter = new LayoutParameter('test', null, null, $type); |
|
121
|
|
|
$result = $parameter->jsonSerialize(); |
|
122
|
|
|
|
|
123
|
|
|
$this->assertSame($type, $result['type']); |
|
124
|
|
|
} |
|
125
|
|
|
} |
|
126
|
|
|
|
|
127
|
|
|
public function testJsonSerializeWithZeroDefault(): void |
|
128
|
|
|
{ |
|
129
|
|
|
$parameter = new LayoutParameter('test', 0); |
|
130
|
|
|
$result = $parameter->jsonSerialize(); |
|
131
|
|
|
|
|
132
|
|
|
$this->assertArrayHasKey('default', $result); |
|
133
|
|
|
$this->assertSame(0, $result['default']); |
|
134
|
|
|
} |
|
135
|
|
|
|
|
136
|
|
|
public function testJsonSerializeWithFalseDefault(): void |
|
137
|
|
|
{ |
|
138
|
|
|
$parameter = new LayoutParameter('test', false); |
|
139
|
|
|
$result = $parameter->jsonSerialize(); |
|
140
|
|
|
|
|
141
|
|
|
$this->assertArrayHasKey('default', $result); |
|
142
|
|
|
$this->assertFalse($result['default']); |
|
143
|
|
|
} |
|
144
|
|
|
|
|
145
|
|
|
public function testJsonSerializeWithEmptyStringDefault(): void |
|
146
|
|
|
{ |
|
147
|
|
|
$parameter = new LayoutParameter('test', ''); |
|
148
|
|
|
$result = $parameter->jsonSerialize(); |
|
149
|
|
|
|
|
150
|
|
|
$this->assertArrayHasKey('default', $result); |
|
151
|
|
|
$this->assertSame('', $result['default']); |
|
152
|
|
|
} |
|
153
|
|
|
|
|
154
|
|
|
public function testJsonSerializeStructure(): void |
|
155
|
|
|
{ |
|
156
|
|
|
$parameter = new LayoutParameter('test', 'value', 'description'); |
|
157
|
|
|
$result = $parameter->jsonSerialize(); |
|
158
|
|
|
|
|
159
|
|
|
$this->assertIsArray($result); |
|
160
|
|
|
$this->assertArrayHasKey('name', $result); |
|
161
|
|
|
$this->assertArrayHasKey('type', $result); |
|
162
|
|
|
$this->assertArrayHasKey('default', $result); |
|
163
|
|
|
$this->assertArrayHasKey('description', $result); |
|
164
|
|
|
} |
|
165
|
|
|
|
|
166
|
|
|
public function testImplementsJsonSerializable(): void |
|
167
|
|
|
{ |
|
168
|
|
|
$parameter = new LayoutParameter('test'); |
|
169
|
|
|
|
|
170
|
|
|
$this->assertInstanceOf(\JsonSerializable::class, $parameter); |
|
171
|
|
|
} |
|
172
|
|
|
} |
|
173
|
|
|
|