GridSequenceComponentTest::testTypeConstant()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
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\Request\ScrollDirection;
8
use MaxBeckers\AmazonAlexa\Response\Directives\APL\Component\APLBaseComponent;
9
use MaxBeckers\AmazonAlexa\Response\Directives\APL\Component\GridSequenceComponent;
10
use MaxBeckers\AmazonAlexa\Response\Directives\APL\Component\Traits\ActionableComponentTrait;
11
use MaxBeckers\AmazonAlexa\Response\Directives\APL\Component\Traits\MultiChildComponentTrait;
12
use MaxBeckers\AmazonAlexa\Response\Directives\APL\Document\APLComponentType;
13
use MaxBeckers\AmazonAlexa\Response\Directives\APL\Document\Snap;
14
use MaxBeckers\AmazonAlexa\Response\Directives\APL\StandardCommand\AbstractStandardCommand;
15
use PHPUnit\Framework\TestCase;
16
17
class GridSequenceComponentTest extends TestCase
18
{
19
    public function testConstructorWithAllParameters(): void
20
    {
21
        $childHeight = '100dp';
22
        $childHeights = ['100dp', '200dp'];
23
        $childWidth = '150dp';
24
        $childWidths = ['150dp', '250dp'];
25
        $numbered = true;
26
        $onScroll = [$this->createMock(AbstractStandardCommand::class)];
27
        $preserve = ['scrollPosition'];
28
        $scrollDirection = ScrollDirection::HORIZONTAL;
29
        $snap = Snap::CENTER;
30
31
        $component = new GridSequenceComponent(
32
            $childHeight,
33
            $childHeights,
34
            $childWidth,
35
            $childWidths,
36
            $numbered,
37
            $onScroll,
38
            $preserve,
39
            $scrollDirection,
40
            $snap
41
        );
42
43
        $this->assertSame($childHeight, $component->childHeight);
44
        $this->assertSame($childHeights, $component->childHeights);
45
        $this->assertSame($childWidth, $component->childWidth);
46
        $this->assertSame($childWidths, $component->childWidths);
47
        $this->assertTrue($component->numbered);
48
        $this->assertSame($onScroll, $component->onScroll);
49
        $this->assertSame($preserve, $component->preserve);
50
        $this->assertSame($scrollDirection, $component->scrollDirection);
51
        $this->assertSame($snap, $component->snap);
52
    }
53
54
    public function testConstructorWithDefaultParameters(): void
55
    {
56
        $component = new GridSequenceComponent();
57
58
        $this->assertNull($component->childHeight);
59
        $this->assertNull($component->childHeights);
60
        $this->assertNull($component->childWidth);
61
        $this->assertNull($component->childWidths);
62
        $this->assertFalse($component->numbered);
63
        $this->assertNull($component->onScroll);
64
        $this->assertNull($component->preserve);
65
        $this->assertNull($component->scrollDirection);
66
        $this->assertNull($component->snap);
67
    }
68
69
    public function testJsonSerializeWithAllProperties(): void
70
    {
71
        $childHeight = '80dp';
72
        $childHeights = ['80dp', '120dp'];
73
        $childWidth = '100dp';
74
        $childWidths = ['100dp', '200dp'];
75
        $onScroll = [
76
            $this->createMock(AbstractStandardCommand::class),
77
            $this->createMock(AbstractStandardCommand::class),
78
        ];
79
        $preserve = ['state', 'position'];
80
        $scrollDirection = ScrollDirection::VERTICAL;
81
        $snap = Snap::START;
82
83
        $component = new GridSequenceComponent(
84
            $childHeight,
85
            $childHeights,
86
            $childWidth,
87
            $childWidths,
88
            true,
89
            $onScroll,
90
            $preserve,
91
            $scrollDirection,
92
            $snap
93
        );
94
95
        $result = $component->jsonSerialize();
96
97
        $this->assertSame(APLComponentType::GRID_SEQUENCE->value, $result['type']);
98
        $this->assertSame($childHeight, $result['childHeight']);
99
        $this->assertSame($childHeights, $result['childHeights']);
100
        $this->assertSame($childWidth, $result['childWidth']);
101
        $this->assertSame($childWidths, $result['childWidths']);
102
        $this->assertTrue($result['numbered']);
103
        $this->assertSame($onScroll, $result['onScroll']);
104
        $this->assertSame($preserve, $result['preserve']);
105
        $this->assertSame($scrollDirection->value, $result['scrollDirection']);
106
        $this->assertSame($snap->value, $result['snap']);
107
    }
108
109
    public function testJsonSerializeWithDefaultNumbered(): void
110
    {
111
        $component = new GridSequenceComponent();
112
        $result = $component->jsonSerialize();
113
114
        $this->assertArrayNotHasKey('numbered', $result);
115
    }
116
117
    public function testJsonSerializeWithNumberedTrue(): void
118
    {
119
        $component = new GridSequenceComponent(numbered: true);
120
        $result = $component->jsonSerialize();
121
122
        $this->assertTrue($result['numbered']);
123
    }
124
125
    public function testJsonSerializeWithEmptyArrays(): void
126
    {
127
        $component = new GridSequenceComponent(
128
            childHeights: [],
129
            childWidths: [],
130
            onScroll: [],
131
            preserve: []
132
        );
133
        $result = $component->jsonSerialize();
134
135
        $this->assertArrayNotHasKey('childHeights', $result);
136
        $this->assertArrayNotHasKey('childWidths', $result);
137
        $this->assertArrayNotHasKey('onScroll', $result);
138
        $this->assertArrayNotHasKey('preserve', $result);
139
    }
140
141
    public function testJsonSerializeWithNullValues(): void
142
    {
143
        $component = new GridSequenceComponent();
144
        $result = $component->jsonSerialize();
145
146
        $this->assertSame(APLComponentType::GRID_SEQUENCE->value, $result['type']);
147
        $this->assertArrayNotHasKey('childHeight', $result);
148
        $this->assertArrayNotHasKey('childHeights', $result);
149
        $this->assertArrayNotHasKey('childWidth', $result);
150
        $this->assertArrayNotHasKey('childWidths', $result);
151
        $this->assertArrayNotHasKey('onScroll', $result);
152
        $this->assertArrayNotHasKey('preserve', $result);
153
        $this->assertArrayNotHasKey('scrollDirection', $result);
154
        $this->assertArrayNotHasKey('snap', $result);
155
    }
156
157
    public function testTypeConstant(): void
158
    {
159
        $this->assertSame(APLComponentType::GRID_SEQUENCE, GridSequenceComponent::TYPE);
160
    }
161
162
    public function testExtendsAPLBaseComponent(): void
163
    {
164
        $component = new GridSequenceComponent();
165
166
        $this->assertInstanceOf(APLBaseComponent::class, $component);
167
    }
168
169
    public function testUsesActionableComponentTrait(): void
170
    {
171
        $component = new GridSequenceComponent();
172
173
        $this->assertTrue(in_array(
174
            ActionableComponentTrait::class,
175
            class_uses($component),
176
            true
177
        ));
178
    }
179
180
    public function testUsesMultiChildComponentTrait(): void
181
    {
182
        $component = new GridSequenceComponent();
183
184
        $this->assertTrue(in_array(
185
            MultiChildComponentTrait::class,
186
            class_uses($component),
187
            true
188
        ));
189
    }
190
191
    public function testImplementsJsonSerializable(): void
192
    {
193
        $component = new GridSequenceComponent();
194
195
        $this->assertInstanceOf(\JsonSerializable::class, $component);
196
    }
197
}
198