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

StyleTest::testImplementsJsonSerializable()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 5
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\Document;
6
7
use MaxBeckers\AmazonAlexa\Response\Directives\APL\Document\Style;
8
use MaxBeckers\AmazonAlexa\Response\Directives\APL\Document\StyleValue;
9
use PHPUnit\Framework\TestCase;
10
11
class StyleTest extends TestCase
12
{
13
    public function testConstructorWithAllParameters(): void
14
    {
15
        $description = 'Test style';
16
        $extend = ['baseStyle', 'mixinStyle'];
17
        $extends = 'parentStyle';
18
        $value = $this->createMock(StyleValue::class);
19
        $values = [
20
            $this->createMock(StyleValue::class),
21
            $this->createMock(StyleValue::class),
22
        ];
23
24
        $style = new Style($description, $extend, $extends, $value, $values);
25
26
        $this->assertSame($description, $style->description);
27
        $this->assertSame($extend, $style->extend);
28
        $this->assertSame($extends, $style->extends);
29
        $this->assertSame($value, $style->value);
30
        $this->assertSame($values, $style->values);
31
    }
32
33
    public function testConstructorWithDefaultParameters(): void
34
    {
35
        $style = new Style();
36
37
        $this->assertNull($style->description);
38
        $this->assertNull($style->extend);
39
        $this->assertNull($style->extends);
40
        $this->assertNull($style->value);
41
        $this->assertNull($style->values);
42
    }
43
44
    public function testJsonSerializeWithAllProperties(): void
45
    {
46
        $description = 'Complex style';
47
        $extend = ['style1', 'style2'];
48
        $extends = 'baseStyle';
49
        $value = $this->createMock(StyleValue::class);
50
        $values = [$this->createMock(StyleValue::class)];
51
52
        $style = new Style($description, $extend, $extends, $value, $values);
53
        $result = $style->jsonSerialize();
54
55
        $this->assertSame($description, $result['description']);
56
        $this->assertSame($extend, $result['extend']);
57
        $this->assertSame($extends, $result['extends']);
58
        $this->assertSame($value, $result['value']);
59
        $this->assertSame($values, $result['values']);
60
    }
61
62
    public function testJsonSerializeWithNullValues(): void
63
    {
64
        $style = new Style();
65
        $result = $style->jsonSerialize();
66
67
        $this->assertEmpty($result);
68
        $this->assertArrayNotHasKey('description', $result);
69
        $this->assertArrayNotHasKey('extend', $result);
70
        $this->assertArrayNotHasKey('extends', $result);
71
        $this->assertArrayNotHasKey('value', $result);
72
        $this->assertArrayNotHasKey('values', $result);
73
    }
74
75
    public function testJsonSerializeFiltersEmptyDescription(): void
76
    {
77
        $style = new Style('');
78
        $result = $style->jsonSerialize();
79
80
        $this->assertArrayNotHasKey('description', $result);
81
    }
82
83
    public function testJsonSerializeFiltersEmptyExtend(): void
84
    {
85
        $style = new Style(null, []);
86
        $result = $style->jsonSerialize();
87
88
        $this->assertArrayNotHasKey('extend', $result);
89
    }
90
91
    public function testJsonSerializeFiltersEmptyExtends(): void
92
    {
93
        $style = new Style(null, null, '');
94
        $result = $style->jsonSerialize();
95
96
        $this->assertArrayNotHasKey('extends', $result);
97
    }
98
99
    public function testJsonSerializeFiltersEmptyValues(): void
100
    {
101
        $style = new Style(null, null, null, null, []);
102
        $result = $style->jsonSerialize();
103
104
        $this->assertArrayNotHasKey('values', $result);
105
    }
106
107
    public function testJsonSerializeWithNonEmptyDescription(): void
108
    {
109
        $style = new Style('Valid description');
110
        $result = $style->jsonSerialize();
111
112
        $this->assertArrayHasKey('description', $result);
113
        $this->assertSame('Valid description', $result['description']);
114
    }
115
116
    public function testJsonSerializeWithNonEmptyExtend(): void
117
    {
118
        $extend = ['parent1', 'parent2'];
119
        $style = new Style(null, $extend);
120
        $result = $style->jsonSerialize();
121
122
        $this->assertArrayHasKey('extend', $result);
123
        $this->assertSame($extend, $result['extend']);
124
    }
125
126
    public function testJsonSerializeWithNonEmptyExtends(): void
127
    {
128
        $style = new Style(null, null, 'parentStyle');
129
        $result = $style->jsonSerialize();
130
131
        $this->assertArrayHasKey('extends', $result);
132
        $this->assertSame('parentStyle', $result['extends']);
133
    }
134
135
    public function testJsonSerializeWithStyleValueInstance(): void
136
    {
137
        $value = $this->createMock(StyleValue::class);
138
        $style = new Style(null, null, null, $value);
139
        $result = $style->jsonSerialize();
140
141
        $this->assertArrayHasKey('value', $result);
142
        $this->assertSame($value, $result['value']);
143
    }
144
145
    public function testJsonSerializeWithNonEmptyValues(): void
146
    {
147
        $values = [
148
            $this->createMock(StyleValue::class),
149
            $this->createMock(StyleValue::class),
150
        ];
151
        $style = new Style(null, null, null, null, $values);
152
        $result = $style->jsonSerialize();
153
154
        $this->assertArrayHasKey('values', $result);
155
        $this->assertSame($values, $result['values']);
156
    }
157
158
    public function testJsonSerializeWithPartialProperties(): void
159
    {
160
        $extend = ['mixinStyle'];
161
        $value = $this->createMock(StyleValue::class);
162
163
        $style = new Style(null, $extend, null, $value);
164
        $result = $style->jsonSerialize();
165
166
        $this->assertArrayHasKey('extend', $result);
167
        $this->assertArrayHasKey('value', $result);
168
        $this->assertArrayNotHasKey('description', $result);
169
        $this->assertArrayNotHasKey('extends', $result);
170
        $this->assertArrayNotHasKey('values', $result);
171
        $this->assertSame($extend, $result['extend']);
172
        $this->assertSame($value, $result['value']);
173
    }
174
175
    public function testImplementsJsonSerializable(): void
176
    {
177
        $style = new Style();
178
179
        $this->assertInstanceOf(\JsonSerializable::class, $style);
180
    }
181
}
182