Skip to content

Commit f96160d

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

22 files changed

+66
-594
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@
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;
27-
use Magento\Checkout\Test\Unit\Helper\SessionQuoteLastAddedProductTestHelper;
2828
use PHPUnit\Framework\Attributes\DataProvider;
2929
use Magento\Catalog\Model\ResourceModel\Product\Collection as ProductCollection;
3030

app/code/Magento/Checkout/Test/Unit/Block/Shipping/PriceTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
use Magento\Store\Model\Store;
1616
use PHPUnit\Framework\MockObject\MockObject;
1717
use PHPUnit\Framework\TestCase;
18-
use Magento\Checkout\Test\Unit\Helper\RatePriceTestHelper;
1918

2019
class PriceTest extends TestCase
2120
{
@@ -58,7 +57,9 @@ public function testGetShippingPrice()
5857
$shippingPrice = 5;
5958
$convertedPrice = "$5";
6059

61-
$shippingRateMock = new RatePriceTestHelper($shippingPrice);
60+
$rateReflection = new \ReflectionClass(Rate::class);
61+
$shippingRateMock = $rateReflection->newInstanceWithoutConstructor();
62+
$shippingRateMock->setData('price', $shippingPrice);
6263

6364
$this->priceCurrency->expects($this->once())
6465
->method('convertAndFormat')

app/code/Magento/Checkout/Test/Unit/Controller/Account/CreateTest.php

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,16 @@
88
namespace Magento\Checkout\Test\Unit\Controller\Account;
99

1010
use Magento\Checkout\Controller\Account\Create;
11-
use Magento\Checkout\Model\Session;
12-
use Magento\Customer\Api\Data\CustomerInterface;
1311
use Magento\Framework\App\Action\Context;
1412
use Magento\Framework\Controller\ResultFactory;
15-
use Magento\Framework\Controller\ResultInterface;
1613
use Magento\Framework\Message\ManagerInterface;
1714
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
1815
use Magento\Framework\Test\Unit\Helper\ResultJsonTestHelper;
1916
use Magento\Sales\Api\OrderCustomerManagementInterface;
2017
use Magento\Checkout\Test\Unit\Helper\SessionOrderIdTestHelper;
2118
use PHPUnit\Framework\MockObject\MockObject;
2219
use PHPUnit\Framework\TestCase;
20+
use Magento\Customer\Model\Session as CustomerSession;
2321

2422
/**
2523
* Shopping cart edit tests
@@ -57,15 +55,15 @@ class CreateTest extends TestCase
5755
private $resultFactory;
5856

5957
/**
60-
* @var ResultInterface|MockObject
58+
* @var ResultJsonTestHelper
6159
*/
6260
private $resultPage;
6361

6462
protected function setUp(): void
6563
{
6664
$objectManagerHelper = new ObjectManager($this);
6765
$this->checkoutSession = new SessionOrderIdTestHelper();
68-
$this->customerSession = $this->createMock(\Magento\Customer\Model\Session::class);
66+
$this->customerSession = $this->createMock(CustomerSession::class);
6967
$this->orderCustomerService = $this->createMock(OrderCustomerManagementInterface::class);
7068
$this->messageManager = $this->createMock(ManagerInterface::class);
7169

@@ -111,11 +109,10 @@ public function testExecute()
111109
{
112110
$this->customerSession->expects($this->once())->method('isLoggedIn')->willReturn(false);
113111
$this->checkoutSession->setLastOrderId(100);
114-
$customer = $this->createMock(CustomerInterface::class);
115112
$this->orderCustomerService->expects($this->once())
116113
->method('create')
117114
->with(100)
118-
->willReturn($customer);
115+
->willReturn(new \stdClass());
119116

120117
$resultJson = '{"errors":"false", "message":"A letter with further instructions will be sent to your email."}';
121118
$this->resultFactory->expects($this->once())

app/code/Magento/Checkout/Test/Unit/CustomerData/CartTest.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
use Magento\Store\Model\System\Store;
2323
use PHPUnit\Framework\MockObject\MockObject;
2424
use PHPUnit\Framework\TestCase;
25-
use Magento\Checkout\Test\Unit\Helper\SubtotalValueObjectTestHelper;
2625
use Magento\Quote\Test\Unit\Helper\QuoteFixtureTestHelper;
2726
use Magento\Quote\Test\Unit\Helper\QuoteItemTestHelper;
2827
use Magento\Store\Test\Unit\Helper\StoreWebsiteIdTestHelper;
@@ -111,7 +110,7 @@ public function testGetSectionData()
111110
$shortcutButtonsHtml = '<span>Buttons</span>';
112111
$websiteId = 100;
113112

114-
$subtotalMock = new SubtotalValueObjectTestHelper($subtotalValue);
113+
$subtotalMock = new DataObject(['value' => $subtotalValue]);
115114
$totals = ['subtotal' => $subtotalMock];
116115

117116
$quoteMock = new QuoteFixtureTestHelper();
@@ -186,7 +185,7 @@ public function testGetSectionDataWithCompositeProduct()
186185
$productRewrite = [$productId => ['rewrite' => 'product']];
187186
$itemData = ['item' => 'data'];
188187
$shortcutButtonsHtml = '<span>Buttons</span>';
189-
$subtotalMock = new SubtotalValueObjectTestHelper($subtotalValue);
188+
$subtotalMock = new DataObject(['value' => $subtotalValue]);
190189
$totals = ['subtotal' => $subtotalMock];
191190

192191
$quoteMock = new QuoteFixtureTestHelper();

app/code/Magento/Checkout/Test/Unit/Helper/BaseAmountsDataObjectTestHelper.php

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

app/code/Magento/Checkout/Test/Unit/Helper/CartTest.php

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
use PHPUnit\Framework\Attributes\DataProvider;
1111
use Magento\Catalog\Model\Product;
1212
use Magento\Checkout\Helper\Cart;
13-
use Magento\Catalog\Test\Unit\Helper\ProductTestHelper;
1413
use Magento\Framework\App\Action\Action;
1514
use Magento\Framework\App\Helper\Context;
1615
use Magento\Framework\App\Request\Http;
@@ -148,10 +147,10 @@ public function testAddUrlWithUencPlaceholder()
148147
$productEntityId = 1;
149148
$storeId = 1;
150149
$isRequestSecure = false;
151-
$productMock = new ProductTestHelper(
152-
$productEntityId,
153-
new DataObject(['store_id' => $storeId])
154-
);
150+
$product = new DataObject([
151+
'entity_id' => $productEntityId,
152+
'url_data_object' => new DataObject(['store_id' => $storeId])
153+
]);
155154

156155
$this->requestMock->method('getRouteName')->willReturn('checkout');
157156
$this->requestMock->method('getControllerName')->willReturn('cart');
@@ -168,7 +167,7 @@ public function testAddUrlWithUencPlaceholder()
168167
];
169168

170169
$this->urlBuilderMock->expects($this->once())->method('getUrl')->with('checkout/cart/add', $params);
171-
$this->helper->getAddUrl($productMock, ['custom_param' => 'value', 'useUencPlaceholder' => 1]);
170+
$this->helper->getAddUrl($product, ['custom_param' => 'value', 'useUencPlaceholder' => 1]);
172171
}
173172

174173
public function testGetIsVirtualQuote()
@@ -194,10 +193,10 @@ public function testGetAddUrl()
194193
$productEntityId = 1;
195194
$storeId = 1;
196195
$isRequestSecure = false;
197-
$productMock = new ProductTestHelper(
198-
$productEntityId,
199-
new DataObject(['store_id' => $storeId])
200-
);
196+
$product = new DataObject([
197+
'entity_id' => $productEntityId,
198+
'url_data_object' => new DataObject(['store_id' => $storeId])
199+
]);
201200

202201
$currentUrl = 'http://www.example.com/';
203202
$this->urlBuilderMock->method('getCurrentUrl')->willReturn($currentUrl);
@@ -217,7 +216,7 @@ public function testGetAddUrl()
217216
];
218217

