Skip to content

Commit db42131

Browse files
committed
Merge remote-tracking branch 'origin/AC-15104_V1' into phpunit12_upgrade_and_compatible_with_phpunit10
2 parents 7b6aea2 + c344015 commit db42131

File tree

197 files changed

+6883
-3778
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

197 files changed

+6883
-3778
lines changed

app/code/Magento/Catalog/Test/Unit/Helper/ProductTestHelper.php

Lines changed: 146 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
namespace Magento\Catalog\Test\Unit\Helper;
99

1010
use Magento\Catalog\Model\Product;
11+
use Magento\Framework\DataObject;
1112

1213
/**
1314
* Test helper class for Catalog Product with custom methods
@@ -22,6 +23,12 @@ class ProductTestHelper extends Product
2223
*/
2324
private $data = [];
2425

26+
/** @var int */
27+
private $id;
28+
29+
/** @var DataObject|null */
30+
private $urlDataObject;
31+
2532
/**
2633
* @var bool
2734
*/
@@ -48,9 +55,12 @@ class ProductTestHelper extends Product
4855
/**
4956
* Skip parent constructor to avoid dependencies
5057
*/
51-
public function __construct()
52-
{
53-
// Initialize $_data to prevent "The resource isn't set" errors
58+
public function __construct(
59+
$id = 0,
60+
?DataObject $urlDataObject = null
61+
) {
62+
$this->id = (int)$id;
63+
$this->urlDataObject = $urlDataObject;
5464
$this->_data = [];
5565
}
5666

@@ -125,7 +135,7 @@ protected function getCustomAttributesCodes()
125135
*/
126136
public function getId()
127137
{
128-
return $this->data['id'] ?? null;
138+
return $this->id ?? null;
129139
}
130140

131141
/**
@@ -1203,7 +1213,7 @@ public function setAssociatedProductIds(array $ids): self
12031213
$this->data['associated_product_ids'] = $ids;
12041214
return $this;
12051215
}
1206-
1216+
12071217
/**
12081218
* Override getTierPrice to prevent null errors
12091219
*
@@ -1246,7 +1256,11 @@ public function setMediaGalleryImages($images): self
12461256
*/
12471257
public function getTaxClassId()
12481258
{
1249-
return $this->data['tax_class_id'] ?? null;
1259+
if (isset($this->data['tax_class_id'])) {
1260+
return $this->data['tax_class_id'];
1261+
}
1262+
$productData = $this->data['product_data'] ?? [];
1263+
return $productData['tax_class_id'] ?? null;
12501264
}
12511265

12521266
/**
@@ -1427,4 +1441,130 @@ public function getDownloadableLinks()
14271441
{
14281442
return $this->data['downloadable_links'] ?? [];
14291443
}
1444+
1445+
/**
1446+
* Get cart qty for tests.
1447+
*
1448+
* @return mixed
1449+
*/
1450+
public function getCartQty()
1451+
{
1452+
return $this->getData('cart_qty');
1453+
}
1454+
1455+
/**
1456+
* Return stick within parent flag from internal data.
1457+
*
1458+
* @return mixed
1459+
*/
1460+
public function getStickWithinParent()
1461+
{
1462+
return $this->getData('stick_within_parent');
1463+
}
1464+
1465+
/**
1466+
* Set stick within parent flag for tests.
1467+
*
1468+
* @param mixed $flag
1469+
* @return $this
1470+
*/
1471+
public function setStickWithinParent($flag)
1472+
{
1473+
$this->setData('stick_within_parent', $flag);
1474+
return $this;
1475+
}
1476+
1477+
/**
1478+
* Get parent product id for tests.
1479+
*
1480+
* @return mixed
1481+
*/
1482+
public function getParentProductId()
1483+
{
1484+
return $this->getData('parent_product_id');
1485+
}
1486+
1487+
/**
1488+
* Set parent product id for tests.
1489+
*
1490+
* @param mixed $id
1491+
* @return $this
1492+
*/
1493+
public function setParentProductId($id)
1494+
{
1495+
$this->setData('parent_product_id', $id);
1496+
return $this;
1497+
}
1498+
1499+
/**
1500+
* Get stock item for tests.
1501+
*
1502+
* @return mixed
1503+
*/
1504+
public function getStockItem()
1505+
{
1506+
return $this->getData('stock_item');
1507+
}
1508+
1509+
/**
1510+
* Enable/disable super mode flag for tests.
1511+
*
1512+
* @param bool $flag
1513+
* @return $this
1514+
*/
1515+
public function setIsSuperMode($flag)
1516+
{
1517+
$this->setData('is_super_mode', (bool)$flag);
1518+
return $this;
1519+
}
1520+
1521+
1522+
/**
1523+
* Unset skip check required option flag for tests (no-op).
1524+
*
1525+
* @return $this
1526+
*/
1527+
public function unsSkipCheckRequiredOption()
1528+
{
1529+
// No-op for unit tests, callable method required for mocks
1530+
return $this;
1531+
}
1532+
1533+
/**
1534+
* @return bool
1535+
*/
1536+
public function isVisibleInSiteVisibility()
1537+
{
1538+
return false;
1539+
}
1540+
1541+
/**
1542+
* @param DataObject $data
1543+
* @return $this
1544+
*/
1545+
public function setUrlDataObject($data)
1546+
{
1547+
$this->urlDataObject = $data;
1548+
return $this;
1549+
}
1550+
1551+
/**
1552+
* Get URL data object.
1553+
*
1554+
* @return DataObject|null
1555+
*/
1556+
public function getUrlDataObject()
1557+
{
1558+
return $this->urlDataObject;
1559+
}
1560+
1561+
/**
1562+
* Check if URL data object exists.
1563+
*
1564+
* @return bool
1565+
*/
1566+
public function hasUrlDataObject()
1567+
{
1568+
return (bool)$this->urlDataObject;
1569+
}
14301570
}

