PseudoLocalizationTest   A
last analyzed

Complexity

Total Complexity 14

Size/Duplication

Total Lines 122
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 59
dl 0
loc 122
rs 10
c 1
b 0
f 1
wmc 14

12 Methods

Rating   Name   Duplication   Size   Complexity  
A testJsonSerializeWithZeroExpansionPercentage() 0 7 1
A testConstructorWithDefaultParameters() 0 6 1
A testJsonSerializeWithNonDefaultExpansionPercentage() 0 13 3
A testJsonSerializeWithEnabledTrue() 0 7 1
A testJsonSerializeWithEnabledFalseAndDefaultExpansion() 0 8 1
A testConstructorWithAllParameters() 0 9 1
A testImplementsJsonSerializable() 0 5 1
A testJsonSerializeWithBothNonDefaults() 0 10 1
A testJsonSerializeWithEnabledTrueAndDefaultExpansion() 0 9 1
A testJsonSerializeWithEnabledFalse() 0 7 1
A testJsonSerializeWithDefaultExpansionPercentage() 0 7 1
A testJsonSerializeWithDefaultValues() 0 8 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\PseudoLocalization;
8
use PHPUnit\Framework\TestCase;
9
10
class PseudoLocalizationTest extends TestCase
11
{
12
    public function testConstructorWithAllParameters(): void
13
    {
14
        $enabled = true;
15
        $expansionPercentage = 50;
16
17
        $pseudoLocalization = new PseudoLocalization($enabled, $expansionPercentage);
18
19
        $this->assertTrue($pseudoLocalization->enabled);
20
        $this->assertSame($expansionPercentage, $pseudoLocalization->expansionPercentage);
21
    }
22
23
    public function testConstructorWithDefaultParameters(): void
24
    {
25
        $pseudoLocalization = new PseudoLocalization();
26
27
        $this->assertFalse($pseudoLocalization->enabled);
28
        $this->assertSame(30, $pseudoLocalization->expansionPercentage);
29
    }
30
31
    public function testJsonSerializeWithEnabledTrue(): void
32
    {
33
        $pseudoLocalization = new PseudoLocalization(true, 40);
34
        $result = $pseudoLocalization->jsonSerialize();
35
36
        $this->assertTrue($result['enabled']);
37
        $this->assertSame(40, $result['expansionPercentage']);
38
    }
39
40
    public function testJsonSerializeWithDefaultValues(): void
41
    {
42
        $pseudoLocalization = new PseudoLocalization();
43
        $result = $pseudoLocalization->jsonSerialize();
44
45
        $this->assertEmpty($result);
46
        $this->assertArrayNotHasKey('enabled', $result);
47
        $this->assertArrayNotHasKey('expansionPercentage', $result);
48
    }
49
50
    public function testJsonSerializeWithEnabledFalse(): void
51
    {
52
        $pseudoLocalization = new PseudoLocalization(false, 60);
53
        $result = $pseudoLocalization->jsonSerialize();
54
55
        $this->assertSame(60, $result['expansionPercentage']);
56
        $this->assertArrayNotHasKey('enabled', $result);
57
    }
58
59
    public function testJsonSerializeWithDefaultExpansionPercentage(): void
60
    {
61
        $pseudoLocalization = new PseudoLocalization(true, 30);
62
        $result = $pseudoLocalization->jsonSerialize();
63
64
        $this->assertTrue($result['enabled']);
65
        $this->assertArrayNotHasKey('expansionPercentage', $result);
66
    }
67
68
    public function testJsonSerializeWithNonDefaultExpansionPercentage(): void
69
    {
70
        $testCases = [0, 10, 25, 50, 75, 100, 150];
71
72
        foreach ($testCases as $percentage) {
73
            $pseudoLocalization = new PseudoLocalization(false, $percentage);
74
            $result = $pseudoLocalization->jsonSerialize();
75
76
            if ($percentage !== 30) {
77
                $this->assertArrayHasKey('expansionPercentage', $result);
78
                $this->assertSame($percentage, $result['expansionPercentage']);
79
            } else {
80
                $this->assertArrayNotHasKey('expansionPercentage', $result);
81
            }
82
        }
83
    }
84
85
    public function testJsonSerializeWithEnabledTrueAndDefaultExpansion(): void
86
    {
87
        $pseudoLocalization = new PseudoLocalization(true);
88
        $result = $pseudoLocalization->jsonSerialize();
89
90
        $this->assertCount(1, $result);
91
        $this->assertArrayHasKey('enabled', $result);
92
        $this->assertTrue($result['enabled']);
93
        $this->assertArrayNotHasKey('expansionPercentage', $result);
94
    }
95
96
    public function testJsonSerializeWithEnabledFalseAndDefaultExpansion(): void
97
    {
98
        $pseudoLocalization = new PseudoLocalization(false);
99
        $result = $pseudoLocalization->jsonSerialize();
100
101
        $this->assertEmpty($result);
102
        $this->assertArrayNotHasKey('enabled', $result);
103
        $this->assertArrayNotHasKey('expansionPercentage', $result);
104
    }
105
106
    public function testJsonSerializeWithBothNonDefaults(): void
107
    {
108
        $pseudoLocalization = new PseudoLocalization(true, 75);
109
        $result = $pseudoLocalization->jsonSerialize();
110
111
        $this->assertCount(2, $result);
112
        $this->assertArrayHasKey('enabled', $result);
113
        $this->assertArrayHasKey('expansionPercentage', $result);
114
        $this->assertTrue($result['enabled']);
115
        $this->assertSame(75, $result['expansionPercentage']);
116
    }
117
118
    public function testJsonSerializeWithZeroExpansionPercentage(): void
119
    {
120
        $pseudoLocalization = new PseudoLocalization(true, 0);
121
        $result = $pseudoLocalization->jsonSerialize();
122
123
        $this->assertTrue($result['enabled']);
124
        $this->assertSame(0, $result['expansionPercentage']);
125
    }
126
127
    public function testImplementsJsonSerializable(): void
128
    {
129
        $pseudoLocalization = new PseudoLocalization();
130
131
        $this->assertInstanceOf(\JsonSerializable::class, $pseudoLocalization);
132
    }
133
}
134