219218
$this->urlBuilderMock->expects($this->once())->method('getUrl')->with('checkout/cart/add', $params);
220-
$this->helper->getAddUrl($productMock, ['custom_param' => 'value']);
219+
$this->helper->getAddUrl($product, ['custom_param' => 'value']);
221220
}
222221

223222
/**

app/code/Magento/Checkout/Test/Unit/Helper/CheckoutSessionTestHelper.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ class CheckoutSessionTestHelper extends Session
1616
{
1717
/** @var array */
1818
private array $testData = [];
19+
1920
/**
2021
* Constructor intentionally empty to skip parent dependencies.
2122
*/

app/code/Magento/Checkout/Test/Unit/Helper/DataTest.php

Lines changed: 34 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,6 @@
1818
use Magento\Store\Model\StoreManagerInterface;
1919
use PHPUnit\Framework\MockObject\MockObject;
2020
use PHPUnit\Framework\TestCase;
21-
use Magento\Checkout\Test\Unit\Helper\StoreFormatPriceTestHelper;
22-
use Magento\Checkout\Test\Unit\Helper\QtyOneDataObjectTestHelper;
23-
use Magento\Checkout\Test\Unit\Helper\QtyFalseQtyOrderedDataObjectTestHelper;
24-
use Magento\Checkout\Test\Unit\Helper\BaseAmountsDataObjectTestHelper;
25-
use Magento\Checkout\Test\Unit\Helper\ItemPriceInclTaxFixedTestHelper;
26-
use Magento\Checkout\Test\Unit\Helper\ItemPriceInclTaxContextTestHelper;
27-
use Magento\Checkout\Test\Unit\Helper\RowTotalInclTaxFixedTestHelper;
28-
use Magento\Checkout\Test\Unit\Helper\SubtotalInclTaxNegativeTestHelper;
2921