app/code/Magento/Checkout/Test/Unit/Block/Cart/AbstractCartTest.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use Magento\Quote\Model\Quote\Address;
1818
use Magento\Sales\Block\Items\AbstractItems;
1919
use PHPUnit\Framework\TestCase;
20+
use PHPUnit\Framework\Attributes\DataProvider;
2021

2122
class AbstractCartTest extends TestCase
2223
{
@@ -31,10 +32,10 @@ protected function setUp(): void
3132
}
3233

3334
/**
34-
* @dataProvider getItemRendererDataProvider
3535
* @param string|null $type
3636
* @param string $expectedType
3737
*/
38+
#[DataProvider('getItemRendererDataProvider')]
3839
public function testGetItemRenderer($type, $expectedType)
3940
{
4041
$renderer = $this->createMock(RendererList::class);
@@ -110,8 +111,8 @@ public function testGetItemRendererThrowsExceptionForNonexistentRenderer()
110111
/**
111112
* @param array $expectedResult
112113
* @param bool $isVirtual
113-
* @dataProvider getTotalsCacheDataProvider
114114
*/
115+
#[DataProvider('getTotalsCacheDataProvider')]
115116
public function testGetTotalsCache($expectedResult, $isVirtual)
116117
{
117118
$totals = $isVirtual ? ['billing_totals'] : ['shipping_totals'];
@@ -121,8 +122,8 @@ public function testGetTotalsCache($expectedResult, $isVirtual)
121122
$checkoutSessionMock->expects($this->once())->method('getQuote')->willReturn($quoteMock);
122123

123124
$quoteMock->expects($this->once())->method('isVirtual')->willReturn($isVirtual);
124-
$quoteMock->expects($this->any())->method('getShippingAddress')->willReturn($addressMock);
125-
$quoteMock->expects($this->any())->method('getBillingAddress')->willReturn($addressMock);
125+
$quoteMock->method('getShippingAddress')->willReturn($addressMock);
126+
$quoteMock->method('getBillingAddress')->willReturn($addressMock);
126127
$addressMock->expects($this->once())->method('getTotals')->willReturn($totals);
127128

128129
/** @var \Magento\Checkout\Block\Cart\AbstractCart $model */

app/code/Magento/Checkout/Test/Unit/Block/Cart/CartTotalsProcessorTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class CartTotalsProcessorTest extends TestCase
2626

2727
protected function setUp(): void
2828
{
29-
$this->scopeConfig = $this->getMockForAbstractClass(ScopeConfigInterface::class);
29+
$this->scopeConfig = $this->createMock(ScopeConfigInterface::class);
3030
$this->model = new CartTotalsProcessor($this->scopeConfig);
3131
}
3232

app/code/Magento/Checkout/Test/Unit/Block/Cart/CrosssellTest.php

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,12 @@
2121
use Magento\Framework\EntityManager\EntityMetadataInterface;
2222
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
2323
use Magento\Store\Api\Data\StoreInterface;
24+
use Magento\Checkout\Test\Unit\Helper\SessionQuoteLastAddedProductTestHelper;
2425
use Magento\Store\Model\StoreManagerInterface;
2526
use PHPUnit\Framework\MockObject\MockObject;
2627
use PHPUnit\Framework\TestCase;
28+
use PHPUnit\Framework\Attributes\DataProvider;
29+
use Magento\Catalog\Model\ResourceModel\Product\Collection as ProductCollection;
2730

2831
/**
2932
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
@@ -78,11 +81,7 @@ protected function setUp(): void
7881
'storeManager' => $this->storeManager
7982
]
8083
);
81-
$this->checkoutSession = $this->getMockBuilder(Session::class)
82-
->addMethods(['getLastAddedProductId'])
83-
->onlyMethods(['getQuote'])
84-
->disableOriginalConstructor()
85-
->getMock();
84+
$this->checkoutSession = new SessionQuoteLastAddedProductTestHelper();
8685
$this->productRepository = $this->createMock(
8786
ProductRepositoryInterface::class
8887
);
@@ -108,12 +107,12 @@ protected function setUp(): void
108107
}
109108

110109
/**
111-
* @dataProvider getItemsDataProvider
112110
* @param array $productLinks
113111
* @param array $cartProductIds
114112
* @param int|null $lastAddedProductId
115113
* @param array $expected
116114
*/
115+
#[DataProvider('getItemsDataProvider')]
117116
public function testGetItems(
118117
array $productLinks,
119118
array $cartProductIds,
@@ -134,10 +133,8 @@ function ($product) {
134133
$cartProducts
135134
);
136135
$quote = new DataObject(['all_items' => $cartItems]);
137-
$this->checkoutSession->method('getQuote')
138-
->willReturn($quote);
139-
$this->checkoutSession->method('getLastAddedProductId')
140-
->willReturn($lastAddedProductId);
136+
$this->checkoutSession->setQuote($quote);
137+
$this->checkoutSession->setLastAddedProductId($lastAddedProductId);
141138
$this->productRepository->method('getById')
142139
->willReturnCallback(
143140
function ($id) {
@@ -337,7 +334,7 @@ function ($id) {
337334
*/
338335
private function createProductCollection(): MockObject
339336
{
340-
$productCollection = $this->createMock(\Magento\Catalog\Model\ResourceModel\Product\Collection::class);
337+
$productCollection = $this->createMock(ProductCollection::class);
341338
$entityMetadataInterface =$this->createMock(EntityMetadataInterface::class);
342339
$entityMetadataInterface->method('getLinkField')
343340
->willReturn('entity_id');

app/code/Magento/Checkout/Test/Unit/Block/Cart/GridTest.php

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,8 @@ protected function setUp(): void
8686
->onlyMethods(['create'])
8787
->getMock();
8888
$this->joinAttributeProcessorMock =
89-
$this->getMockBuilder(JoinProcessorInterface::class)
90-
->getMockForAbstractClass();
91-
$this->scopeConfigMock = $this->getMockBuilder(ScopeConfigInterface::class)
92-
->getMockForAbstractClass();
89+
$this->createMock(JoinProcessorInterface::class);
90+
$this->scopeConfigMock = $this->createMock(ScopeConfigInterface::class);
9391
$this->checkoutSessionMock = $this->getMockBuilder(Session::class)
9492
->disableOriginalConstructor()
9593
->getMock();
@@ -99,13 +97,12 @@ protected function setUp(): void
9997
->onlyMethods(['getAllVisibleItems', 'getItemsCount'])
10098
->disableOriginalConstructor()
10199
->getMock();
102-
$this->layoutMock = $this->getMockBuilder(LayoutInterface::class)
103-
->getMockForAbstractClass();
100+
$this->layoutMock = $this->createMock(LayoutInterface::class);
104101
$this->pagerBlockMock = $this->getMockBuilder(Pager::class)
105102
->disableOriginalConstructor()
106103
->getMock();
107-
$this->checkoutSessionMock->expects($this->any())->method('getQuote')->willReturn($this->quoteMock);
108-
$this->quoteMock->expects($this->any())->method('getAllVisibleItems')->willReturn([]);
104+
$this->checkoutSessionMock->method('getQuote')->willReturn($this->quoteMock);
105+
$this->quoteMock->method('getAllVisibleItems')->willReturn([]);
109106
$this->block = $objectManagerHelper->getObject(
110107
Grid::class,
111108
[
@@ -194,7 +191,7 @@ private function getMockItemsForGrid(): void
194191
->expects($this->once())
195192
->method('create')
196193
->willReturn($this->itemCollectionMock);
197-
$this->checkoutSessionMock->expects($this->any())->method('getQuote')->willReturn($this->quoteMock);
194+
$this->checkoutSessionMock->method('getQuote')->willReturn($this->quoteMock);
198195
$this->itemCollectionMock->expects($this->once())->method('setQuote')->with($this->quoteMock)->willReturnSelf();
199196
$this->itemCollectionMock
200197
->expects($this->once())
@@ -213,10 +210,8 @@ public function testGetItemsIfCustomItemsExists(): void
213210
$itemMock = $this->getMockBuilder(Item::class)
214211
->disableOriginalConstructor()
215212
->getMock();
216-
$storeManager = $this->getMockBuilder(StoreManagerInterface::class)
217-
->getMockForAbstractClass();
218-
$storeMock = $this->getMockBuilder(StoreInterface::class)
219-
->getMockForAbstractClass();
213+
$storeManager = $this->createMock(StoreManagerInterface::class);
214+
$storeMock = $this->createMock(StoreInterface::class);
220215
$storeManager->expects($this->once())->method('getStore')->willReturn($storeMock);
221216
$objectManagerHelper = new ObjectManagerHelper($this);
222217
$this->block = $objectManagerHelper->getObject(

app/code/Magento/Checkout/Test/Unit/Block/Cart/Item/Renderer/Actions/EditTest.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,7 @@ protected function setUp(): void
2929
{
3030
$objectManagerHelper = new ObjectManager($this);
3131

32-
$this->urlBuilderMock = $this->getMockBuilder(UrlInterface::class)
33-
->disableOriginalConstructor()
34-
->getMockForAbstractClass();
32+
$this->urlBuilderMock = $this->createMock(UrlInterface::class);
3533

3634
$this->model = $objectManagerHelper->getObject(
3735
Edit::class,

0 commit comments

Comments
 (0)