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

testJsonSerializeWithPartialProperties()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 6
nc 1
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\StandardCommand\ScrollCommand;
8
use PHPUnit\Framework\TestCase;
9
10
class ScrollCommandTest extends TestCase
11
{
12
    public function testConstructorWithAllParameters(): void
13
    {
14
        $componentId = 'myScrollContainer';
15
        $distance = 500;
16
        $targetDuration = 1000;
17
18
        $command = new ScrollCommand($componentId, $distance, $targetDuration);
19
20
        $this->assertSame($componentId, $command->componentId);
21
        $this->assertSame($distance, $command->distance);
22
        $this->assertSame($targetDuration, $command->targetDuration);
23
    }
24
25
    public function testConstructorWithDefaultParameters(): void
26
    {
27
        $command = new ScrollCommand();
28
29
        $this->assertNull($command->componentId);
30
        $this->assertNull($command->distance);
31
        $this->assertNull($command->targetDuration);
32
    }
33
34
    public function testJsonSerializeWithAllProperties(): void
35
    {
36
        $componentId = 'testScroller';
37
        $distance = 300;
38
        $targetDuration = 800;
39
40
        $command = new ScrollCommand($componentId, $distance, $targetDuration);
41
        $result = $command->jsonSerialize();
42
43
        $this->assertSame(ScrollCommand::TYPE, $result['type']);
44
        $this->assertSame($componentId, $result['componentId']);
45
        $this->assertSame($distance, $result['distance']);
46
        $this->assertSame($targetDuration, $result['targetDuration']);
47
    }
48
49
    public function testJsonSerializeWithNullValues(): void
50
    {
51
        $command = new ScrollCommand();
52
        $result = $command->jsonSerialize();
53
54
        $this->assertSame(ScrollCommand::TYPE, $result['type']);
55
        $this->assertArrayNotHasKey('componentId', $result);
56
        $this->assertArrayNotHasKey('distance', $result);
57
        $this->assertArrayNotHasKey('targetDuration', $result);
58
    }
59
60
    public function testJsonSerializeWithPartialProperties(): void
61
    {
62
        $command = new ScrollCommand('scroller1', 100);
63
        $result = $command->jsonSerialize();
64
65
        $this->assertSame(ScrollCommand::TYPE, $result['type']);
66
        $this->assertSame('scroller1', $result['componentId']);
67
        $this->assertSame(100, $result['distance']);
68
        $this->assertArrayNotHasKey('targetDuration', $result);
69
    }
70
71
    public function testJsonSerializeWithNegativeDistance(): void
72
    {
73
        $command = new ScrollCommand('scroller', -200, 500);
74
        $result = $command->jsonSerialize();
75
76
        $this->assertSame(ScrollCommand::TYPE, $result['type']);
77
        $this->assertSame('scroller', $result['componentId']);
78
        $this->assertSame(-200, $result['distance']);
79
        $this->assertSame(500, $result['targetDuration']);
80
    }
81
82
    public function testJsonSerializeWithZeroValues(): void
83
    {
84
        $command = new ScrollCommand('scroller', 0, 0);
85
        $result = $command->jsonSerialize();
86
87
        $this->assertSame(ScrollCommand::TYPE, $result['type']);
88
        $this->assertSame('scroller', $result['componentId']);
89
        $this->assertSame(0, $result['distance']);
90
        $this->assertSame(0, $result['targetDuration']);
91
    }
92
93
    public function testImplementsJsonSerializable(): void
94
    {
95
        $command = new ScrollCommand();
96
97
        $this->assertInstanceOf(\JsonSerializable::class, $command);
98
    }
99
100
    public function testTypeConstant(): void
101
    {
102
        $this->assertSame('Scroll', ScrollCommand::TYPE);
103
    }
104
}
105