testUsesActionableComponentTrait()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

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