Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ExtensibleDataObjectConverterTest.php
Go to the documentation of this file.
1 <?php
8 
12 
13 class ExtensibleDataObjectConverterTest extends \PHPUnit\Framework\TestCase
14 {
16  protected $converter;
17 
19  protected $processor;
20 
22  protected $dataObject;
23 
24  protected function setUp()
25  {
26  $this->processor = $this->getMockBuilder(\Magento\Framework\Reflection\DataObjectProcessor::class)
27  ->disableOriginalConstructor()
28  ->getMock();
29 
30  $this->dataObject = $this->getMockBuilder(\Magento\Framework\Api\ExtensibleDataInterface::class)
31  ->getMock();
32 
33  $objectManager = new ObjectManager($this);
34  $this->converter = $objectManager->getObject(
35  \Magento\Framework\Api\ExtensibleDataObjectConverter::class,
36  [
37  'dataObjectProcessor' => $this->processor,
38  ]
39  );
40  }
41 
45  public function testToNestedArray()
46  {
47  $dataArray = [
48  'attribute_key' => 'attribute_value',
49  ];
50 
51  $this->processor->expects($this->any())
52  ->method('buildOutputDataArray')
53  ->with($this->dataObject)
54  ->willReturn($dataArray);
55 
56  $this->assertEquals(
57  $dataArray,
58  $this->converter->toNestedArray($this->dataObject)
59  );
60  }
61 
65  public function testToNestedArrayCustom()
66  {
67  $dataArray = [
68  'attribute_key' => 'attribute_value',
70  [
71  AttributeValue::ATTRIBUTE_CODE => 'custom_attribute_code',
72  AttributeValue::VALUE => 'custom_attribute_value',
73  ],
74  [
75  AttributeValue::ATTRIBUTE_CODE => 'custom_attribute_code_multi',
77  'custom_attribute_value_multi_1',
78  'custom_attribute_value_multi_2',
79  ],
80  ],
81  [
82  AttributeValue::ATTRIBUTE_CODE => 'custom_attribute_code_skip',
83  AttributeValue::VALUE => 'custom_attribute_value_skip',
84  ],
85  ],
86  ];
87 
88  $resultArray = [
89  'attribute_key' => 'attribute_value',
90  'custom_attribute_code' => 'custom_attribute_value',
91  'custom_attribute_code_multi' => [
92  'custom_attribute_value_multi_1',
93  'custom_attribute_value_multi_2',
94  ],
95  ];
96 
97  $this->processor->expects($this->any())
98  ->method('buildOutputDataArray')
99  ->with($this->dataObject)
100  ->willReturn($dataArray);
101 
102  $this->assertEquals(
103  $resultArray,
104  $this->converter->toNestedArray($this->dataObject, ['custom_attribute_code_skip'])
105  );
106  }
107 }
$objectManager
Definition: bootstrap.php:17