Skip to content

Commit afbce4a

Browse files
committed
AC-10634: setMethods replaced with onlyMethods() or addMethods()
1 parent c9aef73 commit afbce4a

File tree

25 files changed

+271
-224
lines changed

25 files changed

+271
-224
lines changed

app/code/Magento/Catalog/Test/Unit/Model/ProductOptionProcessorTest.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -113,12 +113,7 @@ public function testConvertToBuyRequest(
113113
$productOptionMock = $this->getMockBuilder(ProductOptionInterface::class)
114114
->getMockForAbstractClass();
115115

116-
$productOptionExtensionMock = $this->getMockBuilder(
117-
ProductOptionExtensionInterface::class
118-
)
119-
->onlyMethods([
120-
'getCustomOptions',
121-
])
116+
$productOptionExtensionMock = $this->getMockBuilder(ProductOptionExtensionInterface::class)
122117
->getMockForAbstractClass();
123118

124119
$productOptionMock->expects($this->any())

app/code/Magento/Fedex/Test/Unit/Model/CarrierTest.php

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -168,12 +168,12 @@ protected function setUp(): void
168168

169169
$this->trackErrorFactory = $this->getMockBuilder(ErrorFactory::class)
170170
->disableOriginalConstructor()
171-
->setMethods(['create'])
171+
->onlyMethods(['create'])
172172
->getMock();
173173

174174
$this->statusFactory = $this->getMockBuilder(StatusFactory::class)
175175
->disableOriginalConstructor()
176-
->setMethods(['create'])
176+
->onlyMethods(['create'])
177177
->getMock();
178178

179179
$elementFactory = $this->getMockBuilder(ElementFactory::class)
@@ -208,21 +208,21 @@ protected function setUp(): void
208208

209209
$this->curlFactory = $this->getMockBuilder(CurlFactory::class)
210210
->disableOriginalConstructor()
211-
->setMethods(['create'])
211+
->onlyMethods(['create'])
212212
->getMock();
213213

214214
$this->curlClient = $this->getMockBuilder(Curl::class)
215215
->disableOriginalConstructor()
216-
->setMethods(['setHeaders', 'getBody', 'post'])
216+
->onlyMethods(['setHeaders', 'getBody', 'post'])
217217
->getMock();
218218

219219
$this->decoderInterface = $this->getMockBuilder(DecoderInterface::class)
220220
->disableOriginalConstructor()
221-
->setMethods(['decode'])
221+
->onlyMethods(['decode'])
222222
->getMock();
223223

224224
$this->carrier = $this->getMockBuilder(Carrier::class)
225-
->setMethods(['rateRequest'])
225+
->addMethods(['rateRequest'])
226226
->setConstructorArgs(
227227
[
228228
'scopeConfig' => $this->scope,
@@ -368,7 +368,7 @@ public function testSetRequestWithoutCity(): void
368368
{
369369
$request = $this->getMockBuilder(RateRequest::class)
370370
->disableOriginalConstructor()
371-
->setMethods(['getDestCity'])
371+
->addMethods(['getDestCity'])
372372
->getMock();
373373
$request->expects($this->once())
374374
->method('getDestCity')
@@ -380,7 +380,7 @@ public function testSetRequestWithCity(): void
380380
{
381381
$request = $this->getMockBuilder(RateRequest::class)
382382
->disableOriginalConstructor()
383-
->setMethods(['getDestCity'])
383+
->addMethods(['getDestCity'])
384384
->getMock();
385385
$request->expects($this->exactly(2))
386386
->method('getDestCity')
@@ -462,7 +462,7 @@ public function testCollectRatesRateAmountOriginBased(
462462
->willReturn($baseCurrencyCode);
463463

464464
$request = $this->getMockBuilder(RateRequest::class)
465-
->setMethods(['getBaseCurrency'])
465+
->addMethods(['getBaseCurrency'])
466466
->disableOriginalConstructor()
467467
->getMock();
468468
$request->method('getBaseCurrency')
@@ -485,7 +485,7 @@ public function testCollectRatesRateAmountOriginBased(
485485
* Get list of rates variations
486486
* @return array
487487
*/
488-
public function collectRatesDataProvider(): array
488+
public static function collectRatesDataProvider(): array
489489
{
490490
return [
491491
[10.0, 'USD', 'EUR', 'RATED_ACCOUNT_PACKAGE', 7.5],
@@ -551,7 +551,7 @@ public function testFilterDebugData($data, array $maskFields, $expected): void
551551
/**
552552
* Get list of variations
553553
*/
554-
public function logDataProvider(): array
554+
public static function logDataProvider(): array
555555
{
556556
return [
557557
[
@@ -573,7 +573,7 @@ public function logDataProvider(): array
573573
* @param string $tracking
574574
* @return array
575575
*/
576-
public function getTrackRequest(string $tracking): array
576+
public static function getTrackRequest(string $tracking): array
577577
{
578578
return [
579579
'includeDetailedScans' => true,
@@ -1009,11 +1009,11 @@ private function initRateErrorFactory(): void
10091009
{
10101010
$this->error = $this->getMockBuilder(RateResultError::class)
10111011
->disableOriginalConstructor()
1012-
->setMethods(['setCarrier', 'setCarrierTitle', 'setErrorMessage'])
1012+
->addMethods(['setCarrier', 'setCarrierTitle', 'setErrorMessage'])
10131013
->getMock();
10141014
$this->errorFactory = $this->getMockBuilder(RateErrorFactory::class)
10151015
->disableOriginalConstructor()
1016-
->setMethods(['create'])
1016+
->onlyMethods(['create'])
10171017
->getMock();
10181018
$this->errorFactory->expects($this->any())
10191019
->method('create')
@@ -1028,11 +1028,11 @@ private function getRateFactory()
10281028
{
10291029
$rate = $this->getMockBuilder(RateResult::class)
10301030
->disableOriginalConstructor()
1031-
->setMethods(['getError'])
1031+
->onlyMethods(['getError'])
10321032
->getMock();
10331033
$rateFactory = $this->getMockBuilder(RateResultFactory::class)
10341034
->disableOriginalConstructor()
1035-
->setMethods(['create'])
1035+
->onlyMethods(['create'])
10361036
->getMock();
10371037
$rateFactory->expects($this->any())
10381038
->method('create')
@@ -1049,15 +1049,15 @@ private function getCountryFactory()
10491049
{
10501050
$country = $this->getMockBuilder(Country::class)
10511051
->disableOriginalConstructor()
1052-
->setMethods(['load', 'getData'])
1052+
->onlyMethods(['load', 'getData'])
10531053
->getMock();
10541054
$country->expects($this->any())
10551055
->method('load')
10561056
->willReturnSelf();
10571057

10581058
$countryFactory = $this->getMockBuilder(CountryFactory::class)
10591059
->disableOriginalConstructor()
1060-
->setMethods(['create'])
1060+
->onlyMethods(['create'])
10611061
->getMock();
10621062
$countryFactory->expects($this->any())
10631063
->method('create')
@@ -1074,7 +1074,7 @@ private function getResultFactory()
10741074
{
10751075
$resultFactory = $this->getMockBuilder(ResultFactory::class)
10761076
->disableOriginalConstructor()
1077-
->setMethods(['create'])
1077+
->onlyMethods(['create'])
10781078
->getMock();
10791079
$this->result = $this->helper->getObject(Result::class);
10801080
$resultFactory->expects($this->any())
@@ -1092,7 +1092,7 @@ private function getStoreManager()
10921092
{
10931093
$store = $this->getMockBuilder(Store::class)
10941094
->disableOriginalConstructor()
1095-
->setMethods(['getBaseCurrencyCode'])
1095+
->onlyMethods(['getBaseCurrencyCode'])
10961096
->getMock();
10971097
$storeManager = $this->getMockForAbstractClass(StoreManagerInterface::class);
10981098
$storeManager->expects($this->any())
@@ -1111,11 +1111,11 @@ private function getRateMethodFactory()
11111111
$priceCurrency = $this->getMockForAbstractClass(PriceCurrencyInterface::class);
11121112
$rateMethod = $this->getMockBuilder(Method::class)
11131113
->setConstructorArgs(['priceCurrency' => $priceCurrency])
1114-
->setMethods(null)
1114+
->onlyMethods([])
11151115
->getMock();
11161116
$rateMethodFactory = $this->getMockBuilder(MethodFactory::class)
11171117
->disableOriginalConstructor()
1118-
->setMethods(['create'])
1118+
->onlyMethods(['create'])
11191119
->getMock();
11201120
$rateMethodFactory->expects($this->any())
11211121
->method('create')

app/code/Magento/GiftMessage/Test/Unit/Model/OrderItemRepositoryTest.php

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -75,30 +75,31 @@ protected function setUp(): void
7575
$helper = new ObjectManager($this);
7676
$this->orderMock = $this->getMockBuilder(Order::class)
7777
->disableOriginalConstructor()
78-
->setMethods(['load', 'getItemById', 'getIsVirtual'])
78+
->onlyMethods(['load', 'getItemById', 'getIsVirtual'])
7979
->getMock();
8080
$this->orderFactoryMock = $this->getMockBuilder(OrderFactory::class)
8181
->disableOriginalConstructor()
82-
->setMethods(['create'])
82+
->onlyMethods(['create'])
8383
->getMock();
8484
$this->helperMock = $this->getMockBuilder(Message::class)
8585
->disableOriginalConstructor()
8686
->getMock();
8787
$this->storeManagerMock = $this->getMockBuilder(StoreManagerInterface::class)
8888
->disableOriginalConstructor()
89-
->setMethods(['getStore'])
89+
->onlyMethods(['getStore'])
9090
->getMockForAbstractClass();
9191
$this->storeMock = $this->getMockBuilder(StoreInterface::class)
9292
->disableOriginalConstructor()
93-
->setMethods([])
93+
->onlyMethods([])
9494
->getMockForAbstractClass();
9595
$this->messageFactoryMock = $this->getMockBuilder(MessageFactory::class)
9696
->disableOriginalConstructor()
97-
->setMethods(['create'])
97+
->onlyMethods(['create'])
9898
->getMock();
9999
$this->giftMessageSaveModelMock = $this->getMockBuilder(Save::class)
100100
->disableOriginalConstructor()
101-
->setMethods(['setGiftmessages', 'saveAllInOrder'])
101+
->addMethods(['setGiftmessages'])
102+
->onlyMethods(['saveAllInOrder'])
102103
->getMock();
103104
$this->storeManagerMock->expects($this->any())
104105
->method('getStore')
@@ -126,7 +127,7 @@ public function testGet()
126127
$messageId = 3;
127128
$orderItemMock = $this->getMockBuilder(Item::class)
128129
->disableOriginalConstructor()
129-
->setMethods(['getGiftMessageId'])
130+
->addMethods(['getGiftMessageId'])
130131
->getMock();
131132
$messageMock = $this->getMockBuilder(\Magento\GiftMessage\Model\Message::class)
132133
->disableOriginalConstructor()
@@ -200,7 +201,7 @@ public function testGetNoSuchEntityExceptionOnIsMessageAllowed()
200201
$orderItemId = 2;
201202
$orderItemMock = $this->getMockBuilder(Item::class)
202203
->disableOriginalConstructor()
203-
->setMethods(['getGiftMessageId'])
204+
->addMethods(['getGiftMessageId'])
204205
->getMock();
205206

206207
$this->orderFactoryMock->expects($this->once())
@@ -241,7 +242,7 @@ public function testGetNoSuchEntityExceptionOnGetGiftMessageId()
241242
$messageId = null;
242243
$orderItemMock = $this->getMockBuilder(Item::class)
243244
->disableOriginalConstructor()
244-
->setMethods(['getGiftMessageId'])
245+
->addMethods(['getGiftMessageId'])
245246
->getMock();
246247

247248
$this->orderFactoryMock->expects($this->once())
@@ -289,7 +290,7 @@ public function testSave()
289290
];
290291
$orderItemMock = $this->getMockBuilder(Item::class)
291292
->disableOriginalConstructor()
292-
->setMethods(['getGiftMessageId'])
293+
->addMethods(['getGiftMessageId'])
293294
->getMock();
294295
$messageMock = $this->getMockBuilder(MessageInterface::class)
295296
->disableOriginalConstructor()
@@ -374,7 +375,7 @@ public function testSaveInvalidTransitionException()
374375
$orderItemId = 2;
375376
$orderItemMock = $this->getMockBuilder(Item::class)
376377
->disableOriginalConstructor()
377-
->setMethods(['getGiftMessageId'])
378+
->addMethods(['getGiftMessageId'])
378379
->getMock();
379380
$messageMock = $this->getMockBuilder(MessageInterface::class)
380381
->disableOriginalConstructor()
@@ -413,7 +414,7 @@ public function testSaveCouldNotSaveException()
413414
$orderItemId = 2;
414415
$orderItemMock = $this->getMockBuilder(Item::class)
415416
->disableOriginalConstructor()
416-
->setMethods(['getGiftMessageId'])
417+
->addMethods(['getGiftMessageId'])
417418
->getMock();
418419
$messageMock = $this->getMockBuilder(MessageInterface::class)
419420
->disableOriginalConstructor()
@@ -463,7 +464,7 @@ public function testSaveCouldNotSaveExceptionOnSaveAllInOrder()
463464
$excep = new \Exception('Exception message');
464465
$orderItemMock = $this->getMockBuilder(Item::class)
465466
->disableOriginalConstructor()
466-
->setMethods(['getGiftMessageId'])
467+
->addMethods(['getGiftMessageId'])
467468
->getMock();
468469
$messageMock = $this->getMockBuilder(MessageInterface::class)
469470
->disableOriginalConstructor()

app/code/Magento/GiftMessage/Test/Unit/Observer/SalesEventOrderToQuoteObserverTest.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,14 +78,15 @@ protected function setUp(): void
7878
$this->observerMock = $this->createMock(Observer::class);
7979
$this->eventMock = $this->getMockBuilder(Event::class)
8080
->disableOriginalConstructor()
81-
->setMethods(['getOrder', 'getQuote'])
81+
->addMethods(['getOrder', 'getQuote'])
8282
->getMock();
8383
$this->orderMock = $this->getMockBuilder(Order::class)
84-
->setMethods(['getReordered', 'getStore', 'getGiftMessageId'])
84+
->addMethods(['getReordered', 'getGiftMessageId'])
85+
->onlyMethods(['getStore'])
8586
->disableOriginalConstructor()
8687
->getMockForAbstractClass();
8788
$this->quoteMock = $this->getMockBuilder(Quote::class)
88-
->setMethods(['setGiftMessageId'])
89+
->addMethods(['setGiftMessageId'])
8990
->disableOriginalConstructor()
9091
->getMockForAbstractClass();
9192
$this->storeMock = $this->createMock(Store::class);
@@ -164,7 +165,7 @@ public function testExecute(bool $orderIsReordered, bool $isMessagesAllowed): vo
164165
*
165166
* @return array
166167
*/
167-
public function giftMessageDataProvider(): array
168+
public static function giftMessageDataProvider(): array
168169
{
169170
return [
170171
[false, true],

app/code/Magento/GroupedProduct/Test/Unit/Pricing/Price/ConfiguredPriceTest.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,15 +68,17 @@ protected function setUp(): void
6868
->getMock();
6969

7070
$this->saleableItem = $this->getMockBuilder(SaleableInterface::class)
71-
->setMethods([
72-
'getTypeId',
73-
'getId',
74-
'getQty',
75-
'getPriceInfo',
71+
->addMethods([
7672
'getTypeInstance',
7773
'getStore',
7874
'getCustomOption',
79-
'hasFinalPrice'
75+
'hasFinalPrice',
76+
])
77+
->onlyMethods([
78+
'getTypeId',
79+
'getId',
80+
'getQty',
81+
'getPriceInfo'
8082
])
8183
->getMockForAbstractClass();
8284
$this->saleableItem->expects($this->once())

0 commit comments

Comments
 (0)