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

testJsonSerializeWithEmptyParameters()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
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 8
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\Environment;
8
use MaxBeckers\AmazonAlexa\Response\Directives\APL\Document\LayoutDirection;
9
use PHPUnit\Framework\TestCase;
10
11
class EnvironmentTest extends TestCase
12
{
13
    public function testConstructorWithAllParameters(): void
14
    {
15
        $lang = 'en-US';
16
        $layoutDirection = LayoutDirection::RTL;
17
        $parameters = ['param1', 'param2', 'param3'];
18
19
        $environment = new Environment($lang, $layoutDirection, $parameters);
20
21
        $this->assertSame($lang, $environment->lang);
22
        $this->assertSame($layoutDirection, $environment->layoutDirection);
23
        $this->assertSame($parameters, $environment->parameters);
24
    }
25
26
    public function testConstructorWithDefaultParameters(): void
27
    {
28
        $environment = new Environment();
29
30
        $this->assertNull($environment->lang);
31
        $this->assertNull($environment->layoutDirection);
32
        $this->assertNull($environment->parameters);
33
    }
34
35
    public function testJsonSerializeWithAllProperties(): void
36
    {
37
        $lang = 'fr-FR';
38
        $layoutDirection = LayoutDirection::LTR;
39
        $parameters = ['width', 'height', 'theme'];
40
41
        $environment = new Environment($lang, $layoutDirection, $parameters);
42
        $result = $environment->jsonSerialize();
43
44
        $this->assertSame($lang, $result['lang']);
45
        $this->assertSame($layoutDirection->value, $result['layoutDirection']);
46
        $this->assertSame($parameters, $result['parameters']);
47
    }
48
49
    public function testJsonSerializeWithNullValues(): void
50
    {
51
        $environment = new Environment();
52
        $result = $environment->jsonSerialize();
53
54
        $this->assertEmpty($result);
55
        $this->assertArrayNotHasKey('lang', $result);
56
        $this->assertArrayNotHasKey('layoutDirection', $result);
57
        $this->assertArrayNotHasKey('parameters', $result);
58
    }
59
60
    public function testJsonSerializeWithEmptyParameters(): void
61
    {
62
        $environment = new Environment('en-GB', LayoutDirection::LTR, []);
63
        $result = $environment->jsonSerialize();
64
65
        $this->assertSame('en-GB', $result['lang']);
66
        $this->assertSame(LayoutDirection::LTR->value, $result['layoutDirection']);
67
        $this->assertArrayNotHasKey('parameters', $result);
68
    }
69
70
    public function testJsonSerializeWithPartialProperties(): void
71
    {
72
        $environment = new Environment('de-DE', null, ['locale']);
73
        $result = $environment->jsonSerialize();
74
75
        $this->assertSame('de-DE', $result['lang']);
76
        $this->assertSame(['locale'], $result['parameters']);
77
        $this->assertArrayNotHasKey('layoutDirection', $result);
78
    }
79
80
    public function testJsonSerializeWithDifferentLayoutDirections(): void
81
    {
82
        $directions = [LayoutDirection::LTR, LayoutDirection::RTL];
83
84
        foreach ($directions as $direction) {
85
            $environment = new Environment(layoutDirection: $direction);
86
            $result = $environment->jsonSerialize();
87
88
            $this->assertSame($direction->value, $result['layoutDirection']);
89
        }
90
    }
91
92
    public function testJsonSerializeWithSingleParameter(): void
93
    {
94
        $environment = new Environment(parameters: ['singleParam']);
95
        $result = $environment->jsonSerialize();
96
97
        $this->assertSame(['singleParam'], $result['parameters']);
98
    }
99
100
    public function testJsonSerializeWithMultipleParameters(): void
101
    {
102
        $parameters = ['param1', 'param2', 'param3', 'param4'];
103
        $environment = new Environment(parameters: $parameters);
104
        $result = $environment->jsonSerialize();
105
106
        $this->assertSame($parameters, $result['parameters']);
107
    }
108
109
    public function testImplementsJsonSerializable(): void
110
    {
111
        $environment = new Environment();
112
113
        $this->assertInstanceOf(\JsonSerializable::class, $environment);
114
    }
115
}
116