Skip to content

Commit 67145c3

Browse files
author
Valeriy Nayda
committed
GraphQL-54: [Mutations] My Account: Change Password
1 parent 611d78c commit 67145c3

File tree

1 file changed

+26
-17
lines changed

1 file changed

+26
-17
lines changed

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

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,35 @@
88
namespace Magento\GraphQl\Customer;
99

1010
use Magento\Customer\Api\AccountManagementInterface;
11+
use Magento\Customer\Model\CustomerRegistry;
1112
use Magento\Framework\Exception\LocalizedException;
1213
use Magento\Integration\Api\CustomerTokenServiceInterface;
13-
use Magento\TestFramework\ObjectManager;
14+
use Magento\TestFramework\Helper\Bootstrap;
1415
use Magento\TestFramework\TestCase\GraphQlAbstract;
1516

1617
class CustomerChangePasswordTest extends GraphQlAbstract
1718
{
1819
/**
19-
* @var ObjectManager
20+
* @var AccountManagementInterface
2021
*/
21-
private $objectManager;
22+
private $accountManagement;
2223

2324
/**
24-
* @var AccountManagementInterface
25+
* @var CustomerTokenServiceInterface
2526
*/
26-
private $accountManagement;
27+
private $customerTokenService;
28+
29+
/**
30+
* @var CustomerRegistry
31+
*/
32+
private $customerRegistry;
33+
34+
protected function setUp()
35+
{
36+
$this->customerTokenService = Bootstrap::getObjectManager()->get(CustomerTokenServiceInterface::class);
37+
$this->accountManagement = Bootstrap::getObjectManager()->get(AccountManagementInterface::class);
38+
$this->customerRegistry = Bootstrap::getObjectManager()->get(CustomerRegistry::class);
39+
}
2740

2841
/**
2942
* @magentoApiDataFixture Magento/Customer/_files/customer.php
@@ -42,8 +55,7 @@ public function testCustomerChangeValidPassword()
4255

4356
try {
4457
// registry contains the old password hash so needs to be reset
45-
$this->objectManager->get(\Magento\Customer\Model\CustomerRegistry::class)
46-
->removeByEmail($customerEmail);
58+
$this->customerRegistry->removeByEmail($customerEmail);
4759
$this->accountManagement->authenticate($customerEmail, $newCustomerPassword);
4860
} catch (LocalizedException $e) {
4961
$this->fail('Password was not changed: ' . $e->getMessage());
@@ -120,17 +132,14 @@ private function getChangePassQuery($currentPassword, $newPassword)
120132
return $query;
121133
}
122134

123-
private function getCustomerAuthHeaders($customerEmail, $oldCustomerPassword)
135+
/**
136+
* @param string $email
137+
* @param string $password
138+
* @return array
139+
*/
140+
private function getCustomerAuthHeaders(string $email, string $password): array
124141
{
125-
/** @var CustomerTokenServiceInterface $customerTokenService */
126-
$customerTokenService = $this->objectManager->create(CustomerTokenServiceInterface::class);
127-
$customerToken = $customerTokenService->createCustomerAccessToken($customerEmail, $oldCustomerPassword);
142+
$customerToken = $this->customerTokenService->createCustomerAccessToken($email, $password);
128143
return ['Authorization' => 'Bearer ' . $customerToken];
129144
}
130-
131-
protected function setUp()
132-
{
133-
$this->objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
134-
$this->accountManagement = $this->objectManager->get(AccountManagementInterface::class);
135-
}
136145
}

0 commit comments

Comments
 (0)