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\AbstractStandardCommand; |
8
|
|
|
use MaxBeckers\AmazonAlexa\Response\Directives\APL\StandardCommand\SelectCommand; |
9
|
|
|
use PHPUnit\Framework\TestCase; |
10
|
|
|
|
11
|
|
|
class SelectCommandTest extends TestCase |
12
|
|
|
{ |
13
|
|
|
public function testConstructorWithAllParameters(): void |
14
|
|
|
{ |
15
|
|
|
$componentId = 'myComponent'; |
16
|
|
|
$commands = [$this->createMock(AbstractStandardCommand::class)]; |
17
|
|
|
$data = ['item1', 'item2']; |
18
|
|
|
$otherwise = [$this->createMock(AbstractStandardCommand::class)]; |
19
|
|
|
|
20
|
|
|
$command = new SelectCommand($componentId, $commands, $data, $otherwise); |
21
|
|
|
|
22
|
|
|
$this->assertSame($componentId, $command->componentId); |
23
|
|
|
$this->assertSame($commands, $command->commands); |
24
|
|
|
$this->assertSame($data, $command->data); |
25
|
|
|
$this->assertSame($otherwise, $command->otherwise); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
public function testConstructorWithDefaultParameters(): void |
29
|
|
|
{ |
30
|
|
|
$command = new SelectCommand(); |
31
|
|
|
|
32
|
|
|
$this->assertNull($command->componentId); |
33
|
|
|
$this->assertNull($command->commands); |
34
|
|
|
$this->assertNull($command->data); |
35
|
|
|
$this->assertNull($command->otherwise); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
public function testJsonSerializeWithAllProperties(): void |
39
|
|
|
{ |
40
|
|
|
$componentId = 'testComponent'; |
41
|
|
|
$commands = [ |
42
|
|
|
$this->createMock(AbstractStandardCommand::class), |
43
|
|
|
$this->createMock(AbstractStandardCommand::class), |
44
|
|
|
]; |
45
|
|
|
$data = ['value1', 'value2']; |
46
|
|
|
$otherwise = [$this->createMock(AbstractStandardCommand::class)]; |
47
|
|
|
|
48
|
|
|
$command = new SelectCommand($componentId, $commands, $data, $otherwise); |
49
|
|
|
$result = $command->jsonSerialize(); |
50
|
|
|
|
51
|
|
|
$this->assertSame(SelectCommand::TYPE, $result['type']); |
52
|
|
|
$this->assertSame($componentId, $result['componentId']); |
53
|
|
|
$this->assertSame($commands, $result['commands']); |
54
|
|
|
$this->assertSame($data, $result['data']); |
55
|
|
|
$this->assertSame($otherwise, $result['otherwise']); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
public function testJsonSerializeWithEmptyArrays(): void |
59
|
|
|
{ |
60
|
|
|
$command = new SelectCommand('comp', [], [], []); |
61
|
|
|
$result = $command->jsonSerialize(); |
62
|
|
|
|
63
|
|
|
$this->assertSame(SelectCommand::TYPE, $result['type']); |
64
|
|
|
$this->assertSame('comp', $result['componentId']); |
65
|
|
|
$this->assertArrayNotHasKey('commands', $result); |
66
|
|
|
$this->assertArrayNotHasKey('data', $result); |
67
|
|
|
$this->assertArrayNotHasKey('otherwise', $result); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
public function testJsonSerializeWithNullValues(): void |
71
|
|
|
{ |
72
|
|
|
$command = new SelectCommand(); |
73
|
|
|
$result = $command->jsonSerialize(); |
74
|
|
|
|
75
|
|
|
$this->assertSame(SelectCommand::TYPE, $result['type']); |
76
|
|
|
$this->assertArrayNotHasKey('componentId', $result); |
77
|
|
|
$this->assertArrayNotHasKey('commands', $result); |
78
|
|
|
$this->assertArrayNotHasKey('data', $result); |
79
|
|
|
$this->assertArrayNotHasKey('otherwise', $result); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
public function testJsonSerializeWithPartialProperties(): void |
83
|
|
|
{ |
84
|
|
|
$commands = [$this->createMock(AbstractStandardCommand::class)]; |
85
|
|
|
$command = new SelectCommand('select1', $commands); |
86
|
|
|
$result = $command->jsonSerialize(); |
87
|
|
|
|
88
|
|
|
$this->assertSame(SelectCommand::TYPE, $result['type']); |
89
|
|
|
$this->assertSame('select1', $result['componentId']); |
90
|
|
|
$this->assertSame($commands, $result['commands']); |
91
|
|
|
$this->assertArrayNotHasKey('data', $result); |
92
|
|
|
$this->assertArrayNotHasKey('otherwise', $result); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
public function testTypeConstant(): void |
96
|
|
|
{ |
97
|
|
|
$this->assertSame('Select', SelectCommand::TYPE); |
98
|
|
|
} |
99
|
|
|
} |
100
|
|
|
|