From 2a96c5e06b2277cd7b5c9ee8e87a4ef2805afb40 Mon Sep 17 00:00:00 2001 From: Ihor Sviziev Date: Fri, 12 Nov 2021 09:50:16 +0200 Subject: [PATCH] Fix adding an option with label '0' Apply suggestions from code review --- .../Magento/Eav/Model/Entity/Attribute/OptionManagement.php | 4 ++-- .../Unit/Model/Entity/Attribute/OptionManagementTest.php | 6 ++++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/app/code/Magento/Eav/Model/Entity/Attribute/OptionManagement.php b/app/code/Magento/Eav/Model/Entity/Attribute/OptionManagement.php index 1a5cd9b19f251..ecee1c6ab6361 100644 --- a/app/code/Magento/Eav/Model/Entity/Attribute/OptionManagement.php +++ b/app/code/Magento/Eav/Model/Entity/Attribute/OptionManagement.php @@ -60,7 +60,7 @@ public function add($entityType, $attributeCode, $option) { $attribute = $this->loadAttribute($entityType, (string)$attributeCode); - $label = trim((string) $option->getLabel()); + $label = trim((string)$option->getLabel()); if ($label === '') { throw new InputException(__('The attribute option label is empty. Enter the value and try again.')); } @@ -93,7 +93,7 @@ public function update( if (empty($optionId)) { throw new InputException(__('The option id is empty. Enter the value and try again.')); } - $label = trim((string) $option->getLabel()); + $label = trim((string)$option->getLabel()); if ($label === '') { throw new InputException(__('The attribute option label is empty. Enter the value and try again.')); } diff --git a/app/code/Magento/Eav/Test/Unit/Model/Entity/Attribute/OptionManagementTest.php b/app/code/Magento/Eav/Test/Unit/Model/Entity/Attribute/OptionManagementTest.php index 998c9f61ef308..7b554a19fc281 100644 --- a/app/code/Magento/Eav/Test/Unit/Model/Entity/Attribute/OptionManagementTest.php +++ b/app/code/Magento/Eav/Test/Unit/Model/Entity/Attribute/OptionManagementTest.php @@ -61,9 +61,10 @@ protected function setUp(): void /** * Test to add attribute option * + * @param string $label * @dataProvider optionLabelDataProvider */ - public function testAdd($label) + public function testAdd(string $label): void { $entityType = 42; $storeId = 4; @@ -232,9 +233,10 @@ public function testAddWithCannotSaveException() /** * Test to update attribute option * + * @param string $label * @dataProvider optionLabelDataProvider */ - public function testUpdate($label) + public function testUpdate(string $label): void { $entityType = Product::ENTITY; $storeId = 4;