Skip to content

Commit e22de8e

Browse files
committed
Merge branch 'MAGETWO-56206-inconsistent-response-types' into MAGETWO-63731-Site-Map
2 parents 4bc6135 + 2fa55d1 commit e22de8e

File tree

9 files changed

+149
-89
lines changed

9 files changed

+149
-89
lines changed

app/code/Magento/Webapi/Test/Unit/Model/DataObjectProcessorTest.php

Lines changed: 0 additions & 74 deletions
This file was deleted.

dev/tests/api-functional/testsuite/Magento/Catalog/Api/ProductRepositoryInterfaceTest.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -344,8 +344,7 @@ public function testProductLinks()
344344
"link_type" => "related",
345345
"linked_product_sku" => "product_simple_500",
346346
"linked_product_type" => "simple",
347-
"position" => 0,
348-
"extension_attributes" => []
347+
"position" => 0
349348
];
350349
$productWithRelatedData = [
351350
ProductInterface::SKU => "product_simple_with_related_500",
@@ -373,8 +372,7 @@ public function testProductLinks()
373372
"link_type" => "upsell",
374373
"linked_product_sku" => "product_simple_500",
375374
"linked_product_type" => "simple",
376-
"position" => 0,
377-
"extension_attributes" => []
375+
"position" => 0
378376
];
379377
$productWithUpsellData = [
380378
ProductInterface::SKU => "product_simple_with_related_500",

dev/tests/api-functional/testsuite/Magento/ConfigurableProduct/Api/ConfigurableProductManagementTest.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,7 @@ public function testGetVariation()
6969
'value' => $attributeOptionValue
7070
]
7171
],
72-
'tier_prices' => [],
73-
'extension_attributes' => []
72+
'tier_prices' => []
7473
]
7574
];
7675
ksort($expectedItems);

