Skip to content

Commit 98bd26f

Browse files
committed
AC-16072: PHPUnit 12: Upgrade SalesRules & other related test cases
1 parent e103aaa commit 98bd26f

File tree

27 files changed

+384
-419
lines changed

27 files changed

+384
-419
lines changed

app/code/Magento/InstantPurchase/Test/Unit/Block/ButtonTest.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use Magento\InstantPurchase\Model\Config;
1414
use Magento\Store\Api\Data\StoreInterface;
1515
use Magento\Store\Model\StoreManagerInterface;
16+
use PHPUnit\Framework\Attributes\DataProvider;
1617
use PHPUnit\Framework\MockObject\MockObject;
1718
use PHPUnit\Framework\TestCase;
1819

@@ -54,8 +55,8 @@ class ButtonTest extends TestCase
5455
protected function setUp(): void
5556
{
5657
$this->context = $this->createMock(Context::class);
57-
$this->storeManager = $this->getMockForAbstractClass(StoreManagerInterface::class);
58-
$this->store = $this->getMockForAbstractClass(StoreInterface::class);
58+
$this->storeManager = $this->createMock(StoreManagerInterface::class);
59+
$this->store = $this->createMock(StoreInterface::class);
5960

6061
$this->storeManager->expects($this->any())->method('getStore')
6162
->willReturn($this->store);
@@ -82,8 +83,8 @@ protected function setUp(): void
8283
* @param $currentStoreId
8384
* @param $isModuleEnabled
8485
* @param $expected
85-
* @dataProvider isEnabledDataProvider
8686
*/
87+
#[DataProvider('isEnabledDataProvider')]
8788
public function testIsEnabled($currentStoreId, $isModuleEnabled, $expected)
8889
{
8990
$this->store->expects($this->any())->method('getId')

app/code/Magento/InstantPurchase/Test/Unit/CustomerData/InstantPurchaseTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
use Magento\InstantPurchase\Model\Ui\ShippingMethodFormatter;
2020
use Magento\Store\Model\Store;
2121
use Magento\Store\Model\StoreManagerInterface;
22+
use PHPUnit\Framework\Attributes\DataProvider;
2223
use PHPUnit\Framework\MockObject\MockObject;
2324
use PHPUnit\Framework\TestCase;
2425

@@ -90,7 +91,7 @@ class InstantPurchaseTest extends TestCase
9091
protected function setUp(): void
9192
{
9293
$this->customerSession = $this->createMock(Session::class);
93-
$this->storeManager = $this->getMockForAbstractClass(StoreManagerInterface::class);
94+
$this->storeManager = $this->createMock(StoreManagerInterface::class);
9495
$this->instantPurchase = $this->createMock(InstantPurchaseModel::class);
9596
$this->paymentTokenFormatter = $this->createMock(PaymentTokenFormatter::class);
9697
$this->customerAddressesFormatter = $this->createMock(CustomerAddressesFormatter::class);
@@ -119,8 +120,8 @@ protected function setUp(): void
119120
* @param $isLogin
120121
* @param $isAvailable
121122
* @param $expected
122-
* @dataProvider getSectionDataProvider
123123
*/
124+
#[DataProvider('getSectionDataProvider')]
124125
public function testGetSectionData($isLogin, $isAvailable, $expected)
125126
{
126127
$this->customerSession->expects($this->any())->method('isLoggedIn')->willReturn($isLogin);

app/code/Magento/InstantPurchase/Test/Unit/Model/Ui/CustomerAddressesFormatterTest.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,16 @@
99

1010
use Magento\Customer\Model\Address;
1111
use Magento\Directory\Model\Country;
12+
use Magento\Framework\TestFramework\Unit\Helper\MockCreationTrait;
1213
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
1314
use Magento\InstantPurchase\Model\Ui\CustomerAddressesFormatter;
1415
use PHPUnit\Framework\MockObject\MockObject;
1516
use PHPUnit\Framework\TestCase;
1617

1718
class CustomerAddressesFormatterTest extends TestCase
1819
{
20+
use MockCreationTrait;
21+
1922
/**
2023
* @var CustomerAddressesFormatter|MockObject
2124
*/
@@ -35,11 +38,10 @@ protected function setUp(): void
3538
*/
3639
public function testFormat()
3740
{
38-
$addressMock = $this->getMockBuilder(Address::class)
39-
->addMethods(['getCity', 'getPostcode'])
40-
->onlyMethods(['getName', 'getStreetFull', 'getRegion', 'getCountryModel'])
41-
->disableOriginalConstructor()
42-
->getMock();
41+
$addressMock = $this->createPartialMockWithReflection(
42+
Address::class,
43+
['getCity', 'getPostcode', 'getName', 'getStreetFull', 'getRegion', 'getCountryModel']
44+
);
4345
$countryMock = $this->createMock(Country::class);
4446

4547
$countryMock->expects($this->any())->method('getName')->willReturn('USA');

app/code/Magento/Multishipping/Test/Unit/Block/Checkout/SuccessTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ protected function setUp(): void
4646
['getOrderIds']
4747
);
4848
$this->contextMock = $this->createMock(Context::class);
49-
$this->storeManagerMock = $this->getMockForAbstractClass(StoreManagerInterface::class);
49+
$this->storeManagerMock = $this->createMock(StoreManagerInterface::class);
5050

5151
$objectManager = new ObjectManager($this);
5252
$this->contextMock->expects($this->once())->method('getSession')->willReturn($this->sessionMock);

app/code/Magento/Multishipping/Test/Unit/Controller/Checkout/Address/NewShippingTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,14 @@ protected function setUp(): void
133133
);
134134
}
135135

136+
/**
137+
* Test execute method with different scenarios
138+
*
139+
* @param string $backUrl
140+
* @param string $shippingAddress
141+
* @param string $url
142+
* @return void
143+
*/
136144
#[DataProvider('executeDataProvider')]
137145
public function testExecute($backUrl, $shippingAddress, $url)
138146
{
@@ -174,6 +182,11 @@ public function testExecute($backUrl, $shippingAddress, $url)
174182
$this->controller->execute();
175183
}
176184

185+
/**
186+
* Data provider for testExecute
187+
*
188+
* @return array
189+
*/
177190
public static function executeDataProvider(): array
178191
{
179192
return [
@@ -182,6 +195,11 @@ public static function executeDataProvider(): array
182195
];
183196
}
184197

198+
/**
199+
* Test execute when customer address block does not exist
200+
*
201+
* @return void
202+
*/
185203
public function testExecuteWhenCustomerAddressBlockNotExist()
186204
{
187205
$this->stateMock

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,11 @@ protected function setUp(): void
6363
$this->scopeConfigMock = $context->getScopeConfig();
6464
}
6565

66+
/**
67+
* Test getting maximum quantity for multishipping
68+
*
69+
* @return void
70+
*/
6671
public function testGetMaximumQty()
6772
{
6873
$maximumQty = 10;
@@ -79,6 +84,18 @@ public function testGetMaximumQty()
7984
$this->assertEquals($maximumQty, $this->helper->getMaximumQty());
8085
}
8186

87+
/**
88+
* Test multishipping checkout availability
89+
*
90+
* @param bool $result
91+
* @param bool $quoteHasItems
92+
* @param bool $isMultiShipping
93+
* @param bool $hasItemsWithDecimalQty
94+
* @param bool $validateMinimumAmount
95+
* @param int $itemsSummaryQty
96+
* @param int $itemVirtualQty
97+
* @param int $maximumQty
98+
*/
8299
#[DataProvider('isMultishippingCheckoutAvailableDataProvider')]
83100
public function testIsMultishippingCheckoutAvailable(
84101
$result,
@@ -151,6 +168,11 @@ public function testIsMultishippingCheckoutAvailable(
151168
$this->assertEquals($result, $this->helper->isMultishippingCheckoutAvailable());
152169
}
153170

171+
/**
172+
* Data provider for testIsMultishippingCheckoutAvailable
173+
*
174+
* @return array
175+
*/
154176
public static function isMultishippingCheckoutAvailableDataProvider(): array
155177
{
156178
return [

app/code/Magento/Multishipping/Test/Unit/Model/Cart/MultishippingClearItemAddressTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,15 @@ protected function setUp(): void
7373
);
7474
}
7575

76+
/**
77+
* Test clearing address items in multishipping flow
78+
*
79+
* @param string $actionName
80+
* @param int $addressId
81+
* @param int $customerAddressId
82+
* @param bool $isMultiShippingAddresses
83+
* @return void
84+
*/
7685
#[DataProvider('getDataDataProvider')]
7786
public function testClearAddressItem(
7887
string $actionName,
@@ -142,6 +151,11 @@ public function testClearAddressItem(
142151
);
143152
}
144153

154+
/**
155+
* Data provider for testClearAddressItem
156+
*
157+
* @return array
158+
*/
145159
public static function getDataDataProvider(): array
146160
{
147161
return [

app/code/Magento/Multishipping/Test/Unit/Model/Checkout/Type/Multishipping/PlaceOrderPoolTest.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,17 @@
1919
*/
2020
class PlaceOrderPoolTest extends TestCase
2121
{
22+
/**
23+
* @param string $paymentProviderCode
24+
* @param PlaceOrderInterface[] $placeOrderList
25+
* @param \Closure $expectedResult
26+
* @return void
27+
*/
2228
#[DataProvider('getDataProvider')]
2329
public function testGet(string $paymentProviderCode, array $placeOrderList, $expectedResult)
2430
{
2531
$placeOrderList['payment_code'] = $placeOrderList['payment_code']($this);
26-
if($expectedResult != null) {
32+
if ($expectedResult != null) {
2733
$expectedResult = $expectedResult($this);
2834
}
2935
/** @var TMapFactory|MockObject $tMapFactory */

app/code/Magento/Multishipping/Test/Unit/Model/Checkout/Type/Multishipping/PluginTest.php

Lines changed: 20 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,16 @@
1515
use Magento\Multishipping\Model\Checkout\Type\Multishipping\Plugin;
1616
use Magento\Multishipping\Model\Checkout\Type\Multishipping\State;
1717
use Magento\Quote\Api\CartRepositoryInterface;
18+
use Magento\Framework\TestFramework\Unit\Helper\MockCreationTrait;
1819
use Magento\Quote\Model\Quote;
20+
use PHPUnit\Framework\Attributes\DataProvider;
1921
use PHPUnit\Framework\MockObject\MockObject;
2022
use PHPUnit\Framework\TestCase;
2123

2224
class PluginTest extends TestCase
2325
{
26+
use MockCreationTrait;
27+
2428
/**
2529
* @var MockObject
2630
*/
@@ -58,29 +62,19 @@ class PluginTest extends TestCase
5862

5963
protected function setUp(): void
6064
{
61-
$this->checkoutSessionMock = $this->getMockBuilder(Session::class)
62-
->addMethods(
63-
[
64-
'getCheckoutState',
65-
'setCheckoutState',
66-
'getMultiShippingAddressesFlag',
67-
'setMultiShippingAddressesFlag'
68-
]
69-
)
70-
->disableOriginalConstructor()
71-
->getMock();
72-
$this->cartRepositoryMock = $this->getMockBuilder(CartRepositoryInterface::class)
73-
->disableOriginalConstructor()
74-
->getMock();
75-
$this->requestMock = $this->getMockBuilder(RequestInterface::class)
76-
->disableOriginalConstructor()
77-
->getMock();
78-
$this->localeMock = $this->getMockBuilder(ResolverInterface::class)
79-
->disableOriginalConstructor()
80-
->getMock();
81-
$this->quantityProcessorMock = $this->getMockBuilder(RequestQuantityProcessor::class)
82-
->disableOriginalConstructor()
83-
->getMock();
65+
$this->checkoutSessionMock = $this->createPartialMockWithReflection(
66+
Session::class,
67+
[
68+
'getCheckoutState',
69+
'setCheckoutState',
70+
'getMultiShippingAddressesFlag',
71+
'setMultiShippingAddressesFlag'
72+
]
73+
);
74+
$this->cartRepositoryMock = $this->createMock(CartRepositoryInterface::class);
75+
$this->requestMock = $this->createMock(RequestInterface::class);
76+
$this->localeMock = $this->createMock(ResolverInterface::class);
77+
$this->quantityProcessorMock = $this->createMock(RequestQuantityProcessor::class);
8478
$this->cartMock = $this->createMock(Cart::class);
8579
$this->model = new Plugin(
8680
$this->checkoutSessionMock,
@@ -114,8 +108,9 @@ public function testBeforeInitCaseFalse()
114108
* @param float $itemInitialQuantity
115109
* @param array $params
116110
* @param bool $multipleShippingAddressesFlag
117-
* @dataProvider getDataDataProvider
111+
* @return void
118112
*/
113+
#[DataProvider('getDataDataProvider')]
119114
public function testAfterSave(
120115
float $itemInitialQuantity,
121116
array $params,
@@ -158,7 +153,7 @@ public function testAfterSave(
158153
/**
159154
* @return array
160155
*/
161-
public static function getDataDataProvider()
156+
public static function getDataDataProvider(): array
162157
{
163158
return [
164159
'test with multi shipping addresses' => [10.0, ['qty' => '5'], true],

0 commit comments

Comments
 (0)