Passed
Push — master ( a53d55...43aca1 )
by Maximilian
03:50
created

SelectCommandTest   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 87
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 51
dl 0
loc 87
rs 10
c 1
b 0
f 1
wmc 7

7 Methods

Rating   Name   Duplication   Size   Complexity  
A testJsonSerializeWithPartialProperties() 0 11 1
A testJsonSerializeWithEmptyArrays() 0 10 1
A testJsonSerializeWithAllProperties() 0 18 1
A testTypeConstant() 0 3 1
A testJsonSerializeWithNullValues() 0 10 1
A testConstructorWithAllParameters() 0 13 1
A testConstructorWithDefaultParameters() 0 8 1
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