|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace MaxBeckers\AmazonAlexa\Test\Response\Directives\APL\StandardCommand; |
|
6
|
|
|
|
|
7
|
|
|
use MaxBeckers\AmazonAlexa\Response\Directives\APL\StandardCommand\SetValueCommand; |
|
8
|
|
|
use PHPUnit\Framework\TestCase; |
|
9
|
|
|
|
|
10
|
|
|
class SetValueCommandTest extends TestCase |
|
11
|
|
|
{ |
|
12
|
|
|
public function testConstructorWithAllParameters(): void |
|
13
|
|
|
{ |
|
14
|
|
|
$componentId = 'myComponent'; |
|
15
|
|
|
$property = 'text'; |
|
16
|
|
|
$value = 'Hello World'; |
|
17
|
|
|
|
|
18
|
|
|
$command = new SetValueCommand($componentId, $property, $value); |
|
19
|
|
|
|
|
20
|
|
|
$this->assertSame($componentId, $command->componentId); |
|
21
|
|
|
$this->assertSame($property, $command->property); |
|
22
|
|
|
$this->assertSame($value, $command->value); |
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
|
|
public function testConstructorWithDefaultParameters(): void |
|
26
|
|
|
{ |
|
27
|
|
|
$command = new SetValueCommand(); |
|
28
|
|
|
|
|
29
|
|
|
$this->assertNull($command->componentId); |
|
30
|
|
|
$this->assertNull($command->property); |
|
31
|
|
|
$this->assertNull($command->value); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
public function testJsonSerializeWithAllProperties(): void |
|
35
|
|
|
{ |
|
36
|
|
|
$componentId = 'testComponent'; |
|
37
|
|
|
$property = 'opacity'; |
|
38
|
|
|
$value = 0.5; |
|
39
|
|
|
|
|
40
|
|
|
$command = new SetValueCommand($componentId, $property, $value); |
|
41
|
|
|
$result = $command->jsonSerialize(); |
|
42
|
|
|
|
|
43
|
|
|
$this->assertSame(SetValueCommand::TYPE, $result['type']); |
|
44
|
|
|
$this->assertSame($componentId, $result['componentId']); |
|
45
|
|
|
$this->assertSame($property, $result['property']); |
|
46
|
|
|
$this->assertSame($value, $result['value']); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
public function testJsonSerializeWithNullValues(): void |
|
50
|
|
|
{ |
|
51
|
|
|
$command = new SetValueCommand(); |
|
52
|
|
|
$result = $command->jsonSerialize(); |
|
53
|
|
|
|
|
54
|
|
|
$this->assertSame(SetValueCommand::TYPE, $result['type']); |
|
55
|
|
|
$this->assertArrayNotHasKey('componentId', $result); |
|
56
|
|
|
$this->assertArrayNotHasKey('property', $result); |
|
57
|
|
|
$this->assertArrayNotHasKey('value', $result); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
public function testJsonSerializeWithDifferentValueTypes(): void |
|
61
|
|
|
{ |
|
62
|
|
|
$testCases = [ |
|
63
|
|
|
['string value', 'string'], |
|
64
|
|
|
[123, 'integer'], |
|
65
|
|
|
[45.67, 'float'], |
|
66
|
|
|
[true, 'boolean'], |
|
67
|
|
|
[['nested' => 'array'], 'array'], |
|
68
|
|
|
]; |
|
69
|
|
|
|
|
70
|
|
|
foreach ($testCases as [$value, $description]) { |
|
71
|
|
|
$command = new SetValueCommand('comp', 'prop', $value); |
|
72
|
|
|
$result = $command->jsonSerialize(); |
|
73
|
|
|
|
|
74
|
|
|
$this->assertSame($value, $result['value'], "Failed for $description"); |
|
75
|
|
|
} |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
public function testJsonSerializeWithZeroValue(): void |
|
79
|
|
|
{ |
|
80
|
|
|
$command = new SetValueCommand('component', 'property', 0); |
|
81
|
|
|
$result = $command->jsonSerialize(); |
|
82
|
|
|
|
|
83
|
|
|
$this->assertSame(SetValueCommand::TYPE, $result['type']); |
|
84
|
|
|
$this->assertSame('component', $result['componentId']); |
|
85
|
|
|
$this->assertSame('property', $result['property']); |
|
86
|
|
|
$this->assertSame(0, $result['value']); |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
public function testJsonSerializeWithFalseValue(): void |
|
90
|
|
|
{ |
|
91
|
|
|
$command = new SetValueCommand('component', 'visible', false); |
|
92
|
|
|
$result = $command->jsonSerialize(); |
|
93
|
|
|
|
|
94
|
|
|
$this->assertFalse($result['value']); |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
public function testJsonSerializeWithEmptyStringValue(): void |
|
98
|
|
|
{ |
|
99
|
|
|
$command = new SetValueCommand('component', 'text', ''); |
|
100
|
|
|
$result = $command->jsonSerialize(); |
|
101
|
|
|
|
|
102
|
|
|
$this->assertSame('', $result['value']); |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
public function testTypeConstant(): void |
|
106
|
|
|
{ |
|
107
|
|
|
$this->assertSame('SetValue', SetValueCommand::TYPE); |
|
108
|
|
|
} |
|
109
|
|
|
} |
|
110
|
|
|
|