Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Tigrov committed Jan 29, 2025
1 parent 4883903 commit b405f17
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions tests/Db/Helper/DbArrayHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,38 @@ public function testIndexWithNonExistingIndexBy(): void

DbArrayHelper::index($rows, 'non-existing-key', ['key']);
}

public function testIndexWithArrangeBy(): void
{
$rows = [
['key' => 'value1'],
['key' => 'value2'],
];

set_error_handler(static function (int $errno, string $errstr) {
restore_error_handler();
throw new \Exception('E_WARNING: ' . $errstr, $errno);
}, E_WARNING);

$this->expectExceptionMessage('E_WARNING: Undefined array key "non-existing-key"');

DbArrayHelper::index($rows, null, ['non-existing-key']);
}

public function testIndexWithClosureIndexByAndArrangeBy(): void
{
$rows = [
['key' => 'value1'],
['key' => 'value2'],
];

$this->assertSame([
'value1' => [
'value1' => ['key' => 'value1'],
],
'value2' => [
'value2' => ['key' => 'value2'],
],
], DbArrayHelper::index($rows, fn ($row) => $row['key'], ['key']));
}
}

0 comments on commit b405f17

Please sign in to comment.