Skip to content

Commit aba7e20

Browse files
33383: apply suggestions
1 parent ab38512 commit aba7e20

File tree

3 files changed

+32
-45
lines changed

3 files changed

+32
-45
lines changed

app/code/Magento/CustomerGraphQl/Model/Customer/DeleteCustomer.php

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,13 @@
88
namespace Magento\CustomerGraphQl\Model\Customer;
99

1010
use Magento\Customer\Api\CustomerRepositoryInterface;
11+
use Magento\Customer\Api\Data\CustomerInterface;
1112
use Magento\Framework\Exception\LocalizedException;
12-
use Magento\Framework\Exception\NoSuchEntityException;
1313
use Magento\Framework\GraphQl\Exception\GraphQlInputException;
1414
use Magento\Framework\GraphQl\Exception\GraphQlNoSuchEntityException;
15-
use Magento\GraphQl\Model\Query\ContextInterface;
1615

1716
/**
18-
* Get customer
17+
* Delete customer
1918
*/
2019
class DeleteCustomer
2120
{
@@ -34,30 +33,15 @@ public function __construct(
3433
}
3534

3635
/**
37-
* Get customer
36+
* Delete customer
3837
*
39-
* @param ContextInterface $context
38+
* @param CustomerInterface
4039
* @return void
4140
* @throws GraphQlInputException
4241
* @throws GraphQlNoSuchEntityException
4342
*/
44-
public function execute(ContextInterface $context): void
43+
public function execute(CustomerInterface $customer): void
4544
{
46-
$currentUserId = $context->getUserId();
47-
48-
try {
49-
$customer = $this->customerRepository->getById($currentUserId);
50-
// @codeCoverageIgnoreStart
51-
} catch (NoSuchEntityException $e) {
52-
throw new GraphQlNoSuchEntityException(
53-
__('Customer with id "%customer_id" does not exist.', ['customer_id' => $currentUserId]),
54-
$e
55-
);
56-
} catch (LocalizedException $e) {
57-
throw new GraphQlInputException(__($e->getMessage()));
58-
// @codeCoverageIgnoreEnd
59-
}
60-
6145
try {
6246
$this->customerRepository->delete($customer);
6347
} catch (LocalizedException $e) {

app/code/Magento/CustomerGraphQl/Model/Resolver/DeleteCustomer.php

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
namespace Magento\CustomerGraphQl\Model\Resolver;
99

1010
use Magento\CustomerGraphQl\Model\Customer\DeleteCustomer as DeleteCustomerModel;
11+
use Magento\CustomerGraphQl\Model\Customer\GetCustomer;
1112
use Magento\Framework\GraphQl\Exception\GraphQlAuthorizationException;
1213
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
1314
use Magento\Framework\GraphQl\Config\Element\Field;
@@ -20,22 +21,32 @@
2021
*/
2122
class DeleteCustomer implements ResolverInterface
2223
{
24+
/**
25+
* @var GetCustomer
26+
*/
27+
private $getCustomer;
28+
2329
/**
2430
* @var DeleteCustomerModel
2531
*/
2632
private $deleteCustomer;
2733

28-
/** @var Registry */
34+
/**
35+
* @var Registry
36+
*/
2937
private $registry;
3038

3139
/**
40+
* @param GetCustomer $getCustomer
3241
* @param DeleteCustomerModel $deleteCustomer
3342
* @param Registry $registry
3443
*/
3544
public function __construct(
45+
GetCustomer $getCustomer,
3646
DeleteCustomerModel $deleteCustomer,
3747
Registry $registry
3848
) {
49+
$this->getCustomer = $getCustomer;
3950
$this->deleteCustomer = $deleteCustomer;
4051
$this->registry =$registry;
4152
}
@@ -60,7 +71,8 @@ public function resolve(
6071
$this->registry->unregister('isSecureArea');
6172
$this->registry->register('isSecureArea', true);
6273

63-
$this->deleteCustomer->execute($context);
74+
$customer = $this->getCustomer->execute($context);
75+
$this->deleteCustomer->execute($customer);
6476

6577
$this->registry->unregister('isSecureArea');
6678
$this->registry->register('isSecureArea', $isSecure);

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

Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
namespace Magento\GraphQl\Customer;
99

10-
use Magento\Customer\Api\CustomerRepositoryInterface;
1110
use Magento\Framework\Exception\AuthenticationException;
1211
use Magento\TestFramework\Helper\Bootstrap;
1312
use Magento\TestFramework\TestCase\GraphQlAbstract;
@@ -23,64 +22,56 @@ class DeleteCustomerTest extends GraphQlAbstract
2322
*/
2423
private $customerTokenService;
2524

26-
/**
27-
* @var CustomerRepositoryInterface
28-
*/
29-
private $customerRepository;
30-
31-
/**
32-
* @var LockCustomer
33-
*/
34-
private $lockCustomer;
35-
3625
/**
3726
* @inheritdoc
3827
*/
3928
protected function setUp(): void
4029
{
4130
parent::setUp();
4231
$this->customerTokenService = Bootstrap::getObjectManager()->get(CustomerTokenServiceInterface::class);
43-
$this->customerRepository = Bootstrap::getObjectManager()->get(CustomerRepositoryInterface::class);
44-
$this->lockCustomer = Bootstrap::getObjectManager()->get(LockCustomer::class);
4532
}
4633

4734
/**
35+
* Test deleting customer
36+
*
4837
* @magentoApiDataFixture Magento/Customer/_files/customer.php
4938
*/
50-
public function testDeleteCustomer()
39+
public function testDeleteCustomer(): void
5140
{
5241
$response = $this->graphQlMutation($this->getMutation(), [], '', $this->getHeaderMap());
5342
$this->assertArrayHasKey('deleteCustomer', $response);
5443
$this->assertTrue($response['deleteCustomer']);
5544
}
5645

5746
/**
47+
* Test deleting non authorized customer
5848
*/
59-
public function testDeleteCustomerIfUserIsNotAuthorized()
49+
public function testDeleteCustomerIfUserIsNotAuthorized(): void
6050
{
6151
$this->expectException(\Exception::class);
6252
$this->expectExceptionMessage('The current customer isn\'t authorized.');
6353
$this->graphQlMutation($this->getMutation());
6454
}
6555

6656
/**
67-
* @magentoApiDataFixture Magento/Customer/_files/customer.php
57+
* Test deleting locked customer
58+
*
59+
* @magentoApiDataFixture Magento/Customer/_files/locked_customer.php
6860
* @magentoApiDataFixture Magento/Customer/_files/customer_two_addresses.php
6961
*/
70-
public function testDeleteCustomerIfAccountIsLocked()
62+
public function testDeleteCustomerIfAccountIsLocked(): void
7163
{
72-
$this->lockCustomer->execute(1);
73-
$response = $this->graphQlMutation($this->getMutation(), [], '', $this->getHeaderMap());
74-
$this->assertArrayHasKey('deleteCustomer', $response);
75-
$this->assertTrue($response['deleteCustomer']);
64+
$this->expectException(\Exception::class);
65+
$this->expectExceptionMessage('The account sign-in was incorrect or your account is disabled temporarily. Please wait and try again later');
66+
$this->graphQlMutation($this->getMutation(), [], '', $this->getHeaderMap());
7667
}
7768

7869
/**
7970
* Retrieve deleteCustomer mutation
8071
*
8172
* @return string
8273
*/
83-
private function getMutation()
74+
private function getMutation(): string
8475
{
8576
return <<<MUTATION
8677
mutation {

0 commit comments

Comments
 (0)