5
5
*/
6
6
namespace Magento \Customer \Test \Unit \Model \Metadata ;
7
7
8
+ use Magento \Customer \Model \Metadata \AttributeMetadataHydrator ;
8
9
use Magento \Framework \App \CacheInterface ;
9
10
use Magento \Framework \App \Cache \StateInterface ;
10
11
use Magento \Customer \Api \Data \AttributeMetadataInterface ;
11
- use Magento \Customer \Api \Data \AttributeMetadataInterfaceFactory ;
12
- use Magento \Customer \Api \Data \OptionInterface ;
13
- use Magento \Customer \Api \Data \OptionInterfaceFactory ;
14
- use Magento \Customer \Api \Data \ValidationRuleInterface ;
15
- use Magento \Customer \Api \Data \ValidationRuleInterfaceFactory ;
16
12
use Magento \Framework \Serialize \SerializerInterface ;
17
13
use Magento \Eav \Model \Cache \Type ;
18
14
use Magento \Eav \Model \Entity \Attribute ;
@@ -39,19 +35,14 @@ class AttributeMetadataCacheTest extends \PHPUnit_Framework_TestCase
39
35
private $ stateMock ;
40
36
41
37
/**
42
- * @var AttributeMetadataInterfaceFactory |\PHPUnit_Framework_MockObject_MockObject
38
+ * @var AttributeMetadataInterface |\PHPUnit_Framework_MockObject_MockObject
43
39
*/
44
- private $ attributeMetadataFactoryMock ;
40
+ private $ attributeMetadataMock ;
45
41
46
42
/**
47
- * @var OptionInterfaceFactory |\PHPUnit_Framework_MockObject_MockObject
43
+ * @var AttributeMetadataHydrator |\PHPUnit_Framework_MockObject_MockObject
48
44
*/
49
- private $ optionFactoryMock ;
50
-
51
- /**
52
- * @var ValidationRuleInterfaceFactory|\PHPUnit_Framework_MockObject_MockObject
53
- */
54
- private $ validationRuleFactoryMock ;
45
+ private $ attributeMetadataHydratorMock ;
55
46
56
47
/**
57
48
* @var SerializerInterface|\PHPUnit_Framework_MockObject_MockObject
@@ -68,40 +59,22 @@ protected function setUp()
68
59
$ objectManager = new ObjectManager ($ this );
69
60
$ this ->cacheMock = $ this ->getMock (CacheInterface::class);
70
61
$ this ->stateMock = $ this ->getMock (StateInterface::class);
71
- $ this ->attributeMetadataFactoryMock = $ this ->getMock (
72
- AttributeMetadataInterfaceFactory::class,
73
- ['create ' ],
74
- [],
75
- '' ,
76
- false
77
- );
78
- $ this ->optionFactoryMock = $ this ->getMock (
79
- OptionInterfaceFactory::class,
80
- ['create ' ],
62
+ $ this ->serializerMock = $ this ->getMock (SerializerInterface::class);
63
+ $ this ->attributeMetadataMock = $ this ->getMock (AttributeMetadataInterface::class);
64
+ $ this ->attributeMetadataHydratorMock = $ this ->getMock (
65
+ AttributeMetadataHydrator::class,
81
66
[],
82
- '' ,
83
- false
84
- );
85
- $ this ->validationRuleFactoryMock = $ this ->getMock (
86
- ValidationRuleInterfaceFactory::class,
87
- ['create ' ],
88
67
[],
89
68
'' ,
90
69
false
91
70
);
92
- $ this ->serializerMock = $ this ->getMock (SerializerInterface::class);
93
- $ this ->attributeMetadataMock = $ this ->getMock (AttributeMetadataInterface::class);
94
- $ this ->optionMock = $ this ->getMock (OptionInterface::class);
95
- $ this ->validationRuleMock = $ this ->getMock (ValidationRuleInterface::class);
96
71
$ this ->attributeMetadataCache = $ objectManager ->getObject (
97
72
AttributeMetadataCache::class,
98
73
[
99
74
'cache ' => $ this ->cacheMock ,
100
75
'state ' => $ this ->stateMock ,
101
- 'attributeMetadataFactory ' => $ this ->attributeMetadataFactoryMock ,
102
- 'optionFactory ' => $ this ->optionFactoryMock ,
103
- 'validationRuleFactory ' => $ this ->validationRuleFactoryMock ,
104
- 'serializer ' => $ this ->serializerMock
76
+ 'serializer ' => $ this ->serializerMock ,
77
+ 'attributeMetadataHydrator ' => $ this ->attributeMetadataHydratorMock
105
78
]
106
79
);
107
80
}
@@ -134,9 +107,6 @@ public function testLoadNoCache()
134
107
$ this ->assertFalse ($ this ->attributeMetadataCache ->load ($ entityType , $ suffix ));
135
108
}
136
109
137
- /**
138
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
139
- */
140
110
public function testLoad ()
141
111
{
142
112
$ entityType = 'EntityType ' ;
@@ -169,6 +139,7 @@ public function testLoad()
169
139
'options ' => [$ optionOneData , $ optionTwoData ],
170
140
'validation_rules ' => [$ validationRuleOneData ]
171
141
];
142
+ $ attributesMetadataData = [$ attributeMetadataOneData ];
172
143
$ this ->stateMock ->expects ($ this ->once ())
173
144
->method ('isEnabled ' )
174
145
->with (Type::TYPE_IDENTIFIER )
@@ -180,53 +151,32 @@ public function testLoad()
180
151
$ this ->serializerMock ->expects ($ this ->once ())
181
152
->method ('unserialize ' )
182
153
->with ($ serializedString )
183
- ->willReturn ([ $ attributeMetadataOneData ] );
154
+ ->willReturn ($ attributesMetadataData );
184
155
185
- $ optionOne = new Option ($ optionOneData );
186
- $ this ->optionFactoryMock ->expects ($ this ->at (0 ))
187
- ->method ('create ' )
188
- ->with (['data ' => $ optionOneData ])
189
- ->willReturn ($ optionOne );
190
- $ optionThree = new Option ($ optionThreeData );
191
- $ this ->optionFactoryMock ->expects ($ this ->at (1 ))
192
- ->method ('create ' )
193
- ->with (['data ' => $ optionThreeData ])
194
- ->willReturn ($ optionThree );
195
- $ optionFour = new Option ($ optionFourData );
196
- $ this ->optionFactoryMock ->expects ($ this ->at (2 ))
197
- ->method ('create ' )
198
- ->with (['data ' => $ optionFourData ])
199
- ->willReturn ($ optionFour );
200
-
201
- $ optionTwoDataForFactory = [
156
+ $ optionTwoDataPartiallyConverted = [
202
157
'label ' => 'Label 2 ' ,
203
- 'options ' => [$ optionThree , $ optionFour ]
158
+ 'options ' => [
159
+ new Option ($ optionThreeData ),
160
+ new Option ($ optionFourData )
161
+ ]
204
162
];
205
- $ optionFour = new Option ($ optionTwoDataForFactory );
206
- $ this ->optionFactoryMock ->expects ($ this ->at (3 ))
207
- ->method ('create ' )
208
- ->with (['data ' => $ optionTwoDataForFactory ])
209
- ->willReturn ($ optionFour );
210
163
211
164
$ validationRule = new ValidationRule ($ validationRuleOneData );
212
- $ this ->validationRuleFactoryMock ->expects ($ this ->once ())
213
- ->method ('create ' )
214
- ->with (['data ' => $ validationRuleOneData ])
215
- ->willReturn ($ validationRule );
216
165
217
- $ attributeMetadataDataForFactory = [
166
+ $ attributeMetadataDataPartiallyConverted = [
218
167
'attribute_code ' => 'attribute_code ' ,
219
168
'frontend_input ' => 'hidden ' ,
220
- 'options ' => [$ optionOne , $ optionFour ],
169
+ 'options ' => [
170
+ new Option ($ optionOneData ),
171
+ new Option ($ optionTwoDataPartiallyConverted )
172
+ ],
221
173
'validation_rules ' => [$ validationRule ]
222
174
];
223
175
224
- $ this ->attributeMetadataFactoryMock ->expects ($ this ->once ())
225
- ->method ('create ' )
226
- ->with (['data ' => $ attributeMetadataDataForFactory ])
227
- ->willReturn (
228
- new AttributeMetadata ($ attributeMetadataDataForFactory )
229
- );
176
+ $ this ->attributeMetadataHydratorMock ->expects ($ this ->once ())
177
+ ->method ('hydrate ' )
178
+ ->with ($ attributeMetadataOneData )
179
+ ->willReturn (new AttributeMetadata ($ attributeMetadataDataPartiallyConverted ));
230
180
231
181
$ attributeMetadata = $ this ->attributeMetadataCache ->load ($ entityType , $ suffix );
232
182
@@ -278,15 +228,10 @@ public function testSave()
278
228
->method ('isEnabled ' )
279
229
->with (Type::TYPE_IDENTIFIER )
280
230
->willReturn (true );
281
- $ attributeMetadataMock = $ this ->getMock (
282
- AttributeMetadata::class,
283
- [],
284
- [],
285
- '' ,
286
- false
287
- );
288
- $ attributeMetadataMock ->expects ($ this ->once ())
289
- ->method ('__toArray ' )
231
+ $ this ->attributeMetadataMock = $ this ->getMock (AttributeMetadataInterface::class);
232
+ $ this ->attributeMetadataHydratorMock ->expects ($ this ->once ())
233
+ ->method ('extract ' )
234
+ ->with ($ this ->attributeMetadataMock )
290
235
->willReturn ($ attributeMetadataOneData );
291
236
$ this ->serializerMock ->expects ($ this ->once ())
292
237
->method ('serialize ' )
@@ -303,7 +248,7 @@ public function testSave()
303
248
System::CACHE_TAG
304
249
]
305
250
);
306
- $ attributesMetadata = [$ attributeMetadataMock ];
251
+ $ attributesMetadata = [$ this -> attributeMetadataMock ];
307
252
$ this ->attributeMetadataCache ->save ($ entityType , $ attributesMetadata , $ suffix );
308
253
$ this ->assertSame (
309
254
$ attributesMetadata ,
0 commit comments