Skip to content

Commit 97607cd

Browse files
committed
Merge remote-tracking branch 'adobe-commerce-tier-4/ACP2E-3942' into PR_2025_06_12_muntianu
2 parents 97fda5e + cd2fc8f commit 97607cd

File tree

2 files changed

+59
-3
lines changed

2 files changed

+59
-3
lines changed

app/code/Magento/QuoteGraphQl/Model/Cart/GetCartForCheckout.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
3+
* Copyright 2022 Adobe
4+
* All Rights Reserved.
55
*/
66
declare(strict_types=1);
77

@@ -57,7 +57,7 @@ public function execute(string $cartHash, ?int $customerId, int $storeId): Quote
5757
try {
5858
$cart = $this->getCartForUser->execute($cartHash, $customerId, $storeId);
5959
} catch (NoSuchEntityException $e) {
60-
throw new GraphQlNoSuchEntityException(__($e->getMessage()), $e);
60+
throw new GraphQlNoSuchEntityException(__($e->getMessage()), $e, $e->getCode());
6161
}
6262
$this->checkoutAllowance->execute($cart);
6363

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?php
2+
/**
3+
* Copyright 2025 Adobe
4+
* All Rights Reserved.
5+
*/
6+
7+
declare(strict_types=1);
8+
9+
namespace Magento\QuoteGraphQl\Test\Unit\Model\Cart;
10+
11+
use Magento\Framework\GraphQl\Exception\GraphQlAuthorizationException;
12+
use Magento\Framework\GraphQl\Exception\GraphQlInputException;
13+
use Magento\QuoteGraphQl\Model\Cart\GetCartForCheckout;
14+
use Magento\QuoteGraphQl\Model\Cart\GetCartForUser;
15+
use Magento\QuoteGraphQl\Model\Cart\CheckCartCheckoutAllowance;
16+
use Magento\Framework\Exception\NoSuchEntityException;
17+
use Magento\Framework\GraphQl\Exception\GraphQlNoSuchEntityException;
18+
use PHPUnit\Framework\MockObject\Exception;
19+
use PHPUnit\Framework\TestCase;
20+
21+
class GetCartForCheckoutTest extends TestCase
22+
{
23+
/**
24+
* Verifies that when GetCartForUser::execute throws a NoSuchEntityException with a specific code,
25+
* GetCartForCheckout::execute rethrows it as a GraphQlNoSuchEntityException, preserving the original
26+
* exception message and code.
27+
*
28+
* @return void
29+
* @throws GraphQlNoSuchEntityException
30+
* @throws GraphQlAuthorizationException
31+
* @throws GraphQlInputException
32+
* @throws Exception
33+
*/
34+
public function testExecuteThrowsGraphQlNoSuchEntityExceptionWithOriginalCode()
35+
{
36+
$cartHash = 'test_hash';
37+
$customerId = 1;
38+
$storeId = 2;
39+
$originalCode = 1234;
40+
$originalMessage = 'Cart not found';
41+
42+
$getCartForUser = $this->createMock(GetCartForUser::class);
43+
$getCartForUser->method('execute')
44+
->willThrowException(new NoSuchEntityException(__($originalMessage), null, $originalCode));
45+
46+
$checkoutAllowance = $this->createMock(CheckCartCheckoutAllowance::class);
47+
48+
$getCartForCheckout = new GetCartForCheckout($checkoutAllowance, $getCartForUser);
49+
50+
$this->expectException(GraphQlNoSuchEntityException::class);
51+
$this->expectExceptionMessage($originalMessage);
52+
$this->expectExceptionCode($originalCode);
53+
54+
$getCartForCheckout->execute($cartHash, $customerId, $storeId);
55+
}
56+
}

0 commit comments

Comments
 (0)