3022
/**
3123
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
@@ -175,7 +167,7 @@ public function testFormatPrice()
175167
{
176168
$price = 5.5;
177169
$quoteMock = $this->createMock(Quote::class);
178-
$storeMock = new StoreFormatPriceTestHelper();
170+
$storeMock = $this->createMock(Store::class);
179171
$this->checkoutSession->expects($this->once())->method('getQuote')->willReturn($quoteMock);
180172
$quoteMock->expects($this->once())->method('getStore')->willReturn($storeMock);
181173
$this->priceCurrency->expects($this->once())->method('format')->willReturn('5.5');
@@ -225,8 +217,8 @@ public function testIsCustomerMustBeLogged()
225217

226218
public function testGetPriceInclTax()
227219
{
228-
$itemMock = new ItemPriceInclTaxFixedTestHelper(5.5);
229-
$this->assertEquals(5.5, $this->helper->getPriceInclTax($itemMock));
220+
$item = new DataObject(['price_incl_tax' => 5.5]);
221+
$this->assertEquals(5.5, $this->helper->getPriceInclTax($item));
230222
}
231223

232224
public function testGetPriceInclTaxWithoutTax()
@@ -246,7 +238,12 @@ public function testGetPriceInclTaxWithoutTax()
246238
'priceCurrency' => $this->priceCurrency,
247239
]
248240
);
249-
$itemMock = new ItemPriceInclTaxContextTestHelper($qty, $taxAmount, $discountTaxCompensation, $rowTotal);
241+
$itemMock = new DataObject([
242+
'qty' => $qty,
243+
'tax_amount' => $taxAmount,
244+
'discount_tax_compensation' => $discountTaxCompensation,
245+
'row_total' => $rowTotal,
246+
]);
250247
$this->priceCurrency->expects($this->once())->method('round')->with($roundPrice)->willReturn($roundPrice);
251248
$this->assertEquals($expected, $helper->getPriceInclTax($itemMock));
252249
}
@@ -255,7 +252,7 @@ public function testGetSubtotalInclTax()
255252
{
256253
$rowTotalInclTax = 5.5;
257254
$expected = 5.5;
258-
$itemMock = new RowTotalInclTaxFixedTestHelper($rowTotalInclTax);
255+
$itemMock = new DataObject(['row_total_incl_tax' => $rowTotalInclTax]);
259256
$this->assertEquals($expected, $this->helper->getSubtotalInclTax($itemMock));
260257
}
261258

@@ -265,7 +262,11 @@ public function testGetSubtotalInclTaxNegative()
265262
$discountTaxCompensation = 1;
266263
$rowTotal = 15;
267264
$expected = 17;
268-
$itemMock = new SubtotalInclTaxNegativeTestHelper($taxAmount, $discountTaxCompensation, $rowTotal);
265+
$itemMock = new DataObject([
266+
'tax_amount' => $taxAmount,
267+
'discount_tax_compensation' => $discountTaxCompensation,
268+
'row_total' => $rowTotal,
269+
]);
269270
$this->assertEquals($expected, $this->helper->getSubtotalInclTax($itemMock));
270271
}
271272

@@ -280,7 +281,12 @@ public function testGetBasePriceInclTaxWithoutQty()
280281
'priceCurrency' => $this->priceCurrency,
281282
]
282283
);
283-
$itemMock = new QtyOneDataObjectTestHelper();
284+
$itemMock = new DataObject([
285+
'qty' => 1,
286+
'tax_amount' => 0,
287+
'discount_tax_compensation' => 0,
288+
'row_total' => 0,
289+
]);
284290
$this->priceCurrency->expects($this->once())->method('round');
285291
$helper->getPriceInclTax($itemMock);
286292
}
@@ -296,15 +302,25 @@ public function testGetBasePriceInclTax()
296302
'priceCurrency' => $this->priceCurrency,
297303
]
298304
);
299-
$itemMock = new QtyFalseQtyOrderedDataObjectTestHelper();
305+
$itemMock = new DataObject([
306+
'qty' => false,
307+
'qty_ordered' => 1,
308+
'base_tax_amount' => 0,
309+
'base_discount_tax_compensation' => 0,
310+
'base_row_total' => 0,
311+
]);
300312
$this->priceCurrency->expects($this->once())->method('round');
301313
$helper->getBasePriceInclTax($itemMock);
302314
}
303315

304316
public function testGetBaseSubtotalInclTax()
305317
{
306-
$itemMock = new BaseAmountsDataObjectTestHelper();
307-
$this->helper->getBaseSubtotalInclTax($itemMock);
318+
$item = new DataObject([
319+
'base_tax_amount' => 0,
320+
'base_discount_tax_compensation' => 0,
321+
'base_row_total' => 0,
322+
]);
323+
$this->helper->getBaseSubtotalInclTax($item);
308324
}
309325

310326
public function testIsAllowedGuestCheckoutWithoutStore()

0 commit comments

Comments
 (0)