Skip to content

Commit a7bf9f7

Browse files
Merge remote-tracking branch 'origin/AC-16072-SalesRule-Order' into Arrows-AC-14808-v4
2 parents f195965 + 31ecdb0 commit a7bf9f7

File tree

85 files changed

+1378
-1578
lines changed

Some content is hidden

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

85 files changed

+1378
-1578
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/Address/SelectTest.php

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
2020
use Magento\Multishipping\Block\Checkout\Address\Select;
2121
use Magento\Multishipping\Model\Checkout\Type\Multishipping;
22+
use PHPUnit\Framework\Attributes\DataProvider;
2223
use PHPUnit\Framework\MockObject\MockObject;
2324
use PHPUnit\Framework\TestCase;
2425

@@ -82,12 +83,12 @@ protected function setUp(): void
8283
$this->objectManager = new ObjectManager($this);
8384
$this->multishippingMock =
8485
$this->createMock(Multishipping::class);
85-
$this->addressMock = $this->getMockForAbstractClass(AddressInterface::class);
86-
$this->customerMock = $this->getMockForAbstractClass(CustomerInterface::class);
86+
$this->addressMock = $this->createMock(AddressInterface::class);
87+
$this->customerMock = $this->createMock(CustomerInterface::class);
8788
$this->filterBuilderMock = $this->createMock(FilterBuilder::class);
8889
$this->searchCriteriaBuilderMock =
8990
$this->createMock(SearchCriteriaBuilder::class);
90-
$this->addressRepositoryMock = $this->getMockForAbstractClass(AddressRepositoryInterface::class);
91+
$this->addressRepositoryMock = $this->createMock(AddressRepositoryInterface::class);
9192
$this->filterMock = $this->createMock(Filter::class);
9293
$this->searchCriteriaMock = $this->createMock(SearchCriteria::class);
9394
$this->block = $this->objectManager->getObject(
@@ -104,8 +105,8 @@ protected function setUp(): void
104105
/**
105106
* @param string $id
106107
* @param bool $expectedValue
107-
* @dataProvider isDefaultAddressDataProvider
108108
*/
109+
#[DataProvider('isDefaultAddressDataProvider')]
109110
public function testIsAddressDefaultBilling($id, $expectedValue)
110111
{
111112
$this->addressMock->expects($this->once())->method('getId')->willReturn(1);
@@ -117,8 +118,8 @@ public function testIsAddressDefaultBilling($id, $expectedValue)
117118
/**
118119
* @param string $id
119120
* @param bool $expectedValue
120-
* @dataProvider isDefaultAddressDataProvider
121121
*/
122+
#[DataProvider('isDefaultAddressDataProvider')]
122123
public function testIsAddressDefaultShipping($id, $expectedValue)
123124
{
124125
$this->addressMock->expects($this->once())->method('getId')->willReturn(1);
@@ -140,7 +141,7 @@ public static function isDefaultAddressDataProvider()
140141

141142
public function testGetAddress()
142143
{
143-
$searchResultMock = $this->getMockForAbstractClass(AddressSearchResultsInterface::class);
144+
$searchResultMock = $this->createMock(AddressSearchResultsInterface::class);
144145
$this->multishippingMock->expects($this->once())->method('getCustomer')->willReturn($this->customerMock);
145146
$this->customerMock->expects($this->once())->method('getId')->willReturn(1);
146147
$this->filterBuilderMock->expects($this->once())->method('setField')->with('parent_id')->willReturnSelf();
@@ -188,7 +189,7 @@ public function testGetAlreadyExistingAddress()
188189

189190
public function testGetAddressWhenItNotExistInCustomer()
190191
{
191-
$searchResultMock = $this->getMockForAbstractClass(AddressSearchResultsInterface::class);
192+
$searchResultMock = $this->createMock(AddressSearchResultsInterface::class);
192193
$this->multishippingMock->expects($this->once())->method('getCustomer')->willReturn($this->customerMock);
193194
$this->customerMock->expects($this->once())->method('getId')->willReturn(1);
194195
$this->filterBuilderMock->expects($this->once())->method('setField')->with('parent_id')->willReturnSelf();

app/code/Magento/Multishipping/Test/Unit/Block/Checkout/Billing/ItemsTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class ItemsTest extends TestCase
2828
protected function setUp(): void
2929
{
3030
$objectManager = new ObjectManager($this);
31-
$this->urlBuilderMock = $this->getMockForAbstractClass(UrlInterface::class);
31+
$this->urlBuilderMock = $this->createMock(UrlInterface::class);
3232
$this->model = $objectManager->getObject(
3333
Items::class,
3434
[

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

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

1010
use Magento\Framework\App\Config\ScopeConfigInterface;
1111
use Magento\Framework\Pricing\PriceCurrencyInterface;
12+
use Magento\Framework\TestFramework\Unit\Helper\MockCreationTrait;
1213
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
1314
use Magento\Framework\UrlInterface;
1415
use Magento\Multishipping\Block\Checkout\Overview;
@@ -27,6 +28,7 @@
2728
*/
2829
class OverviewTest extends TestCase
2930
{
31+
use MockCreationTrait;
3032
/**
3133
* @var Overview
3234
*/
@@ -76,21 +78,18 @@ protected function setUp(): void
7678
{
7779
$objectManager = new ObjectManager($this);
7880

79-
$this->addressMock = $this->getMockBuilder(Address::class)
80-
->addMethods(['getAddressType'])
81-
->onlyMethods(['getShippingMethod', 'getShippingRateByCode', 'getAllVisibleItems', 'getTotals'])
82-
->disableOriginalConstructor()
83-
->getMock();
81+
$this->addressMock = $this->createPartialMockWithReflection(
82+
Address::class,
83+
['getAddressType', 'getShippingMethod', 'getShippingRateByCode', 'getAllVisibleItems', 'getTotals']
84+
);
8485

85-
$this->priceCurrencyMock =
86-
$this->getMockForAbstractClass(PriceCurrencyInterface::class);
86+
$this->priceCurrencyMock = $this->createMock(PriceCurrencyInterface::class);
8787
$this->totalsReaderMock = $this->createMock(TotalsReader::class);
8888
$this->totalsCollectorMock = $this->createMock(TotalsCollector::class);
89-
$this->checkoutMock =
90-
$this->createMock(Multishipping::class);
89+
$this->checkoutMock = $this->createMock(Multishipping::class);
9190
$this->quoteMock = $this->createMock(Quote::class);
92-
$this->urlBuilderMock = $this->getMockForAbstractClass(UrlInterface::class);
93-
$this->scopeConfigMock = $this->getMockForAbstractClass(ScopeConfigInterface::class);
91+
$this->urlBuilderMock = $this->createMock(UrlInterface::class);
92+
$this->scopeConfigMock = $this->createMock(ScopeConfigInterface::class);
9493
$this->model = $objectManager->getObject(
9594
Overview::class,
9695
[
@@ -137,10 +136,7 @@ public function testGetShippingAddressItems()
137136

138137
public function testGetShippingAddressTotals()
139138
{
140-
$totalMock = $this->getMockBuilder(Total::class)
141-
->addMethods(['getCode', 'setTitle'])
142-
->disableOriginalConstructor()
143-
->getMock();
139+
$totalMock = $this->createPartialMockWithReflection(Total::class, ['getCode', 'setTitle']);
144140
$totalMock->expects($this->once())->method('getCode')->willReturn('grand_total');
145141
$this->addressMock->expects($this->once())->method('getAddressType')->willReturn(Address::TYPE_BILLING);
146142
$this->addressMock->expects($this->once())->method('getTotals')->willReturn([$totalMock]);
@@ -151,10 +147,7 @@ public function testGetShippingAddressTotals()
151147

152148
public function testGetShippingAddressTotalsWithNotBillingAddress()
153149
{
154-
$totalMock = $this->getMockBuilder(Total::class)
155-
->addMethods(['getCode', 'setTitle'])
156-
->disableOriginalConstructor()
157-
->getMock();
150+
$totalMock = $this->createPartialMockWithReflection(Total::class, ['getCode', 'setTitle']);
158151
$totalMock->expects($this->once())->method('getCode')->willReturn('grand_total');
159152
$this->addressMock->expects($this->once())->method('getAddressType')->willReturn('not billing');
160153
$this->addressMock->expects($this->once())->method('getTotals')->willReturn([$totalMock]);
@@ -169,10 +162,7 @@ public function testGetShippingAddressTotalsWithNotBillingAddress()
169162
*/
170163
protected function getTotalsMock($address)
171164
{
172-
$totalMock = $this->getMockBuilder(Total::class)
173-
->addMethods(['getCode', 'setTitle'])
174-
->disableOriginalConstructor()
175-
->getMock();
165+
$totalMock = $this->createPartialMockWithReflection(Total::class, ['getCode', 'setTitle']);
176166
$totalsAddressMock = $this->createMock(\Magento\Quote\Model\Quote\Address\Total::class);
177167
$this->checkoutMock->expects($this->once())->method('getQuote')->willReturn($this->quoteMock);
178168
$this->totalsCollectorMock

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,11 @@ class ShippingTest extends TestCase
5050
protected function setUp(): void
5151
{
5252
$objectManager = new ObjectManager($this);
53-
$this->scopeConfigMock = $this->getMockForAbstractClass(ScopeConfigInterface::class);
53+
$this->scopeConfigMock = $this->createMock(ScopeConfigInterface::class);
5454
$this->multiShippingMock =
5555
$this->createMock(Multishipping::class);
5656
$this->priceCurrencyMock =
57-
$this->getMockForAbstractClass(PriceCurrencyInterface::class);
57+
$this->createMock(PriceCurrencyInterface::class);
5858
$this->taxHelperMock = $this->createMock(Data::class);
5959
$this->model = $objectManager->getObject(
6060
Shipping::class,

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

Lines changed: 8 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77

88
namespace Magento\Multishipping\Test\Unit\Block\Checkout;
99

10-
use Magento\Framework\Session\SessionManagerInterface;
10+
use Magento\Framework\Session\Generic;
11+
use Magento\Framework\TestFramework\Unit\Helper\MockCreationTrait;
1112
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
1213
use Magento\Framework\View\Element\Template\Context;
1314
use Magento\Multishipping\Block\Checkout\Success;
@@ -18,6 +19,7 @@
1819

1920
class SuccessTest extends TestCase
2021
{
22+
use MockCreationTrait;
2123
/**
2224
* @var Success
2325
*/
@@ -39,32 +41,12 @@ class SuccessTest extends TestCase
3941

4042
protected function setUp(): void
4143
{
42-
$this->sessionMock = $this->getMockBuilder(SessionManagerInterface::class)
43-
->addMethods(['getOrderIds'])
44-
->onlyMethods(
45-
[
46-
'start',
47-
'writeClose',
48-
'isSessionExists',
49-
'getSessionId',
50-
'getName',
51-
'setName',
52-
'destroy',
53-
'clearStorage',
54-
'getCookieDomain',
55-
'getCookiePath',
56-
'getCookieLifetime',
57-
'setSessionId',
58-
'regenerateId',
59-
'expireSessionCookie',
60-
'getSessionIdForHost',
61-
'isValidForHost',
62-
'isValidForPath'
63-
]
64-
)
65-
->getMockForAbstractClass();
44+
$this->sessionMock = $this->createPartialMockWithReflection(
45+
Generic::class,
46+
['getOrderIds']
47+
);
6648
$this->contextMock = $this->createMock(Context::class);
67-
$this->storeManagerMock = $this->getMockForAbstractClass(StoreManagerInterface::class);
49+
$this->storeManagerMock = $this->createMock(StoreManagerInterface::class);
6850

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

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

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
use Magento\Framework\View\Result\Page;
2121
use Magento\Multishipping\Controller\Checkout\Address\EditAddress;
2222
use Magento\Multishipping\Helper\Data;
23+
use Magento\Framework\TestFramework\Unit\Helper\MockCreationTrait;
2324
use Magento\Multishipping\Model\Checkout\Type\Multishipping;
2425
use PHPUnit\Framework\MockObject\MockObject;
2526
use PHPUnit\Framework\TestCase;
@@ -29,6 +30,8 @@
2930
*/
3031
class EditAddressTest extends TestCase
3132
{
33+
use MockCreationTrait;
34+
3235
/**
3336
* @var EditAddress
3437
*/
@@ -85,13 +88,9 @@ protected function setUp(): void
8588
$this->checkoutMock = $this->createMock(Multishipping::class);
8689
$this->titleMock = $this->createMock(Title::class);
8790
$this->layoutMock = $this->createMock(Layout::class);
88-
$this->viewMock = $this->getMockForAbstractClass(ViewInterface::class);
89-
$this->request = $this->getMockBuilder(RequestInterface::class)
90-
->disableOriginalConstructor()
91-
->getMockForAbstractClass();
92-
$response = $this->getMockBuilder(ResponseInterface::class)
93-
->disableOriginalConstructor()
94-
->getMockForAbstractClass();
91+
$this->viewMock = $this->createMock(ViewInterface::class);
92+
$this->request = $this->createMock(RequestInterface::class);
93+
$response = $this->createMock(ResponseInterface::class);
9594
$contextMock = $this->createMock(Context::class);
9695
$contextMock->expects($this->atLeastOnce())
9796
->method('getRequest')
@@ -100,13 +99,11 @@ protected function setUp(): void
10099
->method('getResponse')
101100
->willReturn($response);
102101
$contextMock->expects($this->any())->method('getView')->willReturn($this->viewMock);
103-
$this->addressFormMock =
104-
$this->getMockBuilder(Edit::class)
105-
->addMethods(['setTitle', 'setSuccessUrl', 'setBackUrl', 'setErrorUrl'])
106-
->onlyMethods(['getTitle'])
107-
->disableOriginalConstructor()
108-
->getMock();
109-
$this->urlMock = $this->getMockForAbstractClass(UrlInterface::class);
102+
$this->addressFormMock = $this->createPartialMockWithReflection(
103+
Edit::class,
104+
['setTitle', 'setSuccessUrl', 'setBackUrl', 'setErrorUrl', 'getTitle']
105+
);
106+
$this->urlMock = $this->createMock(UrlInterface::class);
110107
$contextMock->expects($this->any())->method('getUrl')->willReturn($this->urlMock);
111108
$this->pageMock = $this->createMock(Page::class);
112109
$this->pageMock->expects($this->any())->method('getConfig')->willReturn($this->configMock);
@@ -133,10 +130,7 @@ public function testExecute()
133130
->method('setTitle')
134131
->with('Edit Address')
135132
->willReturnSelf();
136-
$helperMock = $this->getMockBuilder(Data::class)
137-
->addMethods(['__'])
138-
->disableOriginalConstructor()
139-
->getMock();
133+
$helperMock = $this->createPartialMockWithReflection(Data::class, ['__']);
140134
$helperMock->expects($this->any())->method('__')->willReturn('Edit Address');
141135
$valueMap = [
142136
['*/*/saveBillingFromList', ['id' => 1], 'success/url'],

0 commit comments

Comments
 (0)