|
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\Value; |
|
8
|
|
|
use PHPUnit\Framework\TestCase; |
|
9
|
|
|
|
|
10
|
|
|
class ValueTest extends TestCase |
|
11
|
|
|
{ |
|
12
|
|
|
public function testConstructorWithAllParameters(): void |
|
13
|
|
|
{ |
|
14
|
|
|
$property = 'opacity'; |
|
15
|
|
|
$to = 1.0; |
|
16
|
|
|
$from = 0.5; |
|
17
|
|
|
|
|
18
|
|
|
$value = new Value($property, $to, $from); |
|
19
|
|
|
|
|
20
|
|
|
$this->assertSame($property, $value->property); |
|
21
|
|
|
$this->assertSame($to, $value->to); |
|
22
|
|
|
$this->assertSame($from, $value->from); |
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
|
|
public function testConstructorWithDefaultFrom(): void |
|
26
|
|
|
{ |
|
27
|
|
|
$property = 'translateX'; |
|
28
|
|
|
$to = 100; |
|
29
|
|
|
|
|
30
|
|
|
$value = new Value($property, $to); |
|
31
|
|
|
|
|
32
|
|
|
$this->assertSame($property, $value->property); |
|
33
|
|
|
$this->assertSame($to, $value->to); |
|
34
|
|
|
$this->assertNull($value->from); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
public function testConstructorWithIntegerValues(): void |
|
38
|
|
|
{ |
|
39
|
|
|
$value = new Value('width', 200, 150); |
|
40
|
|
|
|
|
41
|
|
|
$this->assertSame('width', $value->property); |
|
42
|
|
|
$this->assertSame(200, $value->to); |
|
43
|
|
|
$this->assertSame(150, $value->from); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
public function testConstructorWithFloatValues(): void |
|
47
|
|
|
{ |
|
48
|
|
|
$value = new Value('scale', 1.5, 0.8); |
|
49
|
|
|
|
|
50
|
|
|
$this->assertSame('scale', $value->property); |
|
51
|
|
|
$this->assertSame(1.5, $value->to); |
|
52
|
|
|
$this->assertSame(0.8, $value->from); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
public function testConstructorWithMixedNumericTypes(): void |
|
56
|
|
|
{ |
|
57
|
|
|
$value = new Value('rotation', 90.0, 45); |
|
58
|
|
|
|
|
59
|
|
|
$this->assertSame('rotation', $value->property); |
|
60
|
|
|
$this->assertSame(90.0, $value->to); |
|
61
|
|
|
$this->assertSame(45, $value->from); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
public function testJsonSerializeWithAllProperties(): void |
|
65
|
|
|
{ |
|
66
|
|
|
$value = new Value('height', 300, 100); |
|
67
|
|
|
$result = $value->jsonSerialize(); |
|
68
|
|
|
|
|
69
|
|
|
$this->assertSame('height', $result['property']); |
|
70
|
|
|
$this->assertSame(100, $result['from']); |
|
71
|
|
|
$this->assertSame(300, $result['to']); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
public function testJsonSerializeWithoutFrom(): void |
|
75
|
|
|
{ |
|
76
|
|
|
$value = new Value('opacity', 0.0); |
|
77
|
|
|
$result = $value->jsonSerialize(); |
|
78
|
|
|
|
|
79
|
|
|
$this->assertSame('opacity', $result['property']); |
|
80
|
|
|
$this->assertSame(0.0, $result['to']); |
|
81
|
|
|
$this->assertArrayNotHasKey('from', $result); |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
public function testJsonSerializeWithNullFrom(): void |
|
85
|
|
|
{ |
|
86
|
|
|
$value = new Value('translateY', 50, null); |
|
87
|
|
|
$result = $value->jsonSerialize(); |
|
88
|
|
|
|
|
89
|
|
|
$this->assertSame('translateY', $result['property']); |
|
90
|
|
|
$this->assertSame(50, $result['to']); |
|
91
|
|
|
$this->assertArrayNotHasKey('from', $result); |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
public function testJsonSerializePropertyOrder(): void |
|
95
|
|
|
{ |
|
96
|
|
|
$value = new Value('scaleX', 2.0, 1.0); |
|
97
|
|
|
$result = $value->jsonSerialize(); |
|
98
|
|
|
|
|
99
|
|
|
$keys = array_keys($result); |
|
100
|
|
|
$this->assertSame('property', $keys[0]); |
|
101
|
|
|
$this->assertSame('from', $keys[1]); |
|
102
|
|
|
$this->assertSame('to', $keys[2]); |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
public function testJsonSerializeWithZeroValues(): void |
|
106
|
|
|
{ |
|
107
|
|
|
$value = new Value('margin', 0, 0); |
|
108
|
|
|
$result = $value->jsonSerialize(); |
|
109
|
|
|
|
|
110
|
|
|
$this->assertSame('margin', $result['property']); |
|
111
|
|
|
$this->assertSame(0, $result['from']); |
|
112
|
|
|
$this->assertSame(0, $result['to']); |
|
113
|
|
|
} |
|
114
|
|
|
|
|
115
|
|
|
public function testJsonSerializeWithNegativeValues(): void |
|
116
|
|
|
{ |
|
117
|
|
|
$value = new Value('translateX', -100, -50); |
|
118
|
|
|
$result = $value->jsonSerialize(); |
|
119
|
|
|
|
|
120
|
|
|
$this->assertSame('translateX', $result['property']); |
|
121
|
|
|
$this->assertSame(-50, $result['from']); |
|
122
|
|
|
$this->assertSame(-100, $result['to']); |
|
123
|
|
|
} |
|
124
|
|
|
|
|
125
|
|
|
public function testJsonSerializeWithFloatPrecision(): void |
|
126
|
|
|
{ |
|
127
|
|
|
$value = new Value('opacity', 0.123456, 0.987654); |
|
128
|
|
|
$result = $value->jsonSerialize(); |
|
129
|
|
|
|
|
130
|
|
|
$this->assertSame('opacity', $result['property']); |
|
131
|
|
|
$this->assertSame(0.987654, $result['from']); |
|
132
|
|
|
$this->assertSame(0.123456, $result['to']); |
|
133
|
|
|
} |
|
134
|
|
|
|
|
135
|
|
|
public function testImplementsJsonSerializable(): void |
|
136
|
|
|
{ |
|
137
|
|
|
$value = new Value('property', 1); |
|
138
|
|
|
|
|
139
|
|
|
$this->assertInstanceOf(\JsonSerializable::class, $value); |
|
140
|
|
|
} |
|
141
|
|
|
} |
|
142
|
|
|
|