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