Passed
Pull Request — master (#97)
by Maximilian
04:02
created

SpeakListCommandTest   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 116
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 69
dl 0
loc 116
rs 10
c 1
b 0
f 1
wmc 10

9 Methods

Rating   Name   Duplication   Size   Complexity  
A testConstructorWithDefaultParameters() 0 9 1
A testJsonSerializeWithAllProperties() 0 17 1
A testJsonSerializeWithDefaultAlign() 0 11 1
A testTypeConstant() 0 3 1
A testJsonSerializeWithNullValues() 0 11 1
A testConstructorWithAllParameters() 0 15 1
A testJsonSerializeWithZeroValues() 0 11 1
A testJsonSerializeWithDifferentAlignValues() 0 9 2
A testJsonSerializeWithPartialProperties() 0 11 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\Document\ScrollAlign;
8
use MaxBeckers\AmazonAlexa\Response\Directives\APL\StandardCommand\SpeakListCommand;
9
use PHPUnit\Framework\TestCase;
10
11
class SpeakListCommandTest extends TestCase
12
{
13
    public function testConstructorWithAllParameters(): void
14
    {
15
        $componentId = 'myList';
16
        $align = ScrollAlign::CENTER;
17
        $count = 5;
18
        $minimumDwellTime = 800;
19
        $start = 2;
20
21
        $command = new SpeakListCommand($componentId, $align, $count, $minimumDwellTime, $start);
22
23
        $this->assertSame($componentId, $command->componentId);
24
        $this->assertSame($align, $command->align);
25
        $this->assertSame($count, $command->count);
26
        $this->assertSame($minimumDwellTime, $command->minimumDwellTime);
27
        $this->assertSame($start, $command->start);
28
    }
29
30
    public function testConstructorWithDefaultParameters(): void
31
    {
32
        $command = new SpeakListCommand();
33
34
        $this->assertNull($command->componentId);
35
        $this->assertSame(ScrollAlign::VISIBLE, $command->align);
36
        $this->assertNull($command->count);
37
        $this->assertNull($command->minimumDwellTime);
38
        $this->assertNull($command->start);
39
    }
40
41
    public function testJsonSerializeWithAllProperties(): void
42
    {
43
        $componentId = 'testList';
44
        $align = ScrollAlign::FIRST;
45
        $count = 3;
46
        $minimumDwellTime = 600;
47
        $start = 1;
48
49
        $command = new SpeakListCommand($componentId, $align, $count, $minimumDwellTime, $start);
50
        $result = $command->jsonSerialize();
51
52
        $this->assertSame(SpeakListCommand::TYPE, $result['type']);
53
        $this->assertSame($componentId, $result['componentId']);
54
        $this->assertSame($align->value, $result['align']);
55
        $this->assertSame($count, $result['count']);
56
        $this->assertSame($minimumDwellTime, $result['minimumDwellTime']);
57
        $this->assertSame($start, $result['start']);
58
    }
59
60
    public function testJsonSerializeWithDefaultAlign(): void
61
    {
62
        $command = new SpeakListCommand('list1');
63
        $result = $command->jsonSerialize();
64
65
        $this->assertSame(SpeakListCommand::TYPE, $result['type']);
66
        $this->assertSame('list1', $result['componentId']);
67
        $this->assertSame(ScrollAlign::VISIBLE->value, $result['align']);
68
        $this->assertArrayNotHasKey('count', $result);
69
        $this->assertArrayNotHasKey('minimumDwellTime', $result);
70
        $this->assertArrayNotHasKey('start', $result);
71
    }
72
73
    public function testJsonSerializeWithNullValues(): void
74
    {
75
        $command = new SpeakListCommand();
76
        $result = $command->jsonSerialize();
77
78
        $this->assertSame(SpeakListCommand::TYPE, $result['type']);
79
        $this->assertArrayNotHasKey('componentId', $result);
80
        $this->assertSame(ScrollAlign::VISIBLE->value, $result['align']);
81
        $this->assertArrayNotHasKey('count', $result);
82
        $this->assertArrayNotHasKey('minimumDwellTime', $result);
83
        $this->assertArrayNotHasKey('start', $result);
84
    }
85
86
    public function testJsonSerializeWithZeroValues(): void
87
    {
88
        $command = new SpeakListCommand('list', ScrollAlign::LAST, 0, 0, 0);
89
        $result = $command->jsonSerialize();
90
91
        $this->assertSame(SpeakListCommand::TYPE, $result['type']);
92
        $this->assertSame('list', $result['componentId']);
93
        $this->assertSame(ScrollAlign::LAST->value, $result['align']);
94
        $this->assertSame(0, $result['count']);
95
        $this->assertSame(0, $result['minimumDwellTime']);
96
        $this->assertSame(0, $result['start']);
97
    }
98
99
    public function testJsonSerializeWithPartialProperties(): void
100
    {
101
        $command = new SpeakListCommand('list', ScrollAlign::CENTER, 10);
102
        $result = $command->jsonSerialize();
103
104
        $this->assertSame(SpeakListCommand::TYPE, $result['type']);
105
        $this->assertSame('list', $result['componentId']);
106
        $this->assertSame(ScrollAlign::CENTER->value, $result['align']);
107
        $this->assertSame(10, $result['count']);
108
        $this->assertArrayNotHasKey('minimumDwellTime', $result);
109
        $this->assertArrayNotHasKey('start', $result);
110
    }
111
112
    public function testJsonSerializeWithDifferentAlignValues(): void
113
    {
114
        $alignValues = [ScrollAlign::VISIBLE, ScrollAlign::CENTER, ScrollAlign::FIRST, ScrollAlign::LAST];
115
116
        foreach ($alignValues as $align) {
117
            $command = new SpeakListCommand('test', $align);
118
            $result = $command->jsonSerialize();
119
120
            $this->assertSame($align->value, $result['align']);
121
        }
122
    }
123
124
    public function testTypeConstant(): void
125
    {
126
        $this->assertSame('SpeakList', SpeakListCommand::TYPE);
127
    }
128
}
129