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

FrameComponentTest   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 150
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 89
dl 0
loc 150
rs 10
c 1
b 0
f 1
wmc 11

11 Methods

Rating   Name   Duplication   Size   Complexity  
A testConstructorWithAllParameters() 0 32 1
A testConstructorWithDefaultParameters() 0 10 1
A testExtendsAPLBaseComponent() 0 5 1
A testJsonSerializeWithItems() 0 11 1
A testJsonSerializeWithEmptyItems() 0 6 1
A testJsonSerializeWithDefaultValues() 0 8 1
A testTypeConstant() 0 3 1
A testConstructorWithGradientBackground() 0 7 1
A testImplementsJsonSerializable() 0 5 1
A testJsonSerializeWithNonDefaultBorderValues() 0 7 1
A testJsonSerializeWithAllProperties() 0 34 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\FrameComponent;
9
use MaxBeckers\AmazonAlexa\Response\Directives\APL\Document\APLComponentType;
10
use MaxBeckers\AmazonAlexa\Response\Directives\APL\Document\Gradient;
11
use PHPUnit\Framework\TestCase;
12
13
class FrameComponentTest extends TestCase
14
{
15
    public function testConstructorWithAllParameters(): void
16
    {
17
        $background = '#ffffff';
18
        $backgroundColor = '#000000';
19
        $borderColor = '#ff0000';
20
        $borderRadius = '10px';
21
        $borderWidth = '2px';
22
        $item = $this->createMock(APLBaseComponent::class);
23
        $items = [$this->createMock(APLBaseComponent::class)];
24
25
        $component = new FrameComponent(
26
            $background,
27
            $backgroundColor,
28
            null,
29
            null,
30
            $borderColor,
31
            $borderRadius,
32
            null,
33
            null,
34
            null,
35
            $borderWidth,
36
            $item,
37
            $items
38
        );
39
40
        $this->assertSame($background, $component->background);
41
        $this->assertSame($backgroundColor, $component->backgroundColor);
42
        $this->assertSame($borderColor, $component->borderColor);
43
        $this->assertSame($borderRadius, $component->borderRadius);
44
        $this->assertSame($borderWidth, $component->borderWidth);
45
        $this->assertSame($item, $component->item);
46
        $this->assertSame($items, $component->items);
47
    }
48
49
    public function testConstructorWithGradientBackground(): void
50
    {
51
        $gradient = $this->createMock(Gradient::class);
52
53
        $component = new FrameComponent(background: $gradient);
54
55
        $this->assertSame($gradient, $component->background);
56
    }
57
58
    public function testConstructorWithDefaultParameters(): void
59
    {
60
        $component = new FrameComponent();
61
62
        $this->assertNull($component->background);
63
        $this->assertNull($component->backgroundColor);
64
        $this->assertSame('0', $component->borderRadius);
65
        $this->assertSame('0', $component->borderWidth);
66
        $this->assertNull($component->item);
67
        $this->assertNull($component->items);
68
    }
69
70
    public function testJsonSerializeWithAllProperties(): void
71
    {
72
        $background = '#blue';
73
        $backgroundColor = '#red';
74
        $borderBottomLeftRadius = '5px';
75
        $borderTopRightRadius = '8px';
76
        $borderColor = '#green';
77
        $borderStrokeWidth = '1px';
78
        $item = $this->createMock(APLBaseComponent::class);
79
80
        $component = new FrameComponent(
81
            background: $background,
82
            backgroundColor: $backgroundColor,
83
            borderBottomLeftRadius: $borderBottomLeftRadius,
84
            borderTopRightRadius: $borderTopRightRadius,
85
            borderColor: $borderColor,
86
            borderRadius: '10px',
87
            borderStrokeWidth: $borderStrokeWidth,
88
            borderWidth: '2px',
89
            item: $item
90
        );
91
92
        $result = $component->jsonSerialize();
93
94
        $this->assertSame(APLComponentType::FRAME->value, $result['type']);
95
        $this->assertSame($background, $result['background']);
96
        $this->assertSame($backgroundColor, $result['backgroundColor']);
97
        $this->assertSame($borderBottomLeftRadius, $result['borderBottomLeftRadius']);
98
        $this->assertSame($borderTopRightRadius, $result['borderTopRightRadius']);
99
        $this->assertSame($borderColor, $result['borderColor']);
100
        $this->assertSame('10px', $result['borderRadius']);
101
        $this->assertSame($borderStrokeWidth, $result['borderStrokeWidth']);
102
        $this->assertSame('2px', $result['borderWidth']);
103
        $this->assertSame($item, $result['item']);
104
    }
105
106
    public function testJsonSerializeWithDefaultValues(): void
107
    {
108
        $component = new FrameComponent();
109
        $result = $component->jsonSerialize();
110
111
        $this->assertSame(APLComponentType::FRAME->value, $result['type']);
112
        $this->assertArrayNotHasKey('borderRadius', $result);
113
        $this->assertArrayNotHasKey('borderWidth', $result);
114
    }
115
116
    public function testJsonSerializeWithNonDefaultBorderValues(): void
117
    {
118
        $component = new FrameComponent(borderRadius: '5px', borderWidth: '1px');
119
        $result = $component->jsonSerialize();
120
121
        $this->assertSame('5px', $result['borderRadius']);
122
        $this->assertSame('1px', $result['borderWidth']);
123
    }
124
125
    public function testJsonSerializeWithEmptyItems(): void
126
    {
127
        $component = new FrameComponent(items: []);
128
        $result = $component->jsonSerialize();
129
130
        $this->assertArrayNotHasKey('items', $result);
131
    }
132
133
    public function testJsonSerializeWithItems(): void
134
    {
135
        $items = [
136
            $this->createMock(APLBaseComponent::class),
137
            $this->createMock(APLBaseComponent::class),
138
        ];
139
140
        $component = new FrameComponent(items: $items);
141
        $result = $component->jsonSerialize();
142
143
        $this->assertSame($items, $result['items']);
144
    }
145
146
    public function testTypeConstant(): void
147
    {
148
        $this->assertSame(APLComponentType::FRAME, FrameComponent::TYPE);
149
    }
150
151
    public function testExtendsAPLBaseComponent(): void
152
    {
153
        $component = new FrameComponent();
154
155
        $this->assertInstanceOf(APLBaseComponent::class, $component);
156
    }
157
158
    public function testImplementsJsonSerializable(): void
159
    {
160
        $component = new FrameComponent();
161
162
        $this->assertInstanceOf(\JsonSerializable::class, $component);
163
    }
164
}
165