33 * Copyright © Magento, Inc. All rights reserved.
44 * See COPYING.txt for license details.
55 */
6+ declare (strict_types=1 );
67
78namespace Magento \Customer \Model ;
89
910use Magento \Customer \Api \CustomerMetadataInterface ;
1011use Magento \Customer \Api \CustomerRepositoryInterface ;
12+ use Magento \Framework \Api \ExtensibleDataObjectConverter ;
1113use Magento \Framework \Exception \NoSuchEntityException ;
12- use Magento \TestFramework \Helper \CacheCleaner ;
14+ use Magento \TestFramework \Helper \Bootstrap ;
15+ use PHPUnit \Framework \TestCase ;
1316
14- class CustomerMetadataTest extends \PHPUnit \Framework \TestCase
17+ /**
18+ * Checks customer metadata
19+ *
20+ * @magentoDbIsolation enabled
21+ */
22+ class CustomerMetadataTest extends TestCase
1523{
1624 /** @var CustomerRepositoryInterface */
1725 private $ customerRepository ;
@@ -22,16 +30,18 @@ class CustomerMetadataTest extends \PHPUnit\Framework\TestCase
2230 /** @var CustomerMetadataInterface */
2331 private $ serviceTwo ;
2432
25- /**
26- * @var \Magento\Framework\Api\ExtensibleDataObjectConverter
27- */
33+ /** @var ExtensibleDataObjectConverter */
2834 private $ extensibleDataObjectConverter ;
2935
36+ /**
37+ * @inheritdoc
38+ */
3039 protected function setUp (): void
3140 {
32- $ objectManager = \ Magento \ TestFramework \ Helper \ Bootstrap::getObjectManager ();
41+ $ objectManager = Bootstrap::getObjectManager ();
3342 $ objectManager ->configure (
34- [\Magento \Framework \Api \ExtensionAttribute \Config \Reader::class => [
43+ [
44+ \Magento \Framework \Api \ExtensionAttribute \Config \Reader::class => [
3545 'arguments ' => [
3646 'fileResolver ' => ['instance ' => \Magento \Customer \Model \FileResolverStub::class],
3747 ],
@@ -44,13 +54,73 @@ protected function setUp(): void
4454 $ this ->service = $ objectManager ->create (\Magento \Customer \Api \CustomerMetadataInterface::class);
4555 $ this ->serviceTwo = $ objectManager ->create (\Magento \Customer \Api \CustomerMetadataInterface::class);
4656 $ this ->extensibleDataObjectConverter = $ objectManager ->get (
47- \ Magento \ Framework \ Api \ ExtensibleDataObjectConverter::class
57+ ExtensibleDataObjectConverter::class
4858 );
4959 }
5060
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
52122 {
53- $ customAttributesMetadataQty = count ($ this ->service ->getCustomAttributesMetadata ()) ;
123+ $ customAttributesMetadataQty = count ($ this ->service ->getCustomAttributesMetadata ());
54124
55125 // Verify the consistency of getCustomerAttributeMetadata() function from the 2nd call of the same service
56126 $ customAttributesMetadata1Qty = count ($ this ->service ->getCustomAttributesMetadata ());
@@ -71,8 +141,10 @@ public function testGetCustomAttributesMetadata()
71141
72142 /**
73143 * @magentoAppIsolation enabled
144+ *
145+ * @return void
74146 */
75- public function testGetNestedOptionsCustomerAttributesMetadata ()
147+ public function testGetNestedOptionsCustomerAttributesMetadata (): void
76148 {
77149 $ nestedOptionsAttribute = 'store_id ' ;
78150 $ customAttributesMetadata = $ this ->service ->getAttributeMetadata ($ nestedOptionsAttribute );
@@ -126,63 +198,10 @@ public function testGetNestedOptionsCustomerAttributesMetadata()
126198
127199 /**
128200 * @magentoDataFixture Magento/Customer/_files/attribute_user_defined_custom_attribute.php
201+ *
202+ * @return void
129203 */
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
186205 {
187206 $ allAttributesMetadata = $ this ->service ->getAllAttributesMetadata ();
188207
@@ -205,8 +224,10 @@ public function testGetAllAttributesMetadataWithCustomAttribute()
205224
206225 /**
207226 * @magentoDataFixture Magento/Customer/_files/customer.php
227+ *
228+ * @return void
208229 */
209- public function testGetCustomerAttributeMetadata ()
230+ public function testGetCustomerAttributeMetadata (): void
210231 {
211232 // Expect these attributes to exist but do not check the value
212233 $ expectAttrsWOutVals = ['created_at ' , 'updated_at ' ];
@@ -298,7 +319,10 @@ public function testGetCustomerAttributeMetadata()
298319 $ this ->assertEmpty ($ expectAttrsWithVals );
299320 }
300321
301- public function testGetCustomerAttributeMetadataNoSuchEntity ()
322+ /**
323+ * @return void
324+ */
325+ public function testGetCustomerAttributeMetadataNoSuchEntity (): void
302326 {
303327 try {
304328 $ this ->service ->getAttributeMetadata ('wrong_attribute_code ' );
@@ -333,7 +357,10 @@ public function testGetCustomerAttributeMetadataNoSuchEntity()
333357 }
334358 }
335359
336- public function testGetAttributes ()
360+ /**
361+ * @return void
362+ */
363+ public function testGetAttributes (): void
337364 {
338365 $ formAttributesMetadata = $ this ->service ->getAttributes ('adminhtml_customer ' );
339366 $ this ->assertCount (14 , $ formAttributesMetadata , "Invalid number of attributes for the specified form. " );
@@ -383,9 +410,12 @@ public function testGetAttributes()
383410 );
384411 }
385412
413+ /**
414+ * @inheritdoc
415+ */
386416 protected function tearDown (): void
387417 {
388- $ objectManager = \ Magento \ TestFramework \ Helper \ Bootstrap::getObjectManager ();
418+ $ objectManager = Bootstrap::getObjectManager ();
389419
390420 /* @var \Magento\Framework\Config\CacheInterface $cache */
391421 $ cache = $ objectManager ->create (\Magento \Framework \Config \CacheInterface::class);
0 commit comments