ImportTest   A
last analyzed

Complexity

Total Complexity 15

Size/Duplication

Total Lines 168
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 91
dl 0
loc 168
rs 10
c 1
b 0
f 1
wmc 15

15 Methods

Rating   Name   Duplication   Size   Complexity  
A testJsonSerializeExcludesWhenTrue() 0 6 1
A testJsonSerializeIncludesWhenFalse() 0 7 1
A testJsonSerializeFiltersEmptySource() 0 6 1
A testJsonSerializeWithMinimalProperties() 0 12 1
A testJsonSerializeWithNonEmptyLoadAfter() 0 8 1
A testJsonSerializeWithAllProperties() 0 20 1
A testJsonSerializeFiltersEmptyAccept() 0 6 1
A testConstructorWithDefaultParameters() 0 14 1
A testJsonSerializeWithImportType() 0 7 1
A testJsonSerializeFiltersEmptyLoadAfter() 0 6 1
A testJsonSerializeStructure() 0 8 1
A testImplementsJsonSerializable() 0 5 1
A testJsonSerializeWithNonEmptySource() 0 7 1
A testConstructorWithAllParameters() 0 19 1
A testJsonSerializeWithNonEmptyAccept() 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\Import;
8
use MaxBeckers\AmazonAlexa\Response\Directives\APL\Document\ImportType;
9
use PHPUnit\Framework\TestCase;
10
11
class ImportTest extends TestCase
12
{
13
    public function testConstructorWithAllParameters(): void
14
    {
15
        $name = 'testPackage';
16
        $version = '1.0.0';
17
        $accept = 'application/json';
18
        $loadAfter = ['package1', 'package2'];
19
        $source = 'https://example.com/package';
20
        $type = ImportType::ALL_OF;
21
        $when = false;
22
23
        $import = new Import($name, $version, $accept, $loadAfter, $source, $type, $when);
24
25
        $this->assertSame($name, $import->name);
26
        $this->assertSame($version, $import->version);
27
        $this->assertSame($accept, $import->accept);
28
        $this->assertSame($loadAfter, $import->loadAfter);
29
        $this->assertSame($source, $import->source);
30
        $this->assertSame($type, $import->type);
31
        $this->assertFalse($import->when);
32
    }
33
34
    public function testConstructorWithDefaultParameters(): void
35
    {
36
        $name = 'myPackage';
37
        $version = '2.0.0';
38
39
        $import = new Import($name, $version);
40
41
        $this->assertSame($name, $import->name);
42
        $this->assertSame($version, $import->version);
43
        $this->assertNull($import->accept);
44
        $this->assertNull($import->loadAfter);
45
        $this->assertNull($import->source);
46
        $this->assertNull($import->type);
47
        $this->assertTrue($import->when);
48
    }
49
50
    public function testJsonSerializeWithAllProperties(): void
51
    {
52
        $name = 'fullPackage';
53
        $version = '1.2.3';
54
        $accept = 'text/plain';
55
        $loadAfter = ['dep1', 'dep2'];
56
        $source = 'https://test.com/pkg';
57
        $type = ImportType::ALL_OF;
58
        $when = false;
59
60
        $import = new Import($name, $version, $accept, $loadAfter, $source, $type, $when);
61
        $result = $import->jsonSerialize();
62
63
        $this->assertSame($name, $result['name']);
64
        $this->assertSame($version, $result['version']);
65
        $this->assertSame($accept, $result['accept']);
66
        $this->assertSame($loadAfter, $result['loadAfter']);
67
        $this->assertSame($source, $result['source']);
68
        $this->assertSame($type->value, $result['type']);
69
        $this->assertFalse($result['when']);
70
    }
71
72
    public function testJsonSerializeWithMinimalProperties(): void
73
    {
74
        $import = new Import('minimal', '1.0');
75
        $result = $import->jsonSerialize();
76
77
        $this->assertSame('minimal', $result['name']);
78
        $this->assertSame('1.0', $result['version']);
79
        $this->assertArrayNotHasKey('accept', $result);
80
        $this->assertArrayNotHasKey('loadAfter', $result);
81
        $this->assertArrayNotHasKey('source', $result);
82
        $this->assertArrayNotHasKey('type', $result);
83
        $this->assertArrayNotHasKey('when', $result);
84
    }
85
86
    public function testJsonSerializeFiltersEmptyAccept(): void
87
    {
88
        $import = new Import('test', '1.0', '');
89
        $result = $import->jsonSerialize();
90
91
        $this->assertArrayNotHasKey('accept', $result);
92
    }
93
94
    public function testJsonSerializeFiltersEmptyLoadAfter(): void
95
    {
96
        $import = new Import('test', '1.0', null, []);
97
        $result = $import->jsonSerialize();
98
99
        $this->assertArrayNotHasKey('loadAfter', $result);
100
    }
101
102
    public function testJsonSerializeFiltersEmptySource(): void
103
    {
104
        $import = new Import('test', '1.0', null, null, '');
105
        $result = $import->jsonSerialize();
106
107
        $this->assertArrayNotHasKey('source', $result);
108
    }
109
110
    public function testJsonSerializeIncludesWhenFalse(): void
111
    {
112
        $import = new Import('test', '1.0', when: false);
113
        $result = $import->jsonSerialize();
114
115
        $this->assertArrayHasKey('when', $result);
116
        $this->assertFalse($result['when']);
117
    }
118
119
    public function testJsonSerializeExcludesWhenTrue(): void
120
    {
121
        $import = new Import('test', '1.0', when: true);
122
        $result = $import->jsonSerialize();
123
124
        $this->assertArrayNotHasKey('when', $result);
125
    }
126
127
    public function testJsonSerializeWithNonEmptyAccept(): void
128
    {
129
        $import = new Import('test', '1.0', 'application/json');
130
        $result = $import->jsonSerialize();
131
132
        $this->assertArrayHasKey('accept', $result);
133
        $this->assertSame('application/json', $result['accept']);
134
    }
135
136
    public function testJsonSerializeWithNonEmptyLoadAfter(): void
137
    {
138
        $loadAfter = ['dependency1', 'dependency2'];
139
        $import = new Import('test', '1.0', null, $loadAfter);
140
        $result = $import->jsonSerialize();
141
142
        $this->assertArrayHasKey('loadAfter', $result);
143
        $this->assertSame($loadAfter, $result['loadAfter']);
144
    }
145
146
    public function testJsonSerializeWithNonEmptySource(): void
147
    {
148
        $import = new Import('test', '1.0', null, null, 'https://source.com');
149
        $result = $import->jsonSerialize();
150
151
        $this->assertArrayHasKey('source', $result);
152
        $this->assertSame('https://source.com', $result['source']);
153
    }
154
155
    public function testJsonSerializeWithImportType(): void
156
    {
157
        $import = new Import('test', '1.0', type: ImportType::ALL_OF);
158
        $result = $import->jsonSerialize();
159
160
        $this->assertArrayHasKey('type', $result);
161
        $this->assertSame(ImportType::ALL_OF->value, $result['type']);
162
    }
163
164
    public function testJsonSerializeStructure(): void
165
    {
166
        $import = new Import('test', '1.0');
167
        $result = $import->jsonSerialize();
168
169
        $this->assertIsArray($result);
170
        $this->assertArrayHasKey('name', $result);
171
        $this->assertArrayHasKey('version', $result);
172
    }
173
174
    public function testImplementsJsonSerializable(): void
175
    {
176
        $import = new Import('test', '1.0');
177
178
        $this->assertInstanceOf(\JsonSerializable::class, $import);
179
    }
180
}
181