PathTest   A
last analyzed

Complexity

Total Complexity 13

Size/Duplication

Total Lines 201
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 139
dl 0
loc 201
rs 10
c 1
b 0
f 1
wmc 13

11 Methods

Rating   Name   Duplication   Size   Complexity  
A testConstructorWithDefaultParameters() 0 18 1
A testJsonSerializeWithEmptyStrokeDashArray() 0 6 1
A testImplementsJsonSerializable() 0 5 1
A testJsonSerializeWithAllProperties() 0 36 1
A testJsonSerializeWithStrokeLineJoinValues() 0 9 2
A testTypeConstant() 0 3 1
A testJsonSerializeWithStrokeLineCapValues() 0 9 2
A testExtendsAVGItem() 0 5 1
A testConstructorWithAllParameters() 0 48 1
A testJsonSerializeWithZeroValues() 0 18 1
A testJsonSerializeWithNullValues() 0 20 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace MaxBeckers\AmazonAlexa\Test\Response\Directives\APL\AVGItem;
6
7
use MaxBeckers\AmazonAlexa\Response\Directives\APL\AVGItem\AVGItem;
8
use MaxBeckers\AmazonAlexa\Response\Directives\APL\AVGItem\Path;
9
use MaxBeckers\AmazonAlexa\Response\Directives\APL\Document\AVGItemType;
10
use MaxBeckers\AmazonAlexa\Response\Directives\APL\Document\StrokeLineCap;
11
use MaxBeckers\AmazonAlexa\Response\Directives\APL\Document\StrokeLineJoin;
12
use PHPUnit\Framework\TestCase;
13
14
class PathTest extends TestCase
15
{
16
    public function testConstructorWithAllParameters(): void
17
    {
18
        $fill = '#ff0000';
19
        $fillOpacity = 80;
20
        $fillTransform = 'scale(1.5)';
21
        $pathData = 'M10,10 L20,20';
22
        $pathLength = 100;
23
        $stroke = '#0000ff';
24
        $strokeDashArray = [5, 10, 15];
25
        $strokeDashOffset = 2;
26
        $strokeLineCap = StrokeLineCap::ROUND;
27
        $strokeLineJoin = StrokeLineJoin::BEVEL;
28
        $strokeMiterLimit = 4;
29
        $strokeOpacity = 90;
30
        $strokeTransform = 'rotate(45)';
31
        $strokeWidth = 3;
32
33
        $path = new Path(
34
            $fill,
35
            $fillOpacity,
36
            $fillTransform,
37
            $pathData,
38
            $pathLength,
39
            $stroke,
40
            $strokeDashArray,
41
            $strokeDashOffset,
42
            $strokeLineCap,
43
            $strokeLineJoin,
44
            $strokeMiterLimit,
45
            $strokeOpacity,
46
            $strokeTransform,
47
            $strokeWidth
48
        );
49
50
        $this->assertSame($fill, $path->fill);
51
        $this->assertSame($fillOpacity, $path->fillOpacity);
52
        $this->assertSame($fillTransform, $path->fillTransform);
53
        $this->assertSame($pathData, $path->pathData);
54
        $this->assertSame($pathLength, $path->pathLength);
55
        $this->assertSame($stroke, $path->stroke);
56
        $this->assertSame($strokeDashArray, $path->strokeDashArray);
57
        $this->assertSame($strokeDashOffset, $path->strokeDashOffset);
58
        $this->assertSame($strokeLineCap, $path->strokeLineCap);
59
        $this->assertSame($strokeLineJoin, $path->strokeLineJoin);
60
        $this->assertSame($strokeMiterLimit, $path->strokeMiterLimit);
61
        $this->assertSame($strokeOpacity, $path->strokeOpacity);
62
        $this->assertSame($strokeTransform, $path->strokeTransform);
63
        $this->assertSame($strokeWidth, $path->strokeWidth);
64
    }
65
66
    public function testConstructorWithDefaultParameters(): void
67
    {
68
        $path = new Path();
69
70
        $this->assertNull($path->fill);
71
        $this->assertNull($path->fillOpacity);
72
        $this->assertNull($path->fillTransform);
73
        $this->assertNull($path->pathData);
74
        $this->assertNull($path->pathLength);
75
        $this->assertNull($path->stroke);
76
        $this->assertNull($path->strokeDashArray);
77
        $this->assertNull($path->strokeDashOffset);
78
        $this->assertNull($path->strokeLineCap);
79
        $this->assertNull($path->strokeLineJoin);
80
        $this->assertNull($path->strokeMiterLimit);
81
        $this->assertNull($path->strokeOpacity);
82
        $this->assertNull($path->strokeTransform);
83
        $this->assertNull($path->strokeWidth);
84
    }
85
86
    public function testJsonSerializeWithAllProperties(): void
87
    {
88
        $path = new Path(
89
            fill: '#green',
90
            fillOpacity: 70,
91
            fillTransform: 'translate(5, 10)',
92
            pathData: 'M0,0 L100,100 Z',
93
            pathLength: 200,
94
            stroke: '#blue',
95
            strokeDashArray: [3, 6, 9],
96
            strokeDashOffset: 1,
97
            strokeLineCap: StrokeLineCap::SQUARE,
98
            strokeLineJoin: StrokeLineJoin::MITER,
99
            strokeMiterLimit: 8,
100
            strokeOpacity: 85,
101
            strokeTransform: 'skewX(30)',
102
            strokeWidth: 2
103
        );
104
105
        $result = $path->jsonSerialize();
106
107
        $this->assertSame(AVGItemType::PATH->value, $result['type']);
108
        $this->assertSame('#green', $result['fill']);
109
        $this->assertSame(70, $result['fillOpacity']);
110
        $this->assertSame('translate(5, 10)', $result['fillTransform']);
111
        $this->assertSame('M0,0 L100,100 Z', $result['pathData']);
112
        $this->assertSame(200, $result['pathLength']);
113
        $this->assertSame('#blue', $result['stroke']);
114
        $this->assertSame([3, 6, 9], $result['strokeDashArray']);
115
        $this->assertSame(1, $result['strokeDashOffset']);
116
        $this->assertSame(StrokeLineCap::SQUARE->value, $result['strokeLineCap']);
117
        $this->assertSame(StrokeLineJoin::MITER->value, $result['strokeLineJoin']);
118
        $this->assertSame(8, $result['strokeMiterLimit']);
119
        $this->assertSame(85, $result['strokeOpacity']);
120
        $this->assertSame('skewX(30)', $result['strokeTransform']);
121
        $this->assertSame(2, $result['strokeWidth']);
122
    }
123
124
    public function testJsonSerializeWithNullValues(): void
125
    {
126
        $path = new Path();
127
        $result = $path->jsonSerialize();
128
129
        $this->assertSame(AVGItemType::PATH->value, $result['type']);
130
        $this->assertArrayNotHasKey('fill', $result);
131
        $this->assertArrayNotHasKey('fillOpacity', $result);
132
        $this->assertArrayNotHasKey('fillTransform', $result);
133
        $this->assertArrayNotHasKey('pathData', $result);
134
        $this->assertArrayNotHasKey('pathLength', $result);
135
        $this->assertArrayNotHasKey('stroke', $result);
136
        $this->assertArrayNotHasKey('strokeDashArray', $result);
137
        $this->assertArrayNotHasKey('strokeDashOffset', $result);
138
        $this->assertArrayNotHasKey('strokeLineCap', $result);
139
        $this->assertArrayNotHasKey('strokeLineJoin', $result);
140
        $this->assertArrayNotHasKey('strokeMiterLimit', $result);
141
        $this->assertArrayNotHasKey('strokeOpacity', $result);
142
        $this->assertArrayNotHasKey('strokeTransform', $result);
143
        $this->assertArrayNotHasKey('strokeWidth', $result);
144
    }
145
146
    public function testJsonSerializeWithEmptyStrokeDashArray(): void
147
    {
148
        $path = new Path(strokeDashArray: []);
149
        $result = $path->jsonSerialize();
150
151
        $this->assertArrayNotHasKey('strokeDashArray', $result);
152
    }
153
154
    public function testJsonSerializeWithStrokeLineCapValues(): void
155
    {
156
        $lineCapValues = [StrokeLineCap::BUTT, StrokeLineCap::ROUND, StrokeLineCap::SQUARE];
157
158
        foreach ($lineCapValues as $lineCap) {
159
            $path = new Path(strokeLineCap: $lineCap);
160
            $result = $path->jsonSerialize();
161
162
            $this->assertSame($lineCap->value, $result['strokeLineCap']);
163
        }
164
    }
165
166
    public function testJsonSerializeWithStrokeLineJoinValues(): void
167
    {
168
        $lineJoinValues = [StrokeLineJoin::MITER, StrokeLineJoin::ROUND, StrokeLineJoin::BEVEL];
169
170
        foreach ($lineJoinValues as $lineJoin) {
171
            $path = new Path(strokeLineJoin: $lineJoin);
172
            $result = $path->jsonSerialize();
173
174
            $this->assertSame($lineJoin->value, $result['strokeLineJoin']);
175
        }
176
    }
177
178
    public function testJsonSerializeWithZeroValues(): void
179
    {
180
        $path = new Path(
181
            fillOpacity: 0,
182
            pathLength: 0,
183
            strokeDashOffset: 0,
184
            strokeMiterLimit: 0,
185
            strokeOpacity: 0,
186
            strokeWidth: 0
187
        );
188
        $result = $path->jsonSerialize();
189
190
        $this->assertSame(0, $result['fillOpacity']);
191
        $this->assertSame(0, $result['pathLength']);
192
        $this->assertSame(0, $result['strokeDashOffset']);
193
        $this->assertSame(0, $result['strokeMiterLimit']);
194
        $this->assertSame(0, $result['strokeOpacity']);
195
        $this->assertSame(0, $result['strokeWidth']);
196
    }
197
198
    public function testTypeConstant(): void
199
    {
200
        $this->assertSame(AVGItemType::PATH, Path::TYPE);
201
    }
202
203
    public function testExtendsAVGItem(): void
204
    {
205
        $path = new Path();
206
207
        $this->assertInstanceOf(AVGItem::class, $path);
208
    }
209
210
    public function testImplementsJsonSerializable(): void
211
    {
212
        $path = new Path();
213
214
        $this->assertInstanceOf(\JsonSerializable::class, $path);
215
    }
216
}
217