8
8
namespace Magento \GraphQl \Customer ;
9
9
10
10
use Magento \Customer \Api \AccountManagementInterface ;
11
+ use Magento \Customer \Model \CustomerRegistry ;
11
12
use Magento \Framework \Exception \LocalizedException ;
12
13
use Magento \Integration \Api \CustomerTokenServiceInterface ;
13
- use Magento \TestFramework \ObjectManager ;
14
+ use Magento \TestFramework \Helper \ Bootstrap ;
14
15
use Magento \TestFramework \TestCase \GraphQlAbstract ;
15
16
16
17
class CustomerChangePasswordTest extends GraphQlAbstract
17
18
{
18
19
/**
19
- * @var ObjectManager
20
+ * @var AccountManagementInterface
20
21
*/
21
- private $ objectManager ;
22
+ private $ accountManagement ;
22
23
23
24
/**
24
- * @var AccountManagementInterface
25
+ * @var CustomerTokenServiceInterface
25
26
*/
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
+ }
27
40
28
41
/**
29
42
* @magentoApiDataFixture Magento/Customer/_files/customer.php
@@ -42,8 +55,7 @@ public function testCustomerChangeValidPassword()
42
55
43
56
try {
44
57
// 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 );
47
59
$ this ->accountManagement ->authenticate ($ customerEmail , $ newCustomerPassword );
48
60
} catch (LocalizedException $ e ) {
49
61
$ this ->fail ('Password was not changed: ' . $ e ->getMessage ());
@@ -120,17 +132,14 @@ private function getChangePassQuery($currentPassword, $newPassword)
120
132
return $ query ;
121
133
}
122
134
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
124
141
{
125
- /** @var CustomerTokenServiceInterface $customerTokenService */
126
- $ customerTokenService = $ this ->objectManager ->create (CustomerTokenServiceInterface::class);
127
- $ customerToken = $ customerTokenService ->createCustomerAccessToken ($ customerEmail , $ oldCustomerPassword );
142
+ $ customerToken = $ this ->customerTokenService ->createCustomerAccessToken ($ email , $ password );
128
143
return ['Authorization ' => 'Bearer ' . $ customerToken ];
129
144
}
130
-
131
- protected function setUp ()
132
- {
133
- $ this ->objectManager = \Magento \TestFramework \Helper \Bootstrap::getObjectManager ();
134
- $ this ->accountManagement = $ this ->objectManager ->get (AccountManagementInterface::class);
135
- }
136
145
}
0 commit comments