1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace AHJ\ApprovalTests\Tests\Unit; |
6
|
|
|
|
7
|
|
|
use AHJ\ApprovalTests\ReceivedMap; |
8
|
|
|
use AHJ\ApprovalTests\Tests\Example\Item; |
9
|
|
|
use AHJ\ApprovalTests\Tests\Example\RandomObject; |
10
|
|
|
use AHJ\ApprovalTests\Tests\Example\YetAnotherRandomObject; |
11
|
|
|
use Generator; |
12
|
|
|
use PHPUnit\Framework\Assert; |
13
|
|
|
use PHPUnit\Framework\TestCase; |
14
|
|
|
|
15
|
|
|
final class ReceivedMapTest extends TestCase |
16
|
|
|
{ |
17
|
|
|
/** |
18
|
|
|
* @dataProvider provideTestInput |
19
|
|
|
*/ |
20
|
|
|
public function testCreate(array $input, $output, bool $plain, string $expected): void |
21
|
|
|
{ |
22
|
|
|
$actual = (new ReceivedMap())->create($input, $output, $plain); |
23
|
|
|
|
24
|
|
|
Assert::assertEquals($expected, $actual); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
public function provideTestInput(): Generator |
28
|
|
|
{ |
29
|
|
|
yield 'array foo' => [ |
30
|
|
|
'input' => [ |
31
|
|
|
['foo', 0, 1], |
32
|
|
|
], |
33
|
|
|
'output' => [ |
34
|
|
|
['foo', -1, 0], |
35
|
|
|
], |
36
|
|
|
'plain' => false, |
37
|
|
|
'expected' => '[foo, 0, 1] -> [foo, -1, 0]', |
38
|
|
|
]; |
39
|
|
|
|
40
|
|
|
yield 'empty input' => [ |
41
|
|
|
'input' => [], |
42
|
|
|
'output' => [ |
43
|
|
|
['foo', -1, 0], |
44
|
|
|
], |
45
|
|
|
'plain' => false, |
46
|
|
|
'expected' => '[foo, -1, 0]', |
47
|
|
|
]; |
48
|
|
|
|
49
|
|
|
yield 'object without __toString method' => [ |
50
|
|
|
'input' => [ |
51
|
|
|
new RandomObject('foo', 0, []), |
52
|
|
|
new RandomObject('foo', 10, []), |
53
|
|
|
], |
54
|
|
|
'output' => [ |
55
|
|
|
new RandomObject('bar', 10, []), |
56
|
|
|
new RandomObject('bar', 100, []), |
57
|
|
|
], |
58
|
|
|
'plain' => false, |
59
|
|
|
'expected' => '[foo, 0, []] -> [bar, 10, []] |
60
|
|
|
[foo, 10, []] -> [bar, 100, []]', |
61
|
|
|
]; |
62
|
|
|
|
63
|
|
|
yield 'object without input and formatting' => [ |
64
|
|
|
'input' => [ |
65
|
|
|
new RandomObject('foo', 0, []), |
66
|
|
|
new RandomObject('foo', 10, []), |
67
|
|
|
], |
68
|
|
|
'output' => [ |
69
|
|
|
new RandomObject('bar', 10, []), |
70
|
|
|
new RandomObject('bar', 100, []), |
71
|
|
|
], |
72
|
|
|
'plain' => true, |
73
|
|
|
'expected' => '[{"dirPath":"bar","fileNumber":10,"randomList":[]},{"dirPath":"bar","fileNumber":100,"randomList":[]}]', |
74
|
|
|
]; |
75
|
|
|
|
76
|
|
|
yield 'nested objects' => [ |
77
|
|
|
'input' => [ |
78
|
|
|
new YetAnotherRandomObject('foo', 0, new RandomObject('bar', 10, [])), |
79
|
|
|
new YetAnotherRandomObject('foo', 10, new RandomObject('bar', 100, [])), |
80
|
|
|
], |
81
|
|
|
'output' => [ |
82
|
|
|
new YetAnotherRandomObject('foo', 10, new RandomObject('bar', 60, [])), |
83
|
|
|
new YetAnotherRandomObject('foo', 100, new RandomObject('bar', 600, [])), |
84
|
|
|
], |
85
|
|
|
'plain' => false, |
86
|
|
|
'expected' => '[foo, 0, [bar, 10, []]] -> [foo, 10, [bar, 60, []]] |
87
|
|
|
[foo, 10, [bar, 100, []]] -> [foo, 100, [bar, 600, []]]', |
88
|
|
|
]; |
89
|
|
|
|
90
|
|
|
yield 'nested objects including arrays' => [ |
91
|
|
|
'input' => [ |
92
|
|
|
new YetAnotherRandomObject('foo', 0, new RandomObject('bar', 10, [1, 2, 'foo'])), |
93
|
|
|
new YetAnotherRandomObject('foo', 10, new RandomObject('bar', 100, [1, 2, 'foo'])), |
94
|
|
|
], |
95
|
|
|
'output' => [ |
96
|
|
|
new YetAnotherRandomObject('foo', 10, new RandomObject('bar', 60, [1, 2, 'foo'])), |
97
|
|
|
new YetAnotherRandomObject('foo', 100, new RandomObject('bar', 600, [1, 2, 'foo'])), |
98
|
|
|
], |
99
|
|
|
'plain' => false, |
100
|
|
|
'expected' => '[foo, 0, [bar, 10, [1, 2, foo]]] -> [foo, 10, [bar, 60, [1, 2, foo]]] |
101
|
|
|
[foo, 10, [bar, 100, [1, 2, foo]]] -> [foo, 100, [bar, 600, [1, 2, foo]]]', |
102
|
|
|
]; |
103
|
|
|
|
104
|
|
|
yield 'nested objects including arrays of arrays' => [ |
105
|
|
|
'input' => [ |
106
|
|
|
new YetAnotherRandomObject('foo', 0, new RandomObject('bar', 10, [1, 2, 'foo', [1, 3]])), |
107
|
|
|
new YetAnotherRandomObject('foo', 10, new RandomObject('bar', 100, [1, 2, 'foo', [1, 3]])), |
108
|
|
|
], |
109
|
|
|
'output' => [ |
110
|
|
|
new YetAnotherRandomObject('foo', 10, new RandomObject('bar', 60, [1, 2, 'foo', [1, 3]])), |
111
|
|
|
new YetAnotherRandomObject('foo', 100, new RandomObject('bar', 600, [1, 2, 'foo', [1, 3]])), |
112
|
|
|
], |
113
|
|
|
'plain' => false, |
114
|
|
|
'expected' => '[foo, 0, [bar, 10, [1, 2, foo, [1, 3]]]] -> [foo, 10, [bar, 60, [1, 2, foo, [1, 3]]]] |
115
|
|
|
[foo, 10, [bar, 100, [1, 2, foo, [1, 3]]]] -> [foo, 100, [bar, 600, [1, 2, foo, [1, 3]]]]', |
116
|
|
|
]; |
117
|
|
|
|
118
|
|
|
yield 'nested objects including arrays with objects' => [ |
119
|
|
|
'input' => [ |
120
|
|
|
new YetAnotherRandomObject('foo', 0, new RandomObject('bar', 10, [new YetAnotherRandomObject('bar', 1, new RandomObject('bar', 10, [1]))])), |
121
|
|
|
new YetAnotherRandomObject('foo', 10, new RandomObject('bar', 100, [new YetAnotherRandomObject('bar', 1, new RandomObject('bar', 10, [1]))])), |
122
|
|
|
], |
123
|
|
|
'output' => [ |
124
|
|
|
new YetAnotherRandomObject('foo', 10, new RandomObject('bar', 60, [new YetAnotherRandomObject('bar', 1, new RandomObject('bar', 10, [1]))])), |
125
|
|
|
new YetAnotherRandomObject('foo', 100, new RandomObject('bar', 600, [new YetAnotherRandomObject('bar', 1, new RandomObject('bar', 10, [1]))])), |
126
|
|
|
], |
127
|
|
|
'plain' => false, |
128
|
|
|
'expected' => '[foo, 0, [bar, 10, [[bar, 1, [bar, 10, [1]]]]]] -> [foo, 10, [bar, 60, [[bar, 1, [bar, 10, [1]]]]]] |
129
|
|
|
[foo, 10, [bar, 100, [[bar, 1, [bar, 10, [1]]]]]] -> [foo, 100, [bar, 600, [[bar, 1, [bar, 10, [1]]]]]]', |
130
|
|
|
]; |
131
|
|
|
|
132
|
|
|
yield 'nested arrays' => [ |
133
|
|
|
'input' => [ |
134
|
|
|
['foo', 0, 1, [100, 1000]], |
135
|
|
|
], |
136
|
|
|
'output' => [ |
137
|
|
|
['foo', -1, 0, [600, 6000]], |
138
|
|
|
], |
139
|
|
|
'plain' => false, |
140
|
|
|
'expected' => '[foo, 0, 1, [100, 1000]] -> [foo, -1, 0, [600, 6000]]', |
141
|
|
|
]; |
142
|
|
|
|
143
|
|
|
yield 'object with __toString method' => [ |
144
|
|
|
'input' => [ |
145
|
|
|
new Item('foo', 0, 1), |
146
|
|
|
], |
147
|
|
|
'output' => [ |
148
|
|
|
new Item('foo', -1, 0), |
149
|
|
|
], |
150
|
|
|
'plain' => false, |
151
|
|
|
'expected' => '[foo, 0, 1] -> [foo, -1, 0]', |
152
|
|
|
]; |
153
|
|
|
|
154
|
|
|
yield 'more objects with __toString method' => [ |
155
|
|
|
'input' => [ |
156
|
|
|
new Item('bar', 1, 1), |
157
|
|
|
new Item('bar', 1, 0), |
158
|
|
|
new Item('bar', 1, 100), |
159
|
|
|
], |
160
|
|
|
'output' => [ |
161
|
|
|
new Item('bar', -1, 0), |
162
|
|
|
new Item('bar', 1, 10), |
163
|
|
|
new Item('bar', -1, 50), |
164
|
|
|
], |
165
|
|
|
'plain' => false, |
166
|
|
|
'expected' => '[bar, 1, 1] -> [bar, -1, 0] |
167
|
|
|
[bar, 1, 0] -> [bar, 1, 10] |
168
|
|
|
[bar, 1, 100] -> [bar, -1, 50]', |
169
|
|
|
]; |
170
|
|
|
|
171
|
|
|
yield 'plain output' => [ |
172
|
|
|
'input' => [], |
173
|
|
|
'output' => '+--------------+-------------+--------+--------+------+-----+------------+---------+---------+---------+---------+---------+--------+-------+ |
174
|
|
|
| benchmark | subject | groups | params | revs | its | mem_peak | best | mean | mode | worst | stdev | rstdev | diff | |
175
|
|
|
+--------------+-------------+--------+--------+------+-----+------------+---------+---------+---------+---------+---------+--------+-------+ |
176
|
|
|
| HashingBench | benchMd5 | | [] | 1000 | 10 | 1,255,792b | 0.931μs | 0.979μs | 0.957μs | 1.153μs | 0.062μs | 6.37% | 1.00x | |
177
|
|
|
| HashingBench | benchSha1 | | [] | 1000 | 10 | 1,255,792b | 0.988μs | 1.015μs | 1.004μs | 1.079μs | 0.026μs | 2.57% | 1.04x | |
178
|
|
|
| HashingBench | benchSha256 | | [] | 1000 | 10 | 1,255,792b | 1.273μs | 1.413μs | 1.294μs | 1.994μs | 0.242μs | 17.16% | 1.44x | |
179
|
|
|
+--------------+-------------+--------+--------+------+-----+------------+---------+---------+---------+---------+---------+--------+-------+ |
180
|
|
|
', |
181
|
|
|
'plain' => true, |
182
|
|
|
'expected' => '+--------------+-------------+--------+--------+------+-----+------------+---------+---------+---------+---------+---------+--------+-------+ |
183
|
|
|
| benchmark | subject | groups | params | revs | its | mem_peak | best | mean | mode | worst | stdev | rstdev | diff | |
184
|
|
|
+--------------+-------------+--------+--------+------+-----+------------+---------+---------+---------+---------+---------+--------+-------+ |
185
|
|
|
| HashingBench | benchMd5 | | [] | 1000 | 10 | 1,255,792b | 0.931μs | 0.979μs | 0.957μs | 1.153μs | 0.062μs | 6.37% | 1.00x | |
186
|
|
|
| HashingBench | benchSha1 | | [] | 1000 | 10 | 1,255,792b | 0.988μs | 1.015μs | 1.004μs | 1.079μs | 0.026μs | 2.57% | 1.04x | |
187
|
|
|
| HashingBench | benchSha256 | | [] | 1000 | 10 | 1,255,792b | 1.273μs | 1.413μs | 1.294μs | 1.994μs | 0.242μs | 17.16% | 1.44x | |
188
|
|
|
+--------------+-------------+--------+--------+------+-----+------------+---------+---------+---------+---------+---------+--------+-------+ |
189
|
|
|
', |
190
|
|
|
]; |
191
|
|
|
} |
192
|
|
|
} |
193
|
|
|
|