customerTokenService = Bootstrap::getObjectManager()->get(CustomerTokenServiceInterface::class); $this->customerRepository = Bootstrap::getObjectManager()->get(CustomerRepositoryInterface::class); $this->updateCustomerAccount = Bootstrap::getObjectManager()->get(UpdateCustomerAccount::class); $this->storeRepository = Bootstrap::getObjectManager()->get(StoreRepositoryInterface::class); } /** * @magentoApiDataFixture Magento/Customer/_files/customer.php */ public function testUpdateCustomerEmail(): void { $currentEmail = 'customer@example.com'; $currentPassword = 'password'; $newEmail = 'newcustomer@example.com'; $query = <<graphQlMutation( $query, [], '', $this->getCustomerAuthHeaders($currentEmail, $currentPassword) ); $this->assertEquals($newEmail, $response['updateCustomerEmail']['customer']['email']); /* $this->updateCustomerAccount->execute( $this->customerRepository->get($newEmail), ['email' => $currentEmail, 'password' => $currentPassword], $this->storeRepository->getById(1) );*/ } /** * @magentoApiDataFixture Magento/Customer/_files/customer.php */ public function testUpdateCustomerEmailIfPasswordIsWrong(): void { $this->expectException(Exception::class); $this->expectExceptionMessage('Invalid login or password.'); $currentEmail = 'customer@example.com'; $currentPassword = 'password'; $newEmail = 'newcustomer@example.com'; $wrongPassword = 'wrongpassword'; $query = <<graphQlMutation( $query, [], '', $this->getCustomerAuthHeaders($currentEmail, $currentPassword) ); } /** * @magentoApiDataFixture Magento/Customer/_files/two_customers.php */ public function testUpdateEmailIfEmailAlreadyExists() { $this->expectException(Exception::class); $this->expectExceptionMessage( 'A customer with the same email address already exists in an associated website.' ); $currentEmail = 'customer@example.com'; $currentPassword = 'password'; $existedEmail = 'customer_two@example.com'; $query = <<graphQlMutation($query, [], '', $this->getCustomerAuthHeaders($currentEmail, $currentPassword)); } /** * Get customer authorization headers * * @param string $email * @param string $password * @return array * @throws AuthenticationException */ private function getCustomerAuthHeaders(string $email, string $password): array { $customerToken = $this->customerTokenService->createCustomerAccessToken($email, $password); return ['Authorization' => 'Bearer ' . $customerToken]; } }