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

testExtendsActionableComponent()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 5
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\Component;
6
7
use MaxBeckers\AmazonAlexa\Response\Directives\APL\Component\APLBaseComponent;
8
use MaxBeckers\AmazonAlexa\Response\Directives\APL\Component\ScrollViewComponent;
9
use MaxBeckers\AmazonAlexa\Response\Directives\APL\Document\APLComponentType;
10
use MaxBeckers\AmazonAlexa\Response\Directives\APL\StandardCommand\AbstractStandardCommand;
11
use PHPUnit\Framework\TestCase;
12
13
class ScrollViewComponentTest extends TestCase
14
{
15
    public function testConstructorWithAllParameters(): void
16
    {
17
        $item = $this->createMock(APLBaseComponent::class);
18
        $items = [
19
            $this->createMock(APLBaseComponent::class),
20
            $this->createMock(APLBaseComponent::class),
21
        ];
22
        $preserve = ['scrollPosition', 'state'];
23
        $onScroll = [$this->createMock(AbstractStandardCommand::class)];
24
25
        $component = new ScrollViewComponent($item, $items, $preserve, $onScroll);
26
27
        $this->assertSame($item, $component->item);
28
        $this->assertSame($items, $component->items);
29
        $this->assertSame($preserve, $component->preserve);
30
        $this->assertSame($onScroll, $component->onScroll);
31
    }
32
33
    public function testConstructorWithDefaultParameters(): void
34
    {
35
        $component = new ScrollViewComponent();
36
37
        $this->assertNull($component->item);
38
        $this->assertNull($component->items);
39
        $this->assertNull($component->preserve);
40
        $this->assertNull($component->onScroll);
41
    }
42
43
    public function testJsonSerializeWithAllProperties(): void
44
    {
45
        $item = $this->createMock(APLBaseComponent::class);
46
        $items = [
47
            $this->createMock(APLBaseComponent::class),
48
            $this->createMock(APLBaseComponent::class),
49
        ];
50
        $preserve = ['position', 'scroll'];
51
        $onScroll = [
52
            $this->createMock(AbstractStandardCommand::class),
53
            $this->createMock(AbstractStandardCommand::class),
54
        ];
55
56
        $component = new ScrollViewComponent($item, $items, $preserve, $onScroll);
57
        $result = $component->jsonSerialize();
58
59
        $this->assertSame(APLComponentType::SCROLL_VIEW->value, $result['type']);
60
        $this->assertSame($item, $result['item']);
61
        $this->assertSame($items, $result['items']);
62
        $this->assertSame($preserve, $result['preserve']);
63
        $this->assertSame($onScroll, $result['onScroll']);
64
    }
65
66
    public function testJsonSerializeWithNullValues(): void
67
    {
68
        $component = new ScrollViewComponent();
69
        $result = $component->jsonSerialize();
70
71
        $this->assertSame(APLComponentType::SCROLL_VIEW->value, $result['type']);
72
        $this->assertArrayNotHasKey('item', $result);
73
        $this->assertArrayNotHasKey('items', $result);
74
        $this->assertArrayNotHasKey('preserve', $result);
75
        $this->assertArrayNotHasKey('onScroll', $result);
76
    }
77
78
    public function testJsonSerializeWithEmptyArrays(): void
79
    {
80
        $component = new ScrollViewComponent(null, [], [], []);
81
        $result = $component->jsonSerialize();
82
83
        $this->assertArrayNotHasKey('items', $result);
84
        $this->assertArrayNotHasKey('preserve', $result);
85
        $this->assertArrayNotHasKey('onScroll', $result);
86
    }
87
88
    public function testJsonSerializeWithOnlyItem(): void
89
    {
90
        $item = $this->createMock(APLBaseComponent::class);
91
        $component = new ScrollViewComponent($item);
92
        $result = $component->jsonSerialize();
93
94
        $this->assertSame($item, $result['item']);
95
        $this->assertArrayNotHasKey('items', $result);
96
        $this->assertArrayNotHasKey('preserve', $result);
97
        $this->assertArrayNotHasKey('onScroll', $result);
98
    }
99
100
    public function testJsonSerializeWithOnlyItems(): void
101
    {
102
        $items = [$this->createMock(APLBaseComponent::class)];
103
        $component = new ScrollViewComponent(null, $items);
104
        $result = $component->jsonSerialize();
105
106
        $this->assertArrayNotHasKey('item', $result);
107
        $this->assertSame($items, $result['items']);
108
        $this->assertArrayNotHasKey('preserve', $result);
109
        $this->assertArrayNotHasKey('onScroll', $result);
110
    }
111
112
    public function testTypeConstant(): void
113
    {
114
        $this->assertSame(APLComponentType::SCROLL_VIEW, ScrollViewComponent::TYPE);
115
    }
116
117
    public function testExtendsActionableComponent(): void
118
    {
119
        $component = new ScrollViewComponent();
120
121
        $this->assertInstanceOf(\MaxBeckers\AmazonAlexa\Response\Directives\APL\Component\ActionableComponent::class, $component);
122
    }
123
124
    public function testImplementsJsonSerializable(): void
125
    {
126
        $component = new ScrollViewComponent();
127
128
        $this->assertInstanceOf(\JsonSerializable::class, $component);
129
    }
130
}
131