Skip to content

Commit 938dbe8

Browse files
committed
MAGETWO-56206: API - inconsistency in the Magento response data types
- Moved unit test and test objects to correct location - Cleaned up unused imports, methods, and parameters - Added logic to test functionality added to DataObjectProcessor
1 parent 9157861 commit 938dbe8

File tree

3 files changed

+68
-18
lines changed

3 files changed

+68
-18
lines changed

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

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

98
use Magento\Framework\Serialize\SerializerInterface;
109
use Magento\Framework\Reflection\DataObjectProcessor;
11-
use Magento\Webapi\Model\Config as ModelConfig;
10+
use Magento\Framework\Reflection\ExtensionAttributesProcessor;
1211

1312
class DataObjectProcessorTest extends \PHPUnit_Framework_TestCase
1413
{
1514
/**
1615
* @var DataObjectProcessor
1716
*/
18-
protected $dataObjectProcessor;
17+
private $dataObjectProcessor;
1918

2019
/**
21-
* @var ModelConfig
20+
* @var ExtensionAttributesProcessor|\PHPUnit_Framework_MockObject_MockObject
2221
*/
23-
protected $config;
22+
private $extensionAttributesProcessorMock;
2423

25-
protected function setup()
24+
protected function setUp()
2625
{
2726
$objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
2827
$methodsMapProcessor = $objectManager->getObject(
@@ -43,32 +42,68 @@ protected function setup()
4342
'serializer',
4443
$serializerMock
4544
);
45+
46+
$this->extensionAttributesProcessorMock = $this->getMockBuilder(ExtensionAttributesProcessor::class)
47+
->disableOriginalConstructor()
48+
->getMock();
49+
4650
$this->dataObjectProcessor = $objectManager->getObject(
4751
\Magento\Framework\Reflection\DataObjectProcessor::class,
4852
[
4953
'methodsMapProcessor' => $methodsMapProcessor,
5054
'typeCaster' => $objectManager->getObject(\Magento\Framework\Reflection\TypeCaster::class),
5155
'fieldNamer' => $objectManager->getObject(\Magento\Framework\Reflection\FieldNamer::class),
56+
'extensionAttributesProcessor' => $this->extensionAttributesProcessorMock
5257
]
5358
);
54-
parent::setUp();
5559
}
5660

57-
public function testDataObjectProcessor()
61+
/**
62+
* @param array $extensionAttributes
63+
* @param array $expectedOutputDataArray
64+
*
65+
* @dataProvider buildOutputDataArrayDataProvider
66+
*/
67+
public function testBuildOutputDataArray($extensionAttributes, $expectedOutputDataArray)
5868
{
5969
$objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
60-
/** @var \Magento\Webapi\Test\Unit\Model\Files\TestDataObject $testDataObject */
61-
$testDataObject = $objectManager->getObject(\Magento\Webapi\Test\Unit\Model\Files\TestDataObject::class);
70+
/** @var \Magento\Framework\Reflection\Test\Unit\_files\TestDataObject $testDataObject */
71+
$testDataObject = $objectManager->getObject(_files\TestDataObject::class, [
72+
'extensionAttributes' => $this->getMockForAbstractClass(
73+
\Magento\Framework\Api\ExtensionAttributesInterface::class
74+
)
75+
]);
76+
77+
$this->extensionAttributesProcessorMock->expects($this->once())
78+
->method('buildOutputDataArray')
79+
->willReturn($extensionAttributes);
80+
81+
$outputData = $this->dataObjectProcessor
82+
->buildOutputDataArray($testDataObject, _files\TestDataInterface::class);
83+
$this->assertEquals($expectedOutputDataArray, $outputData);
84+
}
6285

86+
public function buildOutputDataArrayDataProvider()
87+
{
6388
$expectedOutputDataArray = [
6489
'id' => '1',
6590
'address' => 'someAddress',
6691
'default_shipping' => 'true',
6792
'required_billing' => 'false',
6893
];
94+
$extensionAttributeArray = [
95+
'attribute1' => 'value1',
96+
'attribute2' => 'value2'
97+
];
6998

70-
$testDataObjectType = \Magento\Webapi\Test\Unit\Model\Files\TestDataInterface::class;
71-
$outputData = $this->dataObjectProcessor->buildOutputDataArray($testDataObject, $testDataObjectType);
72-
$this->assertEquals($expectedOutputDataArray, $outputData);
99+
return [
100+
'No Attributes' => [[], $expectedOutputDataArray],
101+
'With Attributes' => [
102+
$extensionAttributeArray,
103+
array_merge($expectedOutputDataArray, [
104+
'extension_attributes' => $extensionAttributeArray
105+
])
106+
]
107+
];
73108
}
74109
}

app/code/Magento/Webapi/Test/Unit/Model/Files/TestDataInterface.php renamed to lib/internal/Magento/Framework/Reflection/Test/Unit/_files/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\_files;
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/_files/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\_files;
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)