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