From 5d5cb9d620a9c9e5b162260d3c5b683760b78a6c Mon Sep 17 00:00:00 2001 From: Vova Yatsyuk Date: Fri, 18 Aug 2017 12:11:14 +0300 Subject: [PATCH 1/5] Always return a string. Even if array was empty. --- app/code/Magento/Customer/Model/Address/AbstractAddress.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/code/Magento/Customer/Model/Address/AbstractAddress.php b/app/code/Magento/Customer/Model/Address/AbstractAddress.php index 9eb14a20144ce..495f4cfa461f5 100644 --- a/app/code/Magento/Customer/Model/Address/AbstractAddress.php +++ b/app/code/Magento/Customer/Model/Address/AbstractAddress.php @@ -308,7 +308,11 @@ protected function _implodeArrayField(array $data) */ protected function _implodeArrayValues($value) { - if (is_array($value) && count($value)) { + if (is_array($value)) { + if (!count($value)) { + return ''; + } + $isScalar = false; foreach ($value as $val) { if (is_scalar($val)) { From 77a45a8ad90d6380d820525151e4fd1f0151e917 Mon Sep 17 00:00:00 2001 From: Vova Yatsyuk Date: Fri, 18 Aug 2017 12:12:06 +0300 Subject: [PATCH 2/5] Convert array of street lines to the string even if it was empty --- app/code/Magento/Customer/Model/Address/AbstractAddress.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/Customer/Model/Address/AbstractAddress.php b/app/code/Magento/Customer/Model/Address/AbstractAddress.php index 495f4cfa461f5..03b6f6e431732 100644 --- a/app/code/Magento/Customer/Model/Address/AbstractAddress.php +++ b/app/code/Magento/Customer/Model/Address/AbstractAddress.php @@ -268,7 +268,7 @@ public function setData($key, $value = null) { if (is_array($key)) { $key = $this->_implodeArrayField($key); - } elseif (is_array($value) && !empty($value) && $this->isAddressMultilineAttribute($key)) { + } elseif (is_array($value) && $this->isAddressMultilineAttribute($key)) { $value = $this->_implodeArrayValues($value); } return parent::setData($key, $value); From 7ac1872ae6b57c02da2de5e880c8a750653f981d Mon Sep 17 00:00:00 2001 From: Vova Yatsyuk Date: Wed, 23 Aug 2017 15:39:06 +0300 Subject: [PATCH 3/5] Fixed failed unit test --- .../Magento/Quote/Test/Unit/Model/Quote/AddressTest.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/app/code/Magento/Quote/Test/Unit/Model/Quote/AddressTest.php b/app/code/Magento/Quote/Test/Unit/Model/Quote/AddressTest.php index 1557fe420be02..95efd917fa09c 100644 --- a/app/code/Magento/Quote/Test/Unit/Model/Quote/AddressTest.php +++ b/app/code/Magento/Quote/Test/Unit/Model/Quote/AddressTest.php @@ -47,6 +47,11 @@ class AddressTest extends \PHPUnit\Framework\TestCase */ private $quote; + /** + * @var \Magento\Quote\Model\Quote\Address\CustomAttributeListInterface | \PHPUnit_Framework_MockObject_MockObject + */ + private $attributeList; + /** * @var \Magento\Framework\App\Config | \PHPUnit_Framework_MockObject_MockObject */ @@ -165,9 +170,13 @@ protected function setUp() ->disableOriginalConstructor() ->getMock(); + $this->attributeList = $this->createMock(\Magento\Quote\Model\Quote\Address\CustomAttributeListInterface::class); + $this->attributeList->method('getAttributes')->willReturn([]); + $this->address = $objectManager->getObject( \Magento\Quote\Model\Quote\Address::class, [ + 'attributeList' => $this->attributeList, 'scopeConfig' => $this->scopeConfig, 'serializer' => $this->serializer, 'storeManager' => $this->storeManager, From 6200e6962777d9db5d26c9c9d40949f0f43b089b Mon Sep 17 00:00:00 2001 From: Vova Yatsyuk Date: Wed, 23 Aug 2017 16:04:40 +0300 Subject: [PATCH 4/5] Added test to check that street array will be converted to the string --- .../Test/Unit/Model/Address/AbstractAddressTest.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/app/code/Magento/Customer/Test/Unit/Model/Address/AbstractAddressTest.php b/app/code/Magento/Customer/Test/Unit/Model/Address/AbstractAddressTest.php index 23b8b38c962b9..2eef9a44cab74 100644 --- a/app/code/Magento/Customer/Test/Unit/Model/Address/AbstractAddressTest.php +++ b/app/code/Magento/Customer/Test/Unit/Model/Address/AbstractAddressTest.php @@ -366,6 +366,15 @@ public function testGetStreetFullAlwaysReturnsString($expectedResult, $street) $this->assertEquals($expectedResult, $this->model->getStreetFull()); } + /** + * @dataProvider getStreetFullDataProvider + */ + public function testSetDataStreetAlwaysConvertedToString($expectedResult, $street) + { + $this->model->setData('street', $street); + $this->assertEquals($expectedResult, $this->model->getData('street')); + } + /** * @return array */ From ce0b86b34c782ff55fa455e12fba4c7e64093529 Mon Sep 17 00:00:00 2001 From: Vova Yatsyuk Date: Fri, 25 Aug 2017 18:11:42 +0300 Subject: [PATCH 5/5] Supress failed static test (PHPMD.TooManyFields) --- app/code/Magento/Quote/Test/Unit/Model/Quote/AddressTest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/app/code/Magento/Quote/Test/Unit/Model/Quote/AddressTest.php b/app/code/Magento/Quote/Test/Unit/Model/Quote/AddressTest.php index 95efd917fa09c..5cb255515535f 100644 --- a/app/code/Magento/Quote/Test/Unit/Model/Quote/AddressTest.php +++ b/app/code/Magento/Quote/Test/Unit/Model/Quote/AddressTest.php @@ -33,6 +33,7 @@ * Test class for sales quote address model * * @see \Magento\Quote\Model\Quote\Address + * @SuppressWarnings(PHPMD.TooManyFields) * @SuppressWarnings(PHPMD.CouplingBetweenObjects) */ class AddressTest extends \PHPUnit\Framework\TestCase