Skip to content

Commit e325cdd

Browse files
Merge branch '5.4' into 6.2
* 5.4: [Console] Fix computing column width containing multibyte chars [Messenger] Fix deprecation layer of RedeliveryStamp [Mime] Form field values with integer keys not resolved correctly [Messenger] [Redis] Fixed problem where worker stops handling messages on first empty message [PHPUnitBridge] Fix PHPUnit 10.1 compatibility [VarDumper] Make the server TCP connection sync [Messenger] Fix warning message on failed messenger show command [Mailer] [Mailjet] Use body MessageID instead of X-MJ-Request-GUID [HttpFoundation] Fix BinaryFileResponse [Form] fix merge [HttpFoundation] Fix memory limit problems in BinaryFileResponse [PropertyAccess] Readonly properties must have no PropertyWriteInfo [Form] Cast choices value callback result to string [Serializer] Unexpected value should throw UnexpectedValueException [ErrorHandler] Don't throw deprecations for HttplugClient [Serializer] Fix denormalization of object with typed constructor arg (not castable) and with COLLECT_DENORMALIZATION_ERRORS Avoid leading .. for temporary files from Filesystem recursive remove
2 parents 751efa8 + ebdc48d commit e325cdd

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

ChoiceList/Loader/AbstractChoiceLoader.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public function loadValuesForChoices(array $choices, callable $value = null): ar
4646

4747
if ($value) {
4848
// if a value callback exists, use it
49-
return array_map($value, $choices);
49+
return array_map(fn ($item) => (string) $value($item), $choices);
5050
}
5151

5252
return $this->doLoadValuesForChoices($choices);

Tests/ChoiceList/Loader/CallbackChoiceLoaderTest.php

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,8 @@ class CallbackChoiceLoaderTest extends TestCase
4848

4949
public static function setUpBeforeClass(): void
5050
{
51-
self::$loader = new CallbackChoiceLoader(function () {
52-
return self::$choices;
53-
});
54-
self::$value = function ($choice) {
55-
return $choice->value ?? null;
56-
};
51+
self::$loader = new CallbackChoiceLoader(fn () => self::$choices);
52+
self::$value = fn ($choice) => $choice->value ?? null;
5753
self::$choices = [
5854
(object) ['value' => 'choice_one'],
5955
(object) ['value' => 'choice_two'],
@@ -90,6 +86,18 @@ public function testLoadChoicesForValuesLoadsChoiceListOnFirstCall()
9086
);
9187
}
9288

89+
public function testLoadValuesForChoicesCastsCallbackItemsToString()
90+
{
91+
$choices = [
92+
(object) ['id' => 2],
93+
(object) ['id' => 3],
94+
];
95+
96+
$value = fn ($item) => $item->id;
97+
98+
$this->assertSame(['2', '3'], self::$loader->loadValuesForChoices($choices, $value));
99+
}
100+
93101
public function testLoadValuesForChoicesLoadsChoiceListOnFirstCall()
94102
{
95103
$this->assertSame(

0 commit comments

Comments
 (0)