-
-
Notifications
You must be signed in to change notification settings - Fork 180
fix: respect case preferences when grouping by callable #7563
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop-patch
Are you sure you want to change the base?
fix: respect case preferences when grouping by callable #7563
Conversation
@dweidner Can you add a unit test for this improvement, please? I can take care if you're not available. |
Sorry, it took me a while to find the time. I will add some tests today. Thank you for considering my pull request. |
Sorry for the noise. Was struggeling with the prettier configuration in VSCode. Should be ready now. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great 👍
Optional note: IMHO It's not a big deal, but in unit tests, counting the results of ->group()
to check how many results the grouping explicitly returns increases the accuracy of the unit test.
Was considering this as well, but was not sure whether this should be part of this particular unit test. |
What I mean is that the group size changes with sensitive and insensitive grouping. You do this with the key control. We can also make the unit test more meaningful by checking the group size. Something like that: public function testGroupByCallableCaseSensitive(): void
{
$collection = new Collection();
$collection->taylor = [
'name' => 'Taylor',
'genre' => 'Pop',
];
$collection->justin = [
'name' => 'Justin',
'genre' => 'Pop',
];
$collection->aubrey = [
'name' => 'Aubrey',
'genre' => 'Hip-Hop',
];
$collection->kayne = [
'name' => 'kayne',
'genre' => 'hip-hop',
];
$groupsCaseInsensitive = $collection->group(fn (array $item) => $item['genre'], true);
$this->assertCount(2, $groupsCaseInsensitive);
$this->assertTrue($groupsCaseInsensitive->has('pop'));
$this->assertTrue($groupsCaseInsensitive->has('hip-hop'));
$groupsCaseSensitive = $collection->group(fn (array $item) => $item['genre'], false);
$this->assertCount(3, $groupsCaseSensitive);
$this->assertTrue($groupsCaseSensitive->has('Pop'));
$this->assertTrue($groupsCaseSensitive->has('Hip-Hop'));
} |
That makes perfect sense. Thank you for clarifying. |
Changelog
🐛 Bug fixes
Keep original case intact when grouping a collection by callable. See issue #7562.