dev/tests/api-functional/testsuite/Magento/GroupedProduct/Api/ProductRepositoryInterfaceTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ public function testProductLinks()
162162
"position" => 0, "extension_attributes" => ["qty" => 4]];
163163
$productLinkData2 = ["sku" => "group_product_500", "link_type" => "upsell",
164164
"linked_product_sku" => "product_simple_500", "linked_product_type" => "simple",
165-
"position" => 0, "extension_attributes" => []];
165+
"position" => 0];
166166
$productWithGroupData = [
167167
ProductInterface::SKU => "group_product_500",
168168
ProductInterface::NAME => "Group Product 500",

dev/tests/integration/testsuite/Magento/Customer/Block/Adminhtml/Edit/Tab/View/PersonalInfoTest.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,16 @@ public function tearDown()
9999
*/
100100
public function testGetCustomer()
101101
{
102-
$expectedCustomerData = $this->_loadCustomer()->__toArray();
103-
$actualCustomerData = $this->_block->getCustomer()->__toArray();
102+
$expectedCustomer = $this->_loadCustomer();
103+
$expectedCustomerData = $this->_dataObjectProcessor->buildOutputDataArray(
104+
$expectedCustomer,
105+
\Magento\Customer\Api\Data\CustomerInterface::class
106+
);
107+
$actualCustomer = $this->_block->getCustomer();
108+
$actualCustomerData = $this->_dataObjectProcessor->buildOutputDataArray(
109+
$actualCustomer,
110+
\Magento\Customer\Api\Data\CustomerInterface::class
111+
);
104112
foreach ($expectedCustomerData as $property => $value) {
105113
$expectedValue = is_numeric($value) ? intval($value) : $value;
106114
$actualValue = isset($actualCustomerData[$property]) ? $actualCustomerData[$property] : null;

lib/internal/Magento/Framework/Reflection/DataObjectProcessor.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
use Magento\Framework\Api\CustomAttributesDataInterface;
99
use Magento\Framework\Phrase;
10-
use Zend\Code\Reflection\MethodReflection;
1110

1211
/**
1312
* Data object processor for array serialization using class reflection
@@ -75,7 +74,6 @@ public function buildOutputDataArray($dataObject, $dataObjectType)
7574
$methods = $this->methodsMapProcessor->getMethodsMap($dataObjectType);
7675
$outputData = [];
7776

78-
/** @var MethodReflection $method */
7977
foreach (array_keys($methods) as $methodName) {
8078
if (!$this->methodsMapProcessor->isMethodValidForDataField($dataObjectType, $methodName)) {
8179
continue;
@@ -100,6 +98,9 @@ public function buildOutputDataArray($dataObject, $dataObjectType)
10098
$value = $this->customAttributesProcessor->buildOutputDataArray($dataObject, $dataObjectType);
10199
} elseif ($key === "extension_attributes") {
102100
$value = $this->extensionAttributesProcessor->buildOutputDataArray($value, $returnType);
101+
if (empty($value)) {
102+
continue;
103+
}
103104
} else {
104105
if (is_object($value) && !($value instanceof Phrase)) {
105106
$value = $this->buildOutputDataArray($value, $returnType);
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Framework\Reflection\Test\Unit;
7+
8+
use Magento\Framework\Serialize\SerializerInterface;
9+
use Magento\Framework\Reflection\DataObjectProcessor;
10+
use Magento\Framework\Reflection\ExtensionAttributesProcessor;
11+
12+
class DataObjectProcessorTest extends \PHPUnit_Framework_TestCase
13+
{
14+
/**
15+
* @var DataObjectProcessor
16+
*/
17+
private $dataObjectProcessor;
18+
19+
/**
20+
* @var ExtensionAttributesProcessor|\PHPUnit_Framework_MockObject_MockObject
21+
*/
22+
private $extensionAttributesProcessorMock;
23+
24+
protected function setUp()
25+
{
26+
$objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
27+
$methodsMapProcessor = $objectManager->getObject(
28+
\Magento\Framework\Reflection\MethodsMap::class,
29+
[
30+
'fieldNamer' => $objectManager->getObject(\Magento\Framework\Reflection\FieldNamer::class),
31+
'typeProcessor' => $objectManager->getObject(\Magento\Framework\Reflection\TypeProcessor::class),
32+
]
33+
);
34+
$serializerMock = $this->getMock(SerializerInterface::class);
35+
$serializerMock->method('serialize')
36+
->willReturn('serializedData');
37+
$serializerMock->method('unserialize')
38+
->willReturn(['unserializedData']);
39+
40+
$objectManager->setBackwardCompatibleProperty(
41+
$methodsMapProcessor,
42+
'serializer',
43+
$serializerMock
44+
);
45+
46+
$this->extensionAttributesProcessorMock = $this->getMockBuilder(ExtensionAttributesProcessor::class)
47+
->disableOriginalConstructor()
48+
->getMock();
49+
50+
$this->dataObjectProcessor = $objectManager->getObject(
51+
\Magento\Framework\Reflection\DataObjectProcessor::class,
52+
[
53+
'methodsMapProcessor' => $methodsMapProcessor,
54+
'typeCaster' => $objectManager->getObject(\Magento\Framework\Reflection\TypeCaster::class),
55+
'fieldNamer' => $objectManager->getObject(\Magento\Framework\Reflection\FieldNamer::class),
56+
'extensionAttributesProcessor' => $this->extensionAttributesProcessorMock
57+
]
58+
);
59+
}
60+
61+
/**
62+
* @param array $extensionAttributes
63+
* @param array $expectedOutputDataArray
64+
*
65+
* @dataProvider buildOutputDataArrayDataProvider
66+
*/
67+
public function testBuildOutputDataArray($extensionAttributes, $expectedOutputDataArray)
68+
{
69+
$objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
70+
/** @var \Magento\Framework\Reflection\Test\Unit\TestDataObject $testDataObject */
71+
$testDataObject = $objectManager->getObject(
72+
\Magento\Framework\Reflection\Test\Unit\TestDataObject::class,
73+
[
74+
'extensionAttributes' => $this->getMockForAbstractClass(
75+
\Magento\Framework\Api\ExtensionAttributesInterface::class
76+
)
77+
]
78+
);
79+
80+
$this->extensionAttributesProcessorMock->expects($this->once())
81+
->method('buildOutputDataArray')
82+
->willReturn($extensionAttributes);
83+
84+
$outputData = $this->dataObjectProcessor
85+
->buildOutputDataArray($testDataObject, \Magento\Framework\Reflection\Test\Unit\TestDataInterface::class);
86+
$this->assertEquals($expectedOutputDataArray, $outputData);
87+
}
88+
89+
public function buildOutputDataArrayDataProvider()
90+
{
91+
$expectedOutputDataArray = [
92+
'id' => '1',
93+
'address' => 'someAddress',
94+
'default_shipping' => 'true',
95+
'required_billing' => 'false',
96+
];
97+
$extensionAttributeArray = [
98+
'attribute1' => 'value1',
99+
'attribute2' => 'value2'
100+
];
101+
102+
return [
103+
'No Attributes' => [[], $expectedOutputDataArray],
104+
'With Attributes' => [
105+
$extensionAttributeArray,
106+
array_merge(
107+
$expectedOutputDataArray,
108+
['extension_attributes' => $extensionAttributeArray]
109+
)
110+
]
111+
];
112+
}
113+
}

app/code/Magento/Webapi/Test/Unit/Model/Files/TestDataInterface.php renamed to lib/internal/Magento/Framework/Reflection/Test/Unit/TestDataInterface.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6-
7-
namespace Magento\Webapi\Test\Unit\Model\Files;
6+
namespace Magento\Framework\Reflection\Test\Unit;
87

98
interface TestDataInterface
109
{
@@ -27,4 +26,9 @@ public function isDefaultShipping();
2726
* @return string
2827
*/
2928
public function isRequiredBilling();
29+
30+
/**
31+
* @return \Magento\Framework\Api\ExtensionAttributesInterface|null
32+
*/
33+
public function getExtensionAttributes();
3034
}

app/code/Magento/Webapi/Test/Unit/Model/Files/TestDataObject.php renamed to lib/internal/Magento/Framework/Reflection/Test/Unit/TestDataObject.php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,17 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6-
7-
namespace Magento\Webapi\Test\Unit\Model\Files;
6+
namespace Magento\Framework\Reflection\Test\Unit;
87

98
class TestDataObject implements TestDataInterface
109
{
10+
private $extensionAttributes;
11+
12+
public function __construct($extensionAttributes = null)
13+
{
14+
$this->extensionAttributes = $extensionAttributes;
15+
}
16+
1117
public function getId()
1218
{
1319
return '1';
@@ -27,4 +33,9 @@ public function isRequiredBilling()
2733
{
2834
return 'false';
2935
}
36+
37+
public function getExtensionAttributes()
38+
{
39+
return $this->extensionAttributes;
40+
}
3041
}

0 commit comments

Comments
 (0)