From 168dfd35853c706b49bde5c1af368e5faddd1ad4 Mon Sep 17 00:00:00 2001 From: Avikarsha Saha Date: Tue, 25 Jun 2024 20:17:52 +0530 Subject: [PATCH 1/2] cast string --- Entity/CustomField.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Entity/CustomField.php b/Entity/CustomField.php index d9beee6f5..d49bbef0f 100644 --- a/Entity/CustomField.php +++ b/Entity/CustomField.php @@ -578,7 +578,7 @@ public function valueToLabel(string $value): string throw new NotFoundException("Label was not found for value {$value}"); } - return $label; + return (string) $label; } /** From 2d6a6232abda65522956df45381eef297106df20 Mon Sep 17 00:00:00 2001 From: Avikarsha Saha Date: Wed, 26 Jun 2024 13:09:19 +0530 Subject: [PATCH 2/2] test --- Tests/Unit/Entity/CustomFieldTest.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/Tests/Unit/Entity/CustomFieldTest.php b/Tests/Unit/Entity/CustomFieldTest.php index cc44dd05d..40ee83a32 100644 --- a/Tests/Unit/Entity/CustomFieldTest.php +++ b/Tests/Unit/Entity/CustomFieldTest.php @@ -316,6 +316,22 @@ public function testValueToLabel(): void $this->assertSame('Option B', $customField->valueToLabel('option_b')); } + public function testValueToLabelWithInteger(): void + { + $customField = new CustomField(); + $optionB = new CustomFieldOption(); + $optionB->setLabel('1'); + $optionB->setValue('1'); + $customField->addOption($optionB); + $customField->setTypeObject( + new SelectType( + $this->createMock(TranslatorInterface::class), + $this->createMock(FilterOperatorProviderInterface::class) + ) + ); + $this->assertSame('1', $customField->valueToLabel('1')); + } + public function testValueToLabelIfOptionNotFound(): void { $customField = new CustomField();