5
5
*/
6
6
namespace Magento \Customer \Test \Unit \Model \Metadata ;
7
7
8
- use Magento \Customer \ Model \ Metadata \ AttributeMetadataHydrator ;
8
+ use Magento \Framework \ TestFramework \ Unit \ Helper \ ObjectManager ;
9
9
use Magento \Framework \App \CacheInterface ;
10
10
use Magento \Framework \App \Cache \StateInterface ;
11
11
use Magento \Customer \Api \Data \AttributeMetadataInterface ;
12
12
use Magento \Framework \Serialize \SerializerInterface ;
13
13
use Magento \Eav \Model \Cache \Type ;
14
14
use Magento \Eav \Model \Entity \Attribute ;
15
15
use Magento \Config \App \Config \Type \System ;
16
- use Magento \Customer \Model \Data \AttributeMetadata ;
17
- use Magento \Customer \Model \Data \Option ;
18
- use Magento \Customer \Model \Data \ValidationRule ;
16
+ use Magento \Customer \Model \Metadata \AttributeMetadataHydrator ;
19
17
use Magento \Customer \Model \Metadata \AttributeMetadataCache ;
20
- use Magento \Framework \TestFramework \Unit \Helper \ObjectManager ;
21
18
22
- /**
23
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
24
- */
25
19
class AttributeMetadataCacheTest extends \PHPUnit_Framework_TestCase
26
20
{
27
21
/**
@@ -34,11 +28,6 @@ class AttributeMetadataCacheTest extends \PHPUnit_Framework_TestCase
34
28
*/
35
29
private $ stateMock ;
36
30
37
- /**
38
- * @var AttributeMetadataInterface|\PHPUnit_Framework_MockObject_MockObject
39
- */
40
- private $ attributeMetadataMock ;
41
-
42
31
/**
43
32
* @var AttributeMetadataHydrator|\PHPUnit_Framework_MockObject_MockObject
44
33
*/
@@ -60,7 +49,6 @@ protected function setUp()
60
49
$ this ->cacheMock = $ this ->getMock (CacheInterface::class);
61
50
$ this ->stateMock = $ this ->getMock (StateInterface::class);
62
51
$ this ->serializerMock = $ this ->getMock (SerializerInterface::class);
63
- $ this ->attributeMetadataMock = $ this ->getMock (AttributeMetadataInterface::class);
64
52
$ this ->attributeMetadataHydratorMock = $ this ->getMock (
65
53
AttributeMetadataHydrator::class,
66
54
[],
@@ -113,31 +101,9 @@ public function testLoad()
113
101
$ suffix = 'none ' ;
114
102
$ cacheKey = AttributeMetadataCache::ATTRIBUTE_METADATA_CACHE_PREFIX . $ entityType . $ suffix ;
115
103
$ serializedString = 'serialized string ' ;
116
- $ optionOneData = [
117
- 'label ' => 'Label 1 ' ,
118
- 'options ' => null
119
- ];
120
- $ optionThreeData = [
121
- 'label ' => 'Label 3 ' ,
122
- 'options ' => null
123
- ];
124
- $ optionFourData = [
125
- 'label ' => 'Label 4 ' ,
126
- 'options ' => null
127
- ];
128
- $ optionTwoData = [
129
- 'label ' => 'Label 2 ' ,
130
- 'options ' => [$ optionThreeData , $ optionFourData ]
131
- ];
132
- $ validationRuleOneData = [
133
- 'name ' => 'Name 1 ' ,
134
- 'value ' => 'Value 1 '
135
- ];
136
104
$ attributeMetadataOneData = [
137
105
'attribute_code ' => 'attribute_code ' ,
138
106
'frontend_input ' => 'hidden ' ,
139
- 'options ' => [$ optionOneData , $ optionTwoData ],
140
- 'validation_rules ' => [$ validationRuleOneData ]
141
107
];
142
108
$ attributesMetadataData = [$ attributeMetadataOneData ];
143
109
$ this ->stateMock ->expects ($ this ->once ())
@@ -152,49 +118,15 @@ public function testLoad()
152
118
->method ('unserialize ' )
153
119
->with ($ serializedString )
154
120
->willReturn ($ attributesMetadataData );
155
-
156
- $ optionTwoDataPartiallyConverted = [
157
- 'label ' => 'Label 2 ' ,
158
- 'options ' => [
159
- new Option ($ optionThreeData ),
160
- new Option ($ optionFourData )
161
- ]
162
- ];
163
-
164
- $ validationRule = new ValidationRule ($ validationRuleOneData );
165
-
166
- $ attributeMetadataDataPartiallyConverted = [
167
- 'attribute_code ' => 'attribute_code ' ,
168
- 'frontend_input ' => 'hidden ' ,
169
- 'options ' => [
170
- new Option ($ optionOneData ),
171
- new Option ($ optionTwoDataPartiallyConverted )
172
- ],
173
- 'validation_rules ' => [$ validationRule ]
174
- ];
175
-
176
- $ this ->attributeMetadataHydratorMock ->expects ($ this ->once ())
121
+ /** @var AttributeMetadataInterface|\PHPUnit_Framework_MockObject_MockObject $attributeMetadataMock */
122
+ $ attributeMetadataMock = $ this ->getMock (AttributeMetadataInterface::class);
123
+ $ this ->attributeMetadataHydratorMock ->expects ($ this ->at (0 ))
177
124
->method ('hydrate ' )
178
125
->with ($ attributeMetadataOneData )
179
- ->willReturn (new AttributeMetadata ($ attributeMetadataDataPartiallyConverted ));
180
-
181
- $ attributeMetadata = $ this ->attributeMetadataCache ->load ($ entityType , $ suffix );
182
-
183
- $ this ->assertEquals (
184
- $ attributeMetadataOneData ['attribute_code ' ],
185
- $ attributeMetadata [0 ]->getAttributeCode ()
186
- );
187
- $ this ->assertEquals (
188
- $ optionOneData ['label ' ],
189
- $ attributeMetadata [0 ]->getOptions ()[0 ]->getLabel ()
190
- );
191
- $ this ->assertEquals (
192
- $ optionThreeData ['label ' ],
193
- $ attributeMetadata [0 ]->getOptions ()[1 ]->getOptions ()[0 ]->getLabel ()
194
- );
195
- $ this ->assertEquals (
196
- $ validationRuleOneData ['name ' ],
197
- $ attributeMetadata [0 ]->getValidationRules ()[0 ]->getName ()
126
+ ->willReturn ($ attributeMetadataMock );
127
+ $ this ->assertInstanceOf (
128
+ AttributeMetadataInterface::class,
129
+ $ this ->attributeMetadataCache ->load ($ entityType , $ suffix )[0 ]
198
130
);
199
131
}
200
132
@@ -228,10 +160,13 @@ public function testSave()
228
160
->method ('isEnabled ' )
229
161
->with (Type::TYPE_IDENTIFIER )
230
162
->willReturn (true );
231
- $ this ->attributeMetadataMock = $ this ->getMock (AttributeMetadataInterface::class);
163
+
164
+ /** @var AttributeMetadataInterface|\PHPUnit_Framework_MockObject_MockObject $attributeMetadataMock */
165
+ $ attributeMetadataMock = $ this ->getMock (AttributeMetadataInterface::class);
166
+ $ attributesMetadata = [$ attributeMetadataMock ];
232
167
$ this ->attributeMetadataHydratorMock ->expects ($ this ->once ())
233
168
->method ('extract ' )
234
- ->with ($ this -> attributeMetadataMock )
169
+ ->with ($ attributeMetadataMock )
235
170
->willReturn ($ attributeMetadataOneData );
236
171
$ this ->serializerMock ->expects ($ this ->once ())
237
172
->method ('serialize ' )
@@ -248,7 +183,6 @@ public function testSave()
248
183
System::CACHE_TAG
249
184
]
250
185
);
251
- $ attributesMetadata = [$ this ->attributeMetadataMock ];
252
186
$ this ->attributeMetadataCache ->save ($ entityType , $ attributesMetadata , $ suffix );
253
187
$ this ->assertSame (
254
188
$ attributesMetadata ,
0 commit comments