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

SpeakItemCommandTest   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 103
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 54
dl 0
loc 103
rs 10
c 1
b 0
f 1
wmc 11

9 Methods

Rating   Name   Duplication   Size   Complexity  
A testJsonSerializeWithDifferentHighlightModes() 0 9 2
A testTypeConstant() 0 3 1
A testJsonSerializeWithDifferentAlignValues() 0 9 2
A testJsonSerializeWithAllProperties() 0 15 1
A testJsonSerializeWithZeroDwellTime() 0 6 1
A testConstructorWithAllParameters() 0 13 1
A testJsonSerializeWithDefaultEnums() 0 10 1
A testJsonSerializeWithNullComponentId() 0 10 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\Document\HighlightMode;
8
use MaxBeckers\AmazonAlexa\Response\Directives\APL\Document\ScrollAlign;
9
use MaxBeckers\AmazonAlexa\Response\Directives\APL\StandardCommand\SpeakItemCommand;
10
use PHPUnit\Framework\TestCase;
11
12
class SpeakItemCommandTest extends TestCase
13
{
14
    public function testConstructorWithAllParameters(): void
15
    {
16
        $componentId = 'myComponent';
17
        $align = ScrollAlign::CENTER;
18
        $highlightMode = HighlightMode::LINE;
19
        $minimumDwellTime = 1000;
20
21
        $command = new SpeakItemCommand($componentId, $align, $highlightMode, $minimumDwellTime);
22
23
        $this->assertSame($componentId, $command->componentId);
24
        $this->assertSame($align, $command->align);
25
        $this->assertSame($highlightMode, $command->highlightMode);
26
        $this->assertSame($minimumDwellTime, $command->minimumDwellTime);
27
    }
28
29
    public function testConstructorWithDefaultParameters(): void
30
    {
31
        $command = new SpeakItemCommand();
32
33
        $this->assertNull($command->componentId);
34
        $this->assertSame(ScrollAlign::VISIBLE, $command->align);
35
        $this->assertSame(HighlightMode::BLOCK, $command->highlightMode);
36
        $this->assertNull($command->minimumDwellTime);
37
    }
38
39
    public function testJsonSerializeWithAllProperties(): void
40
    {
41
        $componentId = 'testComponent';
42
        $align = ScrollAlign::FIRST;
43
        $highlightMode = HighlightMode::BLOCK;
44
        $minimumDwellTime = 500;
45
46
        $command = new SpeakItemCommand($componentId, $align, $highlightMode, $minimumDwellTime);
47
        $result = $command->jsonSerialize();
48
49
        $this->assertSame(SpeakItemCommand::TYPE, $result['type']);
50
        $this->assertSame($componentId, $result['componentId']);
51
        $this->assertSame($align->value, $result['align']);
52
        $this->assertSame($highlightMode->value, $result['highlightMode']);
53
        $this->assertSame($minimumDwellTime, $result['minimumDwellTime']);
54
    }
55
56
    public function testJsonSerializeWithDefaultEnums(): void
57
    {
58
        $command = new SpeakItemCommand('component1');
59
        $result = $command->jsonSerialize();
60
61
        $this->assertSame(SpeakItemCommand::TYPE, $result['type']);
62
        $this->assertSame('component1', $result['componentId']);
63
        $this->assertSame(ScrollAlign::VISIBLE->value, $result['align']);
64
        $this->assertSame(HighlightMode::BLOCK->value, $result['highlightMode']);
65
        $this->assertArrayNotHasKey('minimumDwellTime', $result);
66
    }
67
68
    public function testJsonSerializeWithNullComponentId(): void
69
    {
70
        $command = new SpeakItemCommand();
71
        $result = $command->jsonSerialize();
72
73
        $this->assertSame(SpeakItemCommand::TYPE, $result['type']);
74
        $this->assertArrayNotHasKey('componentId', $result);
75
        $this->assertSame(ScrollAlign::VISIBLE->value, $result['align']);
76
        $this->assertSame(HighlightMode::BLOCK->value, $result['highlightMode']);
77
        $this->assertArrayNotHasKey('minimumDwellTime', $result);
78
    }
79
80
    public function testJsonSerializeWithZeroDwellTime(): void
81
    {
82
        $command = new SpeakItemCommand('component', ScrollAlign::LAST, HighlightMode::LINE, 0);
83
        $result = $command->jsonSerialize();
84
85
        $this->assertSame(0, $result['minimumDwellTime']);
86
    }
87
88
    public function testJsonSerializeWithDifferentAlignValues(): void
89
    {
90
        $alignValues = [ScrollAlign::VISIBLE, ScrollAlign::CENTER, ScrollAlign::FIRST, ScrollAlign::LAST];
91
92
        foreach ($alignValues as $align) {
93
            $command = new SpeakItemCommand('test', $align);
94
            $result = $command->jsonSerialize();
95
96
            $this->assertSame($align->value, $result['align']);
97
        }
98
    }
99
100
    public function testJsonSerializeWithDifferentHighlightModes(): void
101
    {
102
        $highlightModes = [HighlightMode::BLOCK, HighlightMode::LINE];
103
104
        foreach ($highlightModes as $mode) {
105
            $command = new SpeakItemCommand('test', ScrollAlign::VISIBLE, $mode);
106
            $result = $command->jsonSerialize();
107
108
            $this->assertSame($mode->value, $result['highlightMode']);
109
        }
110
    }
111
112
    public function testTypeConstant(): void
113
    {
114
        $this->assertSame('SpeakItem', SpeakItemCommand::TYPE);
115
    }
116
}
117