From e650796a9670699b75b824746e90dc047b8610da Mon Sep 17 00:00:00 2001 From: Fabian Schmengler Date: Thu, 8 Mar 2018 10:10:52 +0100 Subject: [PATCH 1/2] Change variable names in unit tests to express their role in the test --- .../Catalog/Test/Unit/Model/CategoryTest.php | 25 +++++++++++-------- .../Catalog/Test/Unit/Model/ProductTest.php | 23 +++++++++-------- 2 files changed, 27 insertions(+), 21 deletions(-) diff --git a/app/code/Magento/Catalog/Test/Unit/Model/CategoryTest.php b/app/code/Magento/Catalog/Test/Unit/Model/CategoryTest.php index 9f5f3313c6859..40be105443576 100644 --- a/app/code/Magento/Catalog/Test/Unit/Model/CategoryTest.php +++ b/app/code/Magento/Catalog/Test/Unit/Model/CategoryTest.php @@ -441,33 +441,36 @@ public function testReindexFlatDisabled( public function testGetCustomAttributes() { - $nameAttributeCode = 'name'; - $descriptionAttributeCode = 'description'; + $interfaceAttributeCode = 'name'; + $customAttributeCode = 'description'; + $initialCustomAttributeValue = 'initial description'; + $newCustomAttributeValue = 'new description'; + $this->getCustomAttributeCodes->expects($this->exactly(3)) ->method('execute') - ->willReturn([$descriptionAttributeCode]); - $this->category->setData($nameAttributeCode, "sub"); + ->willReturn([$customAttributeCode]); + $this->category->setData($interfaceAttributeCode, "sub"); //The description attribute is not set, expect empty custom attribute array $this->assertEquals([], $this->category->getCustomAttributes()); //Set the description attribute; - $this->category->setData($descriptionAttributeCode, "description"); + $this->category->setData($customAttributeCode, $initialCustomAttributeValue); $attributeValue = new \Magento\Framework\Api\AttributeValue(); $attributeValue2 = new \Magento\Framework\Api\AttributeValue(); $this->attributeValueFactory->expects($this->exactly(2))->method('create') ->willReturnOnConsecutiveCalls($attributeValue, $attributeValue2); $this->assertEquals(1, count($this->category->getCustomAttributes())); - $this->assertNotNull($this->category->getCustomAttribute($descriptionAttributeCode)); - $this->assertEquals("description", $this->category->getCustomAttribute($descriptionAttributeCode)->getValue()); + $this->assertNotNull($this->category->getCustomAttribute($customAttributeCode)); + $this->assertEquals($initialCustomAttributeValue, $this->category->getCustomAttribute($customAttributeCode)->getValue()); //Change the attribute value, should reflect in getCustomAttribute - $this->category->setData($descriptionAttributeCode, "new description"); + $this->category->setData($customAttributeCode, $newCustomAttributeValue); $this->assertEquals(1, count($this->category->getCustomAttributes())); - $this->assertNotNull($this->category->getCustomAttribute($descriptionAttributeCode)); + $this->assertNotNull($this->category->getCustomAttribute($customAttributeCode)); $this->assertEquals( - "new description", - $this->category->getCustomAttribute($descriptionAttributeCode)->getValue() + $newCustomAttributeValue, + $this->category->getCustomAttribute($customAttributeCode)->getValue() ); } diff --git a/app/code/Magento/Catalog/Test/Unit/Model/ProductTest.php b/app/code/Magento/Catalog/Test/Unit/Model/ProductTest.php index 74a71a2828e1d..bfa81b3395bd1 100644 --- a/app/code/Magento/Catalog/Test/Unit/Model/ProductTest.php +++ b/app/code/Magento/Catalog/Test/Unit/Model/ProductTest.php @@ -1278,31 +1278,34 @@ public function testGetMediaGalleryImagesMerging() public function testGetCustomAttributes() { - $priceCode = 'price'; - $colorAttributeCode = 'color'; + $interfaceAttributeCode = 'price'; + $customAttributeCode = 'color'; + $initialCustomAttributeValue = 'red'; + $newCustomAttributeValue = 'blue'; + $this->getCustomAttributeCodes->expects($this->exactly(3)) ->method('execute') - ->willReturn([$colorAttributeCode]); - $this->model->setData($priceCode, 10); + ->willReturn([$customAttributeCode]); + $this->model->setData($interfaceAttributeCode, 10); //The color attribute is not set, expect empty custom attribute array $this->assertEquals([], $this->model->getCustomAttributes()); //Set the color attribute; - $this->model->setData($colorAttributeCode, "red"); + $this->model->setData($customAttributeCode, $initialCustomAttributeValue); $attributeValue = new \Magento\Framework\Api\AttributeValue(); $attributeValue2 = new \Magento\Framework\Api\AttributeValue(); $this->attributeValueFactory->expects($this->exactly(2))->method('create') ->willReturnOnConsecutiveCalls($attributeValue, $attributeValue2); $this->assertEquals(1, count($this->model->getCustomAttributes())); - $this->assertNotNull($this->model->getCustomAttribute($colorAttributeCode)); - $this->assertEquals("red", $this->model->getCustomAttribute($colorAttributeCode)->getValue()); + $this->assertNotNull($this->model->getCustomAttribute($customAttributeCode)); + $this->assertEquals($initialCustomAttributeValue, $this->model->getCustomAttribute($customAttributeCode)->getValue()); //Change the attribute value, should reflect in getCustomAttribute - $this->model->setData($colorAttributeCode, "blue"); + $this->model->setData($customAttributeCode, $newCustomAttributeValue); $this->assertEquals(1, count($this->model->getCustomAttributes())); - $this->assertNotNull($this->model->getCustomAttribute($colorAttributeCode)); - $this->assertEquals("blue", $this->model->getCustomAttribute($colorAttributeCode)->getValue()); + $this->assertNotNull($this->model->getCustomAttribute($customAttributeCode)); + $this->assertEquals($newCustomAttributeValue, $this->model->getCustomAttribute($customAttributeCode)->getValue()); } /** From 0eb0482dcaaa4d26fb21edef766d6d9058c38b14 Mon Sep 17 00:00:00 2001 From: Stanislav Idolov Date: Thu, 8 Mar 2018 22:07:31 +0200 Subject: [PATCH 2/2] magento/magento2#14006 --- .../Magento/Catalog/Test/Unit/Model/CategoryTest.php | 5 ++++- .../Magento/Catalog/Test/Unit/Model/ProductTest.php | 10 ++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/app/code/Magento/Catalog/Test/Unit/Model/CategoryTest.php b/app/code/Magento/Catalog/Test/Unit/Model/CategoryTest.php index 40be105443576..51521db53312e 100644 --- a/app/code/Magento/Catalog/Test/Unit/Model/CategoryTest.php +++ b/app/code/Magento/Catalog/Test/Unit/Model/CategoryTest.php @@ -462,7 +462,10 @@ public function testGetCustomAttributes() ->willReturnOnConsecutiveCalls($attributeValue, $attributeValue2); $this->assertEquals(1, count($this->category->getCustomAttributes())); $this->assertNotNull($this->category->getCustomAttribute($customAttributeCode)); - $this->assertEquals($initialCustomAttributeValue, $this->category->getCustomAttribute($customAttributeCode)->getValue()); + $this->assertEquals( + $initialCustomAttributeValue, + $this->category->getCustomAttribute($customAttributeCode)->getValue() + ); //Change the attribute value, should reflect in getCustomAttribute $this->category->setData($customAttributeCode, $newCustomAttributeValue); diff --git a/app/code/Magento/Catalog/Test/Unit/Model/ProductTest.php b/app/code/Magento/Catalog/Test/Unit/Model/ProductTest.php index bfa81b3395bd1..1ba35dde7ad2f 100644 --- a/app/code/Magento/Catalog/Test/Unit/Model/ProductTest.php +++ b/app/code/Magento/Catalog/Test/Unit/Model/ProductTest.php @@ -1299,13 +1299,19 @@ public function testGetCustomAttributes() ->willReturnOnConsecutiveCalls($attributeValue, $attributeValue2); $this->assertEquals(1, count($this->model->getCustomAttributes())); $this->assertNotNull($this->model->getCustomAttribute($customAttributeCode)); - $this->assertEquals($initialCustomAttributeValue, $this->model->getCustomAttribute($customAttributeCode)->getValue()); + $this->assertEquals( + $initialCustomAttributeValue, + $this->model->getCustomAttribute($customAttributeCode)->getValue() + ); //Change the attribute value, should reflect in getCustomAttribute $this->model->setData($customAttributeCode, $newCustomAttributeValue); $this->assertEquals(1, count($this->model->getCustomAttributes())); $this->assertNotNull($this->model->getCustomAttribute($customAttributeCode)); - $this->assertEquals($newCustomAttributeValue, $this->model->getCustomAttribute($customAttributeCode)->getValue()); + $this->assertEquals( + $newCustomAttributeValue, + $this->model->getCustomAttribute($customAttributeCode)->getValue() + ); } /**