Passed
Pull Request — master (#97)
by Maximilian
03:52
created

testJsonSerializeWithDifferentAlignValues()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 2
eloc 5
nc 2
nop 0
dl 0
loc 9
rs 10
c 1
b 0
f 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\ScrollToComponentCommand;
9
use PHPUnit\Framework\TestCase;
10
11
class ScrollToComponentCommandTest extends TestCase
12
{
13
    public function testConstructorWithAllParameters(): void
14
    {
15
        $componentId = 'targetComponent';
16
        $align = ScrollAlign::CENTER;
17
        $targetDuration = 1000;
18
19
        $command = new ScrollToComponentCommand($componentId, $align, $targetDuration);
20
21
        $this->assertSame($componentId, $command->componentId);
22
        $this->assertSame($align, $command->align);
23
        $this->assertSame($targetDuration, $command->targetDuration);
24
    }
25
26
    public function testConstructorWithDefaultParameters(): void
27
    {
28
        $command = new ScrollToComponentCommand();
29
30
        $this->assertNull($command->componentId);
31
        $this->assertSame(ScrollAlign::VISIBLE, $command->align);
32
        $this->assertNull($command->targetDuration);
33
    }
34
35
    public function testJsonSerializeWithAllProperties(): void
36
    {
37
        $componentId = 'testComponent';
38
        $align = ScrollAlign::FIRST;
39
        $targetDuration = 800;
40
41
        $command = new ScrollToComponentCommand($componentId, $align, $targetDuration);
42
        $result = $command->jsonSerialize();
43
44
        $this->assertSame(ScrollToComponentCommand::TYPE, $result['type']);
45
        $this->assertSame($componentId, $result['componentId']);
46
        $this->assertSame($align->value, $result['align']);
47
        $this->assertSame($targetDuration, $result['targetDuration']);
48
    }
49
50
    public function testJsonSerializeWithDefaultAlign(): void
51
    {
52
        $command = new ScrollToComponentCommand('component1');
53
        $result = $command->jsonSerialize();
54
55
        $this->assertSame(ScrollToComponentCommand::TYPE, $result['type']);
56
        $this->assertSame('component1', $result['componentId']);
57
        $this->assertSame(ScrollAlign::VISIBLE->value, $result['align']);
58
        $this->assertArrayNotHasKey('targetDuration', $result);
59
    }
60
61
    public function testJsonSerializeWithNullComponentId(): void
62
    {
63
        $command = new ScrollToComponentCommand(null, ScrollAlign::LAST, 500);
64
        $result = $command->jsonSerialize();
65
66
        $this->assertSame(ScrollToComponentCommand::TYPE, $result['type']);
67
        $this->assertArrayNotHasKey('componentId', $result);
68
        $this->assertSame(ScrollAlign::LAST->value, $result['align']);
69
        $this->assertSame(500, $result['targetDuration']);
70
    }
71
72
    public function testJsonSerializeWithDifferentAlignValues(): void
73
    {
74
        $alignValues = [ScrollAlign::VISIBLE, ScrollAlign::CENTER, ScrollAlign::FIRST, ScrollAlign::LAST];
75
76
        foreach ($alignValues as $align) {
77
            $command = new ScrollToComponentCommand('test', $align);
78
            $result = $command->jsonSerialize();
79
80
            $this->assertSame($align->value, $result['align']);
81
        }
82
    }
83
84
    public function testTypeConstant(): void
85
    {
86
        $this->assertSame('ScrollToComponent', ScrollToComponentCommand::TYPE);
87
    }
88
}
89