3
3
* Copyright © Magento, Inc. All rights reserved.
4
4
* See COPYING.txt for license details.
5
5
*/
6
+ declare (strict_types=1 );
6
7
7
8
namespace Magento \Customer \Model ;
8
9
9
10
use Magento \Customer \Api \CustomerMetadataInterface ;
10
11
use Magento \Customer \Api \CustomerRepositoryInterface ;
12
+ use Magento \Framework \Api \ExtensibleDataObjectConverter ;
11
13
use Magento \Framework \Exception \NoSuchEntityException ;
12
- use Magento \TestFramework \Helper \CacheCleaner ;
14
+ use Magento \TestFramework \Helper \Bootstrap ;
15
+ use PHPUnit \Framework \TestCase ;
13
16
14
- class CustomerMetadataTest extends \PHPUnit \Framework \TestCase
17
+ /**
18
+ * Checks customer metadata
19
+ *
20
+ * @magentoDbIsolation enabled
21
+ */
22
+ class CustomerMetadataTest extends TestCase
15
23
{
16
24
/** @var CustomerRepositoryInterface */
17
25
private $ customerRepository ;
@@ -22,16 +30,18 @@ class CustomerMetadataTest extends \PHPUnit\Framework\TestCase
22
30
/** @var CustomerMetadataInterface */
23
31
private $ serviceTwo ;
24
32
25
- /**
26
- * @var \Magento\Framework\Api\ExtensibleDataObjectConverter
27
- */
33
+ /** @var ExtensibleDataObjectConverter */
28
34
private $ extensibleDataObjectConverter ;
29
35
36
+ /**
37
+ * @inheritdoc
38
+ */
30
39
protected function setUp (): void
31
40
{
32
- $ objectManager = \ Magento \ TestFramework \ Helper \ Bootstrap::getObjectManager ();
41
+ $ objectManager = Bootstrap::getObjectManager ();
33
42
$ objectManager ->configure (
34
- [\Magento \Framework \Api \ExtensionAttribute \Config \Reader::class => [
43
+ [
44
+ \Magento \Framework \Api \ExtensionAttribute \Config \Reader::class => [
35
45
'arguments ' => [
36
46
'fileResolver ' => ['instance ' => \Magento \Customer \Model \FileResolverStub::class],
37
47
],
@@ -44,13 +54,73 @@ protected function setUp(): void
44
54
$ this ->service = $ objectManager ->create (\Magento \Customer \Api \CustomerMetadataInterface::class);
45
55
$ this ->serviceTwo = $ objectManager ->create (\Magento \Customer \Api \CustomerMetadataInterface::class);
46
56
$ this ->extensibleDataObjectConverter = $ objectManager ->get (
47
- \ Magento \ Framework \ Api \ ExtensibleDataObjectConverter::class
57
+ ExtensibleDataObjectConverter::class
48
58
);
49
59
}
50
60
51
- public function testGetCustomAttributesMetadata ()
61
+ /**
62
+ * @magentoDataFixture Magento/Customer/_files/attribute_user_defined_custom_attribute.php
63
+ *
64
+ * @return void
65
+ */
66
+ public function testGetCustomAttributesMetadataWithCustomAttributes (): void
67
+ {
68
+ $ customAttributesMetadata = $ this ->service ->getCustomAttributesMetadata ();
69
+ // Verify the consistency of getCustomAttributesMetadata() function from the 2nd call of the same service
70
+ $ customAttributesMetadata1 = $ this ->service ->getCustomAttributesMetadata ();
71
+ $ this ->assertEquals (
72
+ $ customAttributesMetadata ,
73
+ $ customAttributesMetadata1 ,
74
+ 'Different custom attribute metadata returned from the 2nd call of the same service '
75
+ );
76
+ // Verify the consistency of getCustomAttributesMetadata() function from the 2nd service
77
+ $ customAttributesMetadata2 = $ this ->serviceTwo ->getCustomAttributesMetadata ();
78
+ $ this ->assertEquals (
79
+ $ customAttributesMetadata ,
80
+ $ customAttributesMetadata2 ,
81
+ 'Different custom attribute metadata returned from the 2nd service '
82
+ );
83
+
84
+ $ expectedCustomAttributeCodeArray = ['custom_attribute1 ' , 'custom_attribute2 ' , 'customer_image ' ];
85
+ $ actual = [];
86
+ foreach ($ customAttributesMetadata as $ attribute ) {
87
+ $ actual [] = $ attribute ->getAttributeCode ();
88
+ }
89
+ $ this ->assertEquals (
90
+ $ expectedCustomAttributeCodeArray ,
91
+ array_intersect ($ expectedCustomAttributeCodeArray , $ actual ),
92
+ "Expected attributes not returned from the service. "
93
+ );
94
+
95
+ // Verify the consistency of custom attribute metadata from two calls of the same service
96
+ // after getAttributeCode was called
97
+ foreach ($ customAttributesMetadata1 as $ attribute ) {
98
+ $ attribute ->getAttributeCode ();
99
+ }
100
+ $ this ->assertEquals (
101
+ $ customAttributesMetadata ,
102
+ $ customAttributesMetadata1 ,
103
+ 'Custom attribute metadata from the same service became different after getAttributeCode was called '
104
+ );
105
+
106
+ // Verify the consistency of custom attribute metadata from two services
107
+ // after getAttributeCode was called
108
+ foreach ($ customAttributesMetadata2 as $ attribute ) {
109
+ $ attribute ->getAttributeCode ();
110
+ }
111
+ $ this ->assertEquals (
112
+ $ customAttributesMetadata ,
113
+ $ customAttributesMetadata2 ,
114
+ 'Custom attribute metadata from two services are different after getAttributeCode was called '
115
+ );
116
+ }
117
+
118
+ /**
119
+ * @return void
120
+ */
121
+ public function testGetCustomAttributesMetadata (): void
52
122
{
53
- $ customAttributesMetadataQty = count ($ this ->service ->getCustomAttributesMetadata ()) ;
123
+ $ customAttributesMetadataQty = count ($ this ->service ->getCustomAttributesMetadata ());
54
124
55
125
// Verify the consistency of getCustomerAttributeMetadata() function from the 2nd call of the same service
56
126
$ customAttributesMetadata1Qty = count ($ this ->service ->getCustomAttributesMetadata ());
@@ -71,8 +141,10 @@ public function testGetCustomAttributesMetadata()
71
141
72
142
/**
73
143
* @magentoAppIsolation enabled
144
+ *
145
+ * @return void
74
146
*/
75
- public function testGetNestedOptionsCustomerAttributesMetadata ()
147
+ public function testGetNestedOptionsCustomerAttributesMetadata (): void
76
148
{
77
149
$ nestedOptionsAttribute = 'store_id ' ;
78
150
$ customAttributesMetadata = $ this ->service ->getAttributeMetadata ($ nestedOptionsAttribute );
@@ -126,63 +198,10 @@ public function testGetNestedOptionsCustomerAttributesMetadata()
126
198
127
199
/**
128
200
* @magentoDataFixture Magento/Customer/_files/attribute_user_defined_custom_attribute.php
201
+ *
202
+ * @return void
129
203
*/
130
- public function testGetCustomAttributesMetadataWithCustomAttributes ()
131
- {
132
- $ customAttributesMetadata = $ this ->service ->getCustomAttributesMetadata ();
133
- // Verify the consistency of getCustomAttributesMetadata() function from the 2nd call of the same service
134
- $ customAttributesMetadata1 = $ this ->service ->getCustomAttributesMetadata ();
135
- $ this ->assertEquals (
136
- $ customAttributesMetadata ,
137
- $ customAttributesMetadata1 ,
138
- 'Different custom attribute metadata returned from the 2nd call of the same service '
139
- );
140
- // Verify the consistency of getCustomAttributesMetadata() function from the 2nd service
141
- $ customAttributesMetadata2 = $ this ->serviceTwo ->getCustomAttributesMetadata ();
142
- $ this ->assertEquals (
143
- $ customAttributesMetadata ,
144
- $ customAttributesMetadata2 ,
145
- 'Different custom attribute metadata returned from the 2nd service '
146
- );
147
-
148
- $ expectedCustomAttributeCodeArray = ['custom_attribute1 ' , 'custom_attribute2 ' , 'customer_image ' ];
149
- $ actual = [];
150
- foreach ($ customAttributesMetadata as $ attribute ) {
151
- $ actual [] = $ attribute ->getAttributeCode ();
152
- }
153
- $ this ->assertEquals (
154
- $ expectedCustomAttributeCodeArray ,
155
- array_intersect ($ expectedCustomAttributeCodeArray , $ actual ),
156
- "Expected attributes not returned from the service. "
157
- );
158
-
159
- // Verify the consistency of custom attribute metadata from two calls of the same service
160
- // after getAttributeCode was called
161
- foreach ($ customAttributesMetadata1 as $ attribute ) {
162
- $ attribute ->getAttributeCode ();
163
- }
164
- $ this ->assertEquals (
165
- $ customAttributesMetadata ,
166
- $ customAttributesMetadata1 ,
167
- 'Custom attribute metadata from the same service became different after getAttributeCode was called '
168
- );
169
-
170
- // Verify the consistency of custom attribute metadata from two services
171
- // after getAttributeCode was called
172
- foreach ($ customAttributesMetadata2 as $ attribute ) {
173
- $ attribute ->getAttributeCode ();
174
- }
175
- $ this ->assertEquals (
176
- $ customAttributesMetadata ,
177
- $ customAttributesMetadata2 ,
178
- 'Custom attribute metadata from two services are different after getAttributeCode was called '
179
- );
180
- }
181
-
182
- /**
183
- * @magentoDataFixture Magento/Customer/_files/attribute_user_defined_custom_attribute.php
184
- */
185
- public function testGetAllAttributesMetadataWithCustomAttribute ()
204
+ public function testGetAllAttributesMetadataWithCustomAttribute (): void
186
205
{
187
206
$ allAttributesMetadata = $ this ->service ->getAllAttributesMetadata ();
188
207
@@ -205,8 +224,10 @@ public function testGetAllAttributesMetadataWithCustomAttribute()
205
224
206
225
/**
207
226
* @magentoDataFixture Magento/Customer/_files/customer.php
227
+ *
228
+ * @return void
208
229
*/
209
- public function testGetCustomerAttributeMetadata ()
230
+ public function testGetCustomerAttributeMetadata (): void
210
231
{
211
232
// Expect these attributes to exist but do not check the value
212
233
$ expectAttrsWOutVals = ['created_at ' , 'updated_at ' ];
@@ -298,7 +319,10 @@ public function testGetCustomerAttributeMetadata()
298
319
$ this ->assertEmpty ($ expectAttrsWithVals );
299
320
}
300
321
301
- public function testGetCustomerAttributeMetadataNoSuchEntity ()
322
+ /**
323
+ * @return void
324
+ */
325
+ public function testGetCustomerAttributeMetadataNoSuchEntity (): void
302
326
{
303
327
try {
304
328
$ this ->service ->getAttributeMetadata ('wrong_attribute_code ' );
@@ -333,7 +357,10 @@ public function testGetCustomerAttributeMetadataNoSuchEntity()
333
357
}
334
358
}
335
359
336
- public function testGetAttributes ()
360
+ /**
361
+ * @return void
362
+ */
363
+ public function testGetAttributes (): void
337
364
{
338
365
$ formAttributesMetadata = $ this ->service ->getAttributes ('adminhtml_customer ' );
339
366
$ this ->assertCount (14 , $ formAttributesMetadata , "Invalid number of attributes for the specified form. " );
@@ -383,9 +410,12 @@ public function testGetAttributes()
383
410
);
384
411
}
385
412
413
+ /**
414
+ * @inheritdoc
415
+ */
386
416
protected function tearDown (): void
387
417
{
388
- $ objectManager = \ Magento \ TestFramework \ Helper \ Bootstrap::getObjectManager ();
418
+ $ objectManager = Bootstrap::getObjectManager ();
389
419
390
420
/* @var \Magento\Framework\Config\CacheInterface $cache */
391
421
$ cache = $ objectManager ->create (\Magento \Framework \Config \CacheInterface::class);
0 commit comments