@@ -24,11 +24,6 @@ class CreateCustomerTest extends GraphQlAbstract
24
24
*/
25
25
private $ customerRepository ;
26
26
27
- /**
28
- * @var null|string
29
- */
30
- private $ customerRandomEmail = null ;
31
-
32
27
protected function setUp ()
33
28
{
34
29
parent ::setUp ();
@@ -45,15 +40,15 @@ public function testCreateCustomerAccountWithPassword()
45
40
$ newFirstname = 'Richard ' ;
46
41
$ newLastname = 'Rowe ' ;
47
42
$ currentPassword = 'test123# ' ;
48
- $ this -> customerRandomEmail = 'customer_created ' . rand ( 1 , 2000000 ) . ' @example.com ' ;
43
+ $ newEmail = 'customer_created_random123 @example.com ' ;
49
44
50
45
$ query = <<<QUERY
51
46
mutation {
52
47
createCustomer(
53
48
input: {
54
49
firstname: " {$ newFirstname }"
55
50
lastname: " {$ newLastname }"
56
- email: " {$ this -> customerRandomEmail }"
51
+ email: " {$ newEmail }"
57
52
password: " {$ currentPassword }"
58
53
is_subscribed: true
59
54
}
@@ -72,7 +67,7 @@ public function testCreateCustomerAccountWithPassword()
72
67
73
68
$ this ->assertEquals ($ newFirstname , $ response ['createCustomer ' ]['customer ' ]['firstname ' ]);
74
69
$ this ->assertEquals ($ newLastname , $ response ['createCustomer ' ]['customer ' ]['lastname ' ]);
75
- $ this ->assertEquals ($ this -> customerRandomEmail , $ response ['createCustomer ' ]['customer ' ]['email ' ]);
70
+ $ this ->assertEquals ($ newEmail , $ response ['createCustomer ' ]['customer ' ]['email ' ]);
76
71
$ this ->assertEquals (true , $ response ['createCustomer ' ]['customer ' ]['is_subscribed ' ]);
77
72
}
78
73
@@ -83,15 +78,15 @@ public function testCreateCustomerAccountWithoutPassword()
83
78
{
84
79
$ newFirstname = 'Richard ' ;
85
80
$ newLastname = 'Rowe ' ;
86
- $ this -> customerRandomEmail = 'customer_created ' . rand ( 1 , 2000000 ) . ' @example.com ' ;
81
+ $ newEmail = 'customer_created_random123 @example.com ' ;
87
82
88
83
$ query = <<<QUERY
89
84
mutation {
90
85
createCustomer(
91
86
input: {
92
87
firstname: " {$ newFirstname }"
93
88
lastname: " {$ newLastname }"
94
- email: " {$ this -> customerRandomEmail }"
89
+ email: " {$ newEmail }"
95
90
is_subscribed: true
96
91
}
97
92
) {
@@ -109,7 +104,7 @@ public function testCreateCustomerAccountWithoutPassword()
109
104
110
105
$ this ->assertEquals ($ newFirstname , $ response ['createCustomer ' ]['customer ' ]['firstname ' ]);
111
106
$ this ->assertEquals ($ newLastname , $ response ['createCustomer ' ]['customer ' ]['lastname ' ]);
112
- $ this ->assertEquals ($ this -> customerRandomEmail , $ response ['createCustomer ' ]['customer ' ]['email ' ]);
107
+ $ this ->assertEquals ($ newEmail , $ response ['createCustomer ' ]['customer ' ]['email ' ]);
113
108
$ this ->assertEquals (true , $ response ['createCustomer ' ]['customer ' ]['is_subscribed ' ]);
114
109
}
115
110
@@ -216,7 +211,7 @@ public function testCreateCustomerIfPassedAttributeDosNotExistsInCustomerInput()
216
211
$ newFirstname = 'Richard ' ;
217
212
$ newLastname = 'Rowe ' ;
218
213
$ currentPassword = 'test123# ' ;
219
- $ newEmail = 'customer_created ' . rand ( 1 , 2000000 ) . ' @example.com ' ;
214
+ $ newEmail = 'customer_created_random123 @example.com ' ;
220
215
221
216
$ query = <<<QUERY
222
217
mutation {
@@ -245,17 +240,21 @@ public function testCreateCustomerIfPassedAttributeDosNotExistsInCustomerInput()
245
240
246
241
public function tearDown ()
247
242
{
248
- if ($ this ->customerRandomEmail !== null ) {
249
- $ registry = Bootstrap::getObjectManager ()->get (\Magento \Framework \Registry::class);
250
- $ registry ->unregister ('isSecureArea ' );
251
- $ registry ->register ('isSecureArea ' , true );
252
- $ customer = $ this ->customerRepository ->get ($ this ->customerRandomEmail );
253
- if (isset ($ customer ) && $ customer ->getId ()) {
254
- $ this ->customerRepository ->delete ($ customer );
255
- }
256
- $ registry ->unregister ('isSecureArea ' );
257
- $ registry ->register ('isSecureArea ' , false );
243
+ $ newEmail = 'customer_created_random123@example.com ' ;
244
+ try {
245
+ $ customer = $ this ->customerRepository ->get ($ newEmail );
246
+
247
+ } catch (\Exception $ exception ) {
248
+ return false ;
249
+ }
250
+ $ registry = Bootstrap::getObjectManager ()->get (\Magento \Framework \Registry::class);
251
+ $ registry ->unregister ('isSecureArea ' );
252
+ $ registry ->register ('isSecureArea ' , true );
253
+ if (isset ($ customer ) && $ customer ->getId ()) {
254
+ $ this ->customerRepository ->delete ($ customer );
258
255
}
256
+ $ registry ->unregister ('isSecureArea ' );
257
+ $ registry ->register ('isSecureArea ' , false );
259
258
parent ::tearDown ();
260
259
}
261
260
}
0 commit comments