Skip to content

Commit 049f57c

Browse files
committed
Tests data rollback
1 parent 5e5ed1b commit 049f57c

File tree

1 file changed

+21
-15
lines changed

1 file changed

+21
-15
lines changed

dev/tests/api-functional/testsuite/Magento/GraphQl/Customer/CreateCustomerTest.php

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ class CreateCustomerTest extends GraphQlAbstract
2424
*/
2525
private $customerRepository;
2626

27+
/**
28+
* @var null|string
29+
*/
30+
private $customerRandomEmail = null;
31+
2732
protected function setUp()
2833
{
2934
parent::setUp();
@@ -40,15 +45,15 @@ public function testCreateCustomerAccountWithPassword()
4045
$newFirstname = 'Richard';
4146
$newLastname = 'Rowe';
4247
$currentPassword = 'test123#';
43-
$newEmail = 'customer_created' . rand(1, 2000000) . '@example.com';
48+
$this->customerRandomEmail = 'customer_created' . rand(1, 2000000) . '@example.com';
4449

4550
$query = <<<QUERY
4651
mutation {
4752
createCustomer(
4853
input: {
4954
firstname: "{$newFirstname}"
5055
lastname: "{$newLastname}"
51-
email: "{$newEmail}"
56+
email: "{$this->customerRandomEmail}"
5257
password: "{$currentPassword}"
5358
is_subscribed: true
5459
}
@@ -67,7 +72,7 @@ public function testCreateCustomerAccountWithPassword()
6772

6873
$this->assertEquals($newFirstname, $response['createCustomer']['customer']['firstname']);
6974
$this->assertEquals($newLastname, $response['createCustomer']['customer']['lastname']);
70-
$this->assertEquals($newEmail, $response['createCustomer']['customer']['email']);
75+
$this->assertEquals($this->customerRandomEmail, $response['createCustomer']['customer']['email']);
7176
$this->assertEquals(true, $response['createCustomer']['customer']['is_subscribed']);
7277
}
7378

@@ -78,15 +83,15 @@ public function testCreateCustomerAccountWithoutPassword()
7883
{
7984
$newFirstname = 'Richard';
8085
$newLastname = 'Rowe';
81-
$newEmail = 'customer_created' . rand(1, 2000000) . '@example.com';
86+
$this->customerRandomEmail = 'customer_created' . rand(1, 2000000) . '@example.com';
8287

8388
$query = <<<QUERY
8489
mutation {
8590
createCustomer(
8691
input: {
8792
firstname: "{$newFirstname}"
8893
lastname: "{$newLastname}"
89-
email: "{$newEmail}"
94+
email: "{$this->customerRandomEmail}"
9095
is_subscribed: true
9196
}
9297
) {
@@ -104,7 +109,7 @@ public function testCreateCustomerAccountWithoutPassword()
104109

105110
$this->assertEquals($newFirstname, $response['createCustomer']['customer']['firstname']);
106111
$this->assertEquals($newLastname, $response['createCustomer']['customer']['lastname']);
107-
$this->assertEquals($newEmail, $response['createCustomer']['customer']['email']);
112+
$this->assertEquals($this->customerRandomEmail, $response['createCustomer']['customer']['email']);
108113
$this->assertEquals(true, $response['createCustomer']['customer']['is_subscribed']);
109114
}
110115

@@ -240,16 +245,17 @@ public function testCreateCustomerIfPassedAttributeDosNotExistsInCustomerInput()
240245

241246
public function tearDown()
242247
{
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);
250258
}
251-
$registry->unregister('isSecureArea');
252-
$registry->register('isSecureArea', false);
253259
parent::tearDown();
254260
}
255261
}

0 commit comments

Comments
 (0)