Skip to content

Commit b1e4b0f

Browse files
committed
Add extra test to show the reindexing
Passing the static function feels ugly so I decided to duplicate some of the code.
1 parent 5e9ace0 commit b1e4b0f

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

webapp/tests/Unit/Utils/UtilsTest.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -943,4 +943,26 @@ public function testReindex(): void
943943
$doubled = static fn($item) => $item * 2;
944944
self::assertEquals($expectedOutput, Utils::reindex($input, $doubled));
945945
}
946+
947+
/**
948+
* Test that reindexing an array works on arrays with key=>value
949+
*/
950+
public function testReindexKeyValue(): void
951+
{
952+
$input = ['a' => 10, 'b' => 5];
953+
$expectedOutput = [101030 => 10, 5515 => 5];
954+
$tripled = static fn($item) => strval($item) . strval($item) . strval($item * 3);
955+
self::assertEquals($expectedOutput, Utils::reindex($input, $tripled));
956+
}
957+
958+
/**
959+
* Test that reindexing an array works on arrays with key=>value and string values
960+
*/
961+
public function testReindexKeyValueString(): void
962+
{
963+
$input = ['a' => 'A', 'b' => 'B'];
964+
$expectedOutput = ['AA' => 'A', 'BB' => 'B'];
965+
$stringDouble = static fn($item) => strval($item) . strval($item);
966+
self::assertEquals($expectedOutput, Utils::reindex($input, $stringDouble));
967+
}
946968
}

0 commit comments

Comments
 (0)