Passed
Push — master ( a53d55...43aca1 )
by Maximilian
03:50
created

GradientTest   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 123
Duplicated Lines 0 %

Importance

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

10 Methods

Rating   Name   Duplication   Size   Complexity  
A testImplementsJsonSerializable() 0 5 1
A testJsonSerializeWithEmptyInputRange() 0 7 1
A testJsonSerializeStructure() 0 11 1
A testConstructorWithDefaultParameters() 0 11 1
A testJsonSerializeWithDefaultValues() 0 11 1
A testJsonSerializeWithAllProperties() 0 16 1
A testConstructorWithAllParameters() 0 15 1
A testJsonSerializeWithDifferentBackgroundTypes() 0 10 2
A testJsonSerializeWithValidInputRange() 0 9 1
A testJsonSerializeWithNullInputRange() 0 7 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace MaxBeckers\AmazonAlexa\Test\Response\Directives\APL\Document;
6
7
use MaxBeckers\AmazonAlexa\Response\Directives\APL\Document\BackgroundType;
8
use MaxBeckers\AmazonAlexa\Response\Directives\APL\Document\Gradient;
9
use PHPUnit\Framework\TestCase;
10
11
class GradientTest extends TestCase
12
{
13
    public function testConstructorWithAllParameters(): void
14
    {
15
        $colorRange = ['#ff0000', '#00ff00', '#0000ff'];
16
        $description = 'RGB gradient';
17
        $type = BackgroundType::RADIAL;
18
        $inputRange = [0.0, 0.5, 1.0];
19
        $angle = 45;
20
21
        $gradient = new Gradient($colorRange, $description, $type, $inputRange, $angle);
22
23
        $this->assertSame($colorRange, $gradient->colorRange);
24
        $this->assertSame($description, $gradient->description);
25
        $this->assertSame($type, $gradient->type);
26
        $this->assertSame($inputRange, $gradient->inputRange);
27
        $this->assertSame($angle, $gradient->angle);
28
    }
29
30
    public function testConstructorWithDefaultParameters(): void
31
    {
32
        $colorRange = ['#000000', '#ffffff'];
33
34
        $gradient = new Gradient($colorRange);
35
36
        $this->assertSame($colorRange, $gradient->colorRange);
37
        $this->assertSame('', $gradient->description);
38
        $this->assertSame(BackgroundType::LINEAR, $gradient->type);
39
        $this->assertSame([], $gradient->inputRange);
40
        $this->assertSame(0, $gradient->angle);
41
    }
42
43
    public function testJsonSerializeWithAllProperties(): void
44
    {
45
        $colorRange = ['red', 'blue'];
46
        $description = 'Test gradient';
47
        $type = BackgroundType::RADIAL;
48
        $inputRange = [0.0, 1.0];
49
        $angle = 90;
50
51
        $gradient = new Gradient($colorRange, $description, $type, $inputRange, $angle);
52
        $result = $gradient->jsonSerialize();
53
54
        $this->assertSame($description, $result['description']);
55
        $this->assertSame($colorRange, $result['colorRange']);
56
        $this->assertSame($angle, $result['angle']);
57
        $this->assertSame($type, $result['type']);
58
        $this->assertSame($inputRange, $result['inputRange']);
59
    }
60
61
    public function testJsonSerializeWithEmptyInputRange(): void
62
    {
63
        $colorRange = ['#ff0000', '#00ff00'];
64
        $gradient = new Gradient($colorRange, 'test', BackgroundType::LINEAR, []);
65
        $result = $gradient->jsonSerialize();
66
67
        $this->assertArrayNotHasKey('inputRange', $result);
68
    }
69
70
    public function testJsonSerializeWithNullInputRange(): void
71
    {
72
        $colorRange = ['#ff0000', '#00ff00'];
73
        $gradient = new Gradient($colorRange, 'test', BackgroundType::LINEAR, null);
74
        $result = $gradient->jsonSerialize();
75
76
        $this->assertArrayNotHasKey('inputRange', $result);
77
    }
78
79
    public function testJsonSerializeWithValidInputRange(): void
80
    {
81
        $colorRange = ['#ff0000', '#00ff00'];
82
        $inputRange = [0.0, 0.3, 1.0];
83
        $gradient = new Gradient($colorRange, 'test', BackgroundType::LINEAR, $inputRange);
84
        $result = $gradient->jsonSerialize();
85
86
        $this->assertArrayHasKey('inputRange', $result);
87
        $this->assertSame($inputRange, $result['inputRange']);
88
    }
89
90
    public function testJsonSerializeWithDifferentBackgroundTypes(): void
91
    {
92
        $colorRange = ['black', 'white'];
93
        $types = [BackgroundType::LINEAR, BackgroundType::RADIAL];
94
95
        foreach ($types as $type) {
96
            $gradient = new Gradient($colorRange, '', $type);
97
            $result = $gradient->jsonSerialize();
98
99
            $this->assertSame($type, $result['type']);
100
        }
101
    }
102
103
    public function testJsonSerializeWithDefaultValues(): void
104
    {
105
        $colorRange = ['#123456'];
106
        $gradient = new Gradient($colorRange);
107
        $result = $gradient->jsonSerialize();
108
109
        $this->assertSame('', $result['description']);
110
        $this->assertSame($colorRange, $result['colorRange']);
111
        $this->assertSame(0, $result['angle']);
112
        $this->assertSame(BackgroundType::LINEAR, $result['type']);
113
        $this->assertArrayNotHasKey('inputRange', $result);
114
    }
115
116
    public function testJsonSerializeStructure(): void
117
    {
118
        $gradient = new Gradient(['red'], 'test', BackgroundType::LINEAR, [0.0, 1.0], 180);
119
        $result = $gradient->jsonSerialize();
120
121
        $this->assertIsArray($result);
122
        $this->assertArrayHasKey('description', $result);
123
        $this->assertArrayHasKey('colorRange', $result);
124
        $this->assertArrayHasKey('angle', $result);
125
        $this->assertArrayHasKey('type', $result);
126
        $this->assertArrayHasKey('inputRange', $result);
127
    }
128
129
    public function testImplementsJsonSerializable(): void
130
    {
131
        $gradient = new Gradient(['color']);
132
133
        $this->assertInstanceOf(\JsonSerializable::class, $gradient);
134
    }
135
}
136