Skip to content

Commit 334f559

Browse files
committed
MAGE-1383 Add data provider for more scenarios
1 parent 14caa06 commit 334f559

File tree

1 file changed

+105
-15
lines changed

1 file changed

+105
-15
lines changed

Test/Unit/Helper/ArrayDeduplicatorTest.php

Lines changed: 105 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,109 @@ protected function setUp(): void
1414
$this->deduplicator = new ArrayDeduplicator();
1515
}
1616

17-
public function testDedupeArrayOfArraysRemovesExactDuplicates(): void
17+
public static function dedupeArrayOfArraysProvider(): array
1818
{
19-
$data = [
20-
['a' => 1, 'b' => 2],
21-
['a' => 1, 'b' => 2], // duplicate
22-
['a' => 2, 'b' => 3],
19+
return [
20+
'empty array' => [
21+
'input' => [],
22+
'expectedCount' => 0,
23+
'expectedItems' => []
24+
],
25+
'no duplicates' => [
26+
'input' => [
27+
['a' => 1, 'b' => 2],
28+
['a' => 2, 'b' => 3],
29+
['a' => 3, 'b' => 4]
30+
],
31+
'expectedCount' => 3,
32+
'expectedItems' => [
33+
['a' => 1, 'b' => 2],
34+
['a' => 2, 'b' => 3],
35+
['a' => 3, 'b' => 4]
36+
]
37+
],
38+
'exact duplicates' => [
39+
'input' => [
40+
['a' => 1, 'b' => 2],
41+
['a' => 1, 'b' => 2], // duplicate
42+
['a' => 2, 'b' => 3]
43+
],
44+
'expectedCount' => 2,
45+
'expectedItems' => [
46+
['a' => 1, 'b' => 2],
47+
['a' => 2, 'b' => 3]
48+
]
49+
],
50+
'multiple duplicates' => [
51+
'input' => [
52+
['id' => 1, 'name' => 'test'],
53+
['id' => 2, 'name' => 'test2'],
54+
['id' => 1, 'name' => 'test'], // duplicate
55+
['id' => 3, 'name' => 'test3'],
56+
['id' => 2, 'name' => 'test2'] // duplicate
57+
],
58+
'expectedCount' => 3,
59+
'expectedItems' => [
60+
['id' => 1, 'name' => 'test'],
61+
['id' => 2, 'name' => 'test2'],
62+
['id' => 3, 'name' => 'test3']
63+
]
64+
],
65+
'duplicate synonyms' => [
66+
'input' => [
67+
['gray', 'grey'],
68+
['trousers', 'pants'],
69+
['ipad', 'tablet'],
70+
['caulk', 'caulking'],
71+
['trousers', 'pants'], // duplicate
72+
['molding', 'moldings', 'moulding', 'mouldings'],
73+
['trash', 'garbage'],
74+
['molding', 'moldings', 'moulding', 'mouldings'], // duplicate
75+
],
76+
'expectedCount' => 6,
77+
'expectedItems' => [
78+
['gray', 'grey'],
79+
['trousers', 'pants'],
80+
['ipad', 'tablet'],
81+
['caulk', 'caulking'],
82+
['molding', 'moldings', 'moulding', 'mouldings'],
83+
['trash', 'garbage'],
84+
]
85+
],
86+
'duplicate alt corrections' => [
87+
'input' => [
88+
[ 'word' => 'trousers', 'nbTypos' => 1, 'correction' => 'pants' ],
89+
[ 'word' => 'rod', 'nbTypos' => 1, 'correction' => 'bar' ],
90+
[ 'word' => 'bell', 'nbTypos' => 1, 'correction' => 'buzzer' ],
91+
[ 'word' => 'rod', 'nbTypos' => 1, 'correction' => 'bar' ], // duplicate
92+
[ 'word' => 'blind', 'nbTypos' => 1, 'correction' => 'shade' ],
93+
[ 'word' => 'blind', 'nbTypos' => 2, 'correction' => 'shade' ], // not a duplicate
94+
[ 'word' => 'trousers', 'nbTypos' => 1, 'correction' => 'pants' ], // duplicate
95+
],
96+
'expectedCount' => 5,
97+
'expectedItems' => [
98+
[ 'word' => 'trousers', 'nbTypos' => 1, 'correction' => 'pants' ],
99+
[ 'word' => 'rod', 'nbTypos' => 1, 'correction' => 'bar' ],
100+
[ 'word' => 'bell', 'nbTypos' => 1, 'correction' => 'buzzer' ],
101+
[ 'word' => 'blind', 'nbTypos' => 1, 'correction' => 'shade' ],
102+
[ 'word' => 'blind', 'nbTypos' => 2, 'correction' => 'shade' ],
103+
]
104+
]
23105
];
106+
}
24107

25-
$result = $this->deduplicator->dedupeArrayOfArrays($data);
108+
/**
109+
* @dataProvider dedupeArrayOfArraysProvider
110+
*/
111+
public function testDedupeArrayOfArrays(array $input, int $expectedCount, array $expectedItems): void
112+
{
113+
$result = $this->deduplicator->dedupeArrayOfArrays($input);
114+
115+
$this->assertCount($expectedCount, $result);
26116

27-
$this->assertCount(2, $result);
28-
$this->assertContains(['a' => 1, 'b' => 2], $result);
29-
$this->assertContains(['a' => 2, 'b' => 3], $result);
117+
foreach ($expectedItems as $expectedItem) {
118+
$this->assertContains($expectedItem, $result);
119+
}
30120
}
31121

32122
public function testDedupeArrayOfArraysKeepsOrderOfFirstOccurrences(): void
@@ -46,14 +136,14 @@ public function testDedupeSpecificSettingsOnlyProcessesRequestedSettings(): void
46136
{
47137
$settings = [
48138
'synonyms' => [
49-
['word' => 'foo'],
50-
['word' => 'foo'],
139+
['red' => 'rouge'],
140+
['red' => 'rouge'],
51141
],
52142
'altCorrections' => [
53-
['word' => 'bar'],
143+
[ 'word' => 'bell', 'nbTypos' => 1, 'correction' => 'buzzer' ],
54144
],
55-
'placeholders' => [
56-
['word' => 'baz'],
145+
'placeholder' => [
146+
['foo' => 'bar'],
57147
],
58148
];
59149

@@ -72,7 +162,7 @@ public function testDedupeSpecificSettingsOnlyProcessesRequestedSettings(): void
72162
public function testDedupeSpecificSettingsHandlesMissingKeys(): void
73163
{
74164
$settings = [
75-
'synonyms' => [['w' => 'x']],
165+
'synonyms' => [['red', 'rouge']],
76166
];
77167

78168
$result = $this->deduplicator->dedupeSpecificSettings(

0 commit comments

Comments
 (0)