testJsonSerializeWithEmptyDescription()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 5
nc 1
nop 0
dl 0
loc 9
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\ExportItem;
8
use PHPUnit\Framework\TestCase;
9
10
class ExportItemTest extends TestCase
11
{
12
    public function testConstructorWithAllParameters(): void
13
    {
14
        $name = 'testItem';
15
        $description = 'Test description';
16
17
        $exportItem = new ExportItem($name, $description);
18
19
        $this->assertSame($name, $exportItem->name);
20
        $this->assertSame($description, $exportItem->description);
21
    }
22
23
    public function testConstructorWithDefaultDescription(): void
24
    {
25
        $name = 'myItem';
26
27
        $exportItem = new ExportItem($name);
28
29
        $this->assertSame($name, $exportItem->name);
30
        $this->assertSame('', $exportItem->description);
31
    }
32
33
    public function testJsonSerializeWithBothProperties(): void
34
    {
35
        $name = 'exportedItem';
36
        $description = 'Detailed description';
37
38
        $exportItem = new ExportItem($name, $description);
39
        $result = $exportItem->jsonSerialize();
40
41
        $this->assertSame($name, $result['name']);
42
        $this->assertSame($description, $result['description']);
43
    }
44
45
    public function testJsonSerializeWithEmptyDescription(): void
46
    {
47
        $name = 'itemWithoutDescription';
48
49
        $exportItem = new ExportItem($name, '');
50
        $result = $exportItem->jsonSerialize();
51
52
        $this->assertSame($name, $result['name']);
53
        $this->assertArrayNotHasKey('description', $result);
54
    }
55
56
    public function testJsonSerializeWithDefaultDescription(): void
57
    {
58
        $name = 'defaultDescItem';
59
60
        $exportItem = new ExportItem($name);
61
        $result = $exportItem->jsonSerialize();
62
63
        $this->assertSame($name, $result['name']);
64
        $this->assertArrayNotHasKey('description', $result);
65
    }
66
67
    public function testJsonSerializeFiltersEmptyDescription(): void
68
    {
69
        $exportItem = new ExportItem('test', '');
70
        $result = $exportItem->jsonSerialize();
71
72
        $this->assertCount(1, $result);
73
        $this->assertArrayHasKey('name', $result);
74
        $this->assertArrayNotHasKey('description', $result);
75
    }
76
77
    public function testJsonSerializeWithNonEmptyDescription(): void
78
    {
79
        $exportItem = new ExportItem('test', 'Valid description');
80
        $result = $exportItem->jsonSerialize();
81
82
        $this->assertCount(2, $result);
83
        $this->assertArrayHasKey('name', $result);
84
        $this->assertArrayHasKey('description', $result);
85
        $this->assertSame('Valid description', $result['description']);
86
    }
87
88
    public function testJsonSerializeWithWhitespaceDescription(): void
89
    {
90
        $exportItem = new ExportItem('test', '   ');
91
        $result = $exportItem->jsonSerialize();
92
93
        $this->assertArrayHasKey('description', $result);
94
        $this->assertSame('   ', $result['description']);
95
    }
96
97
    public function testImplementsJsonSerializable(): void
98
    {
99
        $exportItem = new ExportItem('test');
100
101
        $this->assertInstanceOf(\JsonSerializable::class, $exportItem);
102
    }
103
}
104