3
3
* Copyright © Magento, Inc. All rights reserved.
4
4
* See COPYING.txt for license details.
5
5
*/
6
-
7
- namespace Magento \Webapi \Test \Unit \Model ;
6
+ namespace Magento \Framework \Reflection \Test \Unit ;
8
7
9
8
use Magento \Framework \Serialize \SerializerInterface ;
10
9
use Magento \Framework \Reflection \DataObjectProcessor ;
11
- use Magento \Webapi \ Model \ Config as ModelConfig ;
10
+ use Magento \Framework \ Reflection \ ExtensionAttributesProcessor ;
12
11
13
12
class DataObjectProcessorTest extends \PHPUnit_Framework_TestCase
14
13
{
15
14
/**
16
15
* @var DataObjectProcessor
17
16
*/
18
- protected $ dataObjectProcessor ;
17
+ private $ dataObjectProcessor ;
19
18
20
19
/**
21
- * @var ModelConfig
20
+ * @var ExtensionAttributesProcessor|\PHPUnit_Framework_MockObject_MockObject
22
21
*/
23
- protected $ config ;
22
+ private $ extensionAttributesProcessorMock ;
24
23
25
- protected function setup ()
24
+ protected function setUp ()
26
25
{
27
26
$ objectManager = new \Magento \Framework \TestFramework \Unit \Helper \ObjectManager ($ this );
28
27
$ methodsMapProcessor = $ objectManager ->getObject (
@@ -43,32 +42,68 @@ protected function setup()
43
42
'serializer ' ,
44
43
$ serializerMock
45
44
);
45
+
46
+ $ this ->extensionAttributesProcessorMock = $ this ->getMockBuilder (ExtensionAttributesProcessor::class)
47
+ ->disableOriginalConstructor ()
48
+ ->getMock ();
49
+
46
50
$ this ->dataObjectProcessor = $ objectManager ->getObject (
47
51
\Magento \Framework \Reflection \DataObjectProcessor::class,
48
52
[
49
53
'methodsMapProcessor ' => $ methodsMapProcessor ,
50
54
'typeCaster ' => $ objectManager ->getObject (\Magento \Framework \Reflection \TypeCaster::class),
51
55
'fieldNamer ' => $ objectManager ->getObject (\Magento \Framework \Reflection \FieldNamer::class),
56
+ 'extensionAttributesProcessor ' => $ this ->extensionAttributesProcessorMock
52
57
]
53
58
);
54
- parent ::setUp ();
55
59
}
56
60
57
- public function testDataObjectProcessor ()
61
+ /**
62
+ * @param array $extensionAttributes
63
+ * @param array $expectedOutputDataArray
64
+ *
65
+ * @dataProvider buildOutputDataArrayDataProvider
66
+ */
67
+ public function testBuildOutputDataArray ($ extensionAttributes , $ expectedOutputDataArray )
58
68
{
59
69
$ 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
+ }
62
85
86
+ public function buildOutputDataArrayDataProvider ()
87
+ {
63
88
$ expectedOutputDataArray = [
64
89
'id ' => '1 ' ,
65
90
'address ' => 'someAddress ' ,
66
91
'default_shipping ' => 'true ' ,
67
92
'required_billing ' => 'false ' ,
68
93
];
94
+ $ extensionAttributeArray = [
95
+ 'attribute1 ' => 'value1 ' ,
96
+ 'attribute2 ' => 'value2 '
97
+ ];
69
98
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
+ ];
73
108
}
74
109
}
0 commit comments