Skip to content

Commit db40e0b

Browse files
authored
ENGCOM-6063: Test coverage for exceptions in \Magento\CustomerGraphQl\Model\Customer\GetCustomer #994
2 parents de81a7f + a405259 commit db40e0b

File tree

2 files changed

+50
-2
lines changed

2 files changed

+50
-2
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,15 @@ public function execute(ContextInterface $context): CustomerInterface
7070

7171
try {
7272
$customer = $this->customerRepository->getById($currentUserId);
73+
// @codeCoverageIgnoreStart
7374
} catch (NoSuchEntityException $e) {
7475
throw new GraphQlNoSuchEntityException(
7576
__('Customer with id "%customer_id" does not exist.', ['customer_id' => $currentUserId]),
7677
$e
7778
);
7879
} catch (LocalizedException $e) {
7980
throw new GraphQlInputException(__($e->getMessage()));
81+
// @codeCoverageIgnoreEnd
8082
}
8183

8284
if (true === $this->authentication->isLocked($currentUserId)) {
@@ -85,8 +87,10 @@ public function execute(ContextInterface $context): CustomerInterface
8587

8688
try {
8789
$confirmationStatus = $this->accountManagement->getConfirmationStatus($currentUserId);
90+
// @codeCoverageIgnoreStart
8891
} catch (LocalizedException $e) {
8992
throw new GraphQlInputException(__($e->getMessage()));
93+
// @codeCoverageIgnoreEnd
9094
}
9195

9296
if ($confirmationStatus === AccountManagementInterface::ACCOUNT_CONFIRMATION_REQUIRED) {

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

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

88
namespace Magento\GraphQl\Customer;
99

10+
use Magento\Customer\Api\CustomerRepositoryInterface;
1011
use Magento\Customer\Model\CustomerAuthUpdate;
1112
use Magento\Customer\Model\CustomerRegistry;
1213
use Magento\Integration\Api\CustomerTokenServiceInterface;
@@ -30,13 +31,19 @@ class GetCustomerTest extends GraphQlAbstract
3031
*/
3132
private $customerAuthUpdate;
3233

34+
/**
35+
* @var CustomerRepositoryInterface
36+
*/
37+
private $customerRepository;
38+
3339
protected function setUp()
3440
{
3541
parent::setUp();
3642

3743
$this->customerTokenService = Bootstrap::getObjectManager()->get(CustomerTokenServiceInterface::class);
3844
$this->customerRegistry = Bootstrap::getObjectManager()->get(CustomerRegistry::class);
3945
$this->customerAuthUpdate = Bootstrap::getObjectManager()->get(CustomerAuthUpdate::class);
46+
$this->customerRepository = Bootstrap::getObjectManager()->get(CustomerRepositoryInterface::class);
4047
}
4148

4249
/**
@@ -57,7 +64,12 @@ public function testGetCustomer()
5764
}
5865
}
5966
QUERY;
60-
$response = $this->graphQlQuery($query, [], '', $this->getCustomerAuthHeaders($currentEmail, $currentPassword));
67+
$response = $this->graphQlQuery(
68+
$query,
69+
[],
70+
'',
71+
$this->getCustomerAuthHeaders($currentEmail, $currentPassword)
72+
);
6173

6274
$this->assertEquals(null, $response['customer']['id']);
6375
$this->assertEquals('John', $response['customer']['firstname']);
@@ -104,7 +116,39 @@ public function testGetCustomerIfAccountIsLocked()
104116
}
105117
}
106118
QUERY;
107-
$this->graphQlQuery($query, [], '', $this->getCustomerAuthHeaders($currentEmail, $currentPassword));
119+
$this->graphQlQuery(
120+
$query,
121+
[],
122+
'',
123+
$this->getCustomerAuthHeaders($currentEmail, $currentPassword)
124+
);
125+
}
126+
127+
/**
128+
* @magentoApiDataFixture Magento/Customer/_files/customer_confirmation_config_enable.php
129+
* @magentoApiDataFixture Magento/Customer/_files/customer.php
130+
* @expectedException \Exception
131+
* @expectedExceptionMessage This account isn't confirmed. Verify and try again.
132+
*/
133+
public function testAccountIsNotConfirmed()
134+
{
135+
$customerEmail = 'customer@example.com';
136+
$currentPassword = 'password';
137+
$headersMap = $this->getCustomerAuthHeaders($customerEmail, $currentPassword);
138+
$customer = $this->customerRepository->getById(1)->setConfirmation(
139+
\Magento\Customer\Api\AccountManagementInterface::ACCOUNT_CONFIRMATION_REQUIRED
140+
);
141+
$this->customerRepository->save($customer);
142+
$query = <<<QUERY
143+
query {
144+
customer {
145+
firstname
146+
lastname
147+
email
148+
}
149+
}
150+
QUERY;
151+
$this->graphQlQuery($query, [], '', $headersMap);
108152
}
109153

110154
/**

0 commit comments

Comments
 (0)