Skip to content

Commit a5267ec

Browse files
committed
AC-15104::[CE] PHPUnit 12: Upgrade Checkout & Cart Management related test cases
1 parent 83b868e commit a5267ec

File tree

11 files changed

+72
-305
lines changed

11 files changed

+72
-305
lines changed

app/code/Magento/Checkout/Test/Unit/Controller/Cart/UpdatePostTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,8 @@ class UpdatePostTest extends TestCase
8787
protected function setUp(): void
8888
{
8989
// Create mocks
90-
$this->requestMock = $this->getMockForAbstractClass(RequestInterface::class);
91-
$this->messageManagerMock = $this->getMockForAbstractClass(ManagerInterface::class);
90+
$this->requestMock = $this->createMock(RequestInterface::class);
91+
$this->messageManagerMock = $this->createMock(ManagerInterface::class);
9292
$this->quantityProcessorMock = $this->createMock(RequestQuantityProcessor::class);
9393
$this->cartMock = $this->createMock(Cart::class);
9494
$this->customerSessionMock = $this->createMock(CustomerSession::class);
@@ -137,9 +137,9 @@ private function createController(
137137

138138
$controller = new UpdatePost(
139139
$context,
140-
$this->getMockForAbstractClass(ScopeConfigInterface::class),
140+
$this->createMock(ScopeConfigInterface::class),
141141
$this->createMock(CheckoutSession::class),
142-
$this->getMockForAbstractClass(StoreManagerInterface::class),
142+
$this->createMock(StoreManagerInterface::class),
143143
$formKeyValidator,
144144
$this->cartMock,
145145
$this->quantityProcessorMock

app/code/Magento/Checkout/Test/Unit/Helper/ShippingMethodManagementDouble.php renamed to app/code/Magento/Checkout/Test/Unit/Helper/ShippingMethodManagementTestHelper.php

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,20 @@
88
namespace Magento\Checkout\Test\Unit\Helper;
99

1010
use Magento\Quote\Api\Data\EstimateAddressInterface;
11-
use Magento\Quote\Api\ShippingMethodManagementInterface as ApiShippingMethodManagementInterface;
12-
use Magento\Quote\Model\ShippingMethodManagementInterface as ModelShippingMethodManagementInterface;
11+
use Magento\Quote\Model\ShippingMethodManagement;
1312

1413
/**
15-
* Simple shipping method management double for unit tests.
14+
* Test helper for shipping method management used in unit tests.
15+
*
16+
* Extends the concrete ShippingMethodManagement while bypassing
17+
* the parent constructor and stubbing public methods used by tests.
1618
*/
17-
class ShippingMethodManagementDouble implements
18-
ApiShippingMethodManagementInterface,
19-
ModelShippingMethodManagementInterface
19+
class ShippingMethodManagementTestHelper extends ShippingMethodManagement
2020
{
21+
public function __construct()
22+
{
23+
// Skip parent constructor to avoid dependency graph
24+
}
2125
/**
2226
* @inheritDoc
2327
*/

app/code/Magento/Checkout/Test/Unit/Model/DefaultConfigProviderTest.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,8 @@
3333
use Magento\Quote\Api\CartItemRepositoryInterface as QuoteItemRepository;
3434
use Magento\Quote\Api\CartRepositoryInterface;
3535
use Magento\Quote\Api\CartTotalRepositoryInterface;
36-
use Magento\Quote\Api\Data\TotalsInterface;
3736
use Magento\Quote\Api\PaymentMethodManagementInterface;
3837
use Magento\Quote\Api\ShippingMethodManagementInterface as ShippingMethodManager;
39-
use Magento\Quote\Model\ShippingMethodManagementInterface as ModelShippingMethodManager;
4038
use Magento\Quote\Model\Quote;
4139
use Magento\Quote\Model\Quote\Address;
4240
use Magento\Quote\Model\QuoteIdMaskFactory;
@@ -46,6 +44,7 @@
4644
use PHPUnit\Framework\MockObject\MockObject;
4745
use PHPUnit\Framework\TestCase;
4846
use Magento\Framework\Escaper;
47+
use Magento\Checkout\Test\Unit\Helper\ShippingMethodManagementTestHelper;
4948
use Magento\Checkout\Test\Unit\Helper\TotalsInterfaceTestHelper;
5049

5150
/**
@@ -107,7 +106,7 @@ protected function setUp(): void
107106
$httpContext = $this->createMock(HttpContext::class);
108107
$quoteRepository = $this->createMock(CartRepositoryInterface::class);
109108
$quoteItemRepository = $this->createMock(QuoteItemRepository::class);
110-
$this->shippingMethodManager = new \Magento\Checkout\Test\Unit\Helper\ShippingMethodManagementDouble();
109+
$this->shippingMethodManager = new ShippingMethodManagementTestHelper();
111110
$configurationPool = $this->createMock(ConfigurationPool::class);
112111
$quoteIdMaskFactory = $this->createMock(QuoteIdMaskFactory::class);
113112
$localeFormat = $this->createMock(LocaleFormat::class);
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?php
2+
/**
3+
* Copyright 2025 Adobe
4+
* All Rights Reserved.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Quote\Test\Unit\Helper;
9+
10+
use Magento\Quote\Model\Quote;
11+
12+
/**
13+
* Test helper for Quote coupon code operations.
14+
*
15+
* Provides lightweight implementations of coupon code setters/getters
16+
* while bypassing the parent constructor for unit tests.
17+
*/
18+
class QuoteCouponTestHelper extends Quote
19+
{
20+
/**
21+
* Construct helper without invoking the parent constructor.
22+
*/
23+
public function __construct()
24+
{
25+
// Skip parent constructor
26+
}
27+
28+
/**
29+
* Set coupon code on the quote for testing.
30+
*
31+
* @param mixed $code
32+
* @return $this
33+
*/
34+
public function setCouponCode($code)
35+
{
36+
$this->setData('coupon_code', $code);
37+
return $this;
38+
}
39+
40+
/**
41+
* Get coupon code from the quote for testing.
42+
*
43+
* @return mixed
44+
*/
45+
public function getCouponCode()
46+
{
47+
return $this->getData('coupon_code');
48+
}
49+
}

app/code/Magento/Quote/Test/Unit/Helper/RateCollectorForAddressTestHelper.php

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

88
namespace Magento\Quote\Test\Unit\Helper;
99

10-
use Magento\Quote\Model\Quote\Address\RateCollectorInterface;
10+
use Magento\Shipping\Model\Shipping;
1111
use Magento\Quote\Model\Quote\Address\RateRequest;
1212

1313
/**
1414
* Minimal rate collector for Address tests providing collectRates() and getResult().
1515
*/
16-
class RateCollectorForAddressTestHelper implements RateCollectorInterface
16+
class RateCollectorForAddressTestHelper extends Shipping
1717
{
1818
/** @var mixed */
1919
private $result;
2020

21+
public function __construct()
22+
{
23+
// Skip parent constructor and dependencies
24+
}
25+
2126
/**
2227
* No-op collect that returns self for chaining.
2328
*

app/code/Magento/Quote/Test/Unit/Model/Cart/CartQuoteMagicDouble.php

Lines changed: 0 additions & 52 deletions
This file was deleted.

app/code/Magento/Quote/Test/Unit/Model/Cart/CartRateMagicDouble.php

Lines changed: 0 additions & 70 deletions
This file was deleted.

app/code/Magento/Quote/Test/Unit/Model/GuestCart/GuestCartQuoteIdMaskDouble.php

Lines changed: 0 additions & 63 deletions
This file was deleted.

app/code/Magento/Quote/Test/Unit/Model/Quote/OptionCodeDouble.php

Lines changed: 0 additions & 41 deletions
This file was deleted.

0 commit comments

Comments
 (0)