Skip to content

Commit 75e7f4d

Browse files
committed
ACPT-1450: fix unit tests failures
1 parent 38ba59d commit 75e7f4d

File tree

2 files changed

+36
-16
lines changed

2 files changed

+36
-16
lines changed

app/code/Magento/SalesRule/Test/Unit/Model/Quote/DiscountTest.php

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -117,11 +117,6 @@ protected function setUp(): void
117117
->getMock();
118118
$this->rule = $this->getMockBuilder(Rule::class)
119119
->disableOriginalConstructor()
120-
->addMethods(
121-
[
122-
'getSimpleAction'
123-
]
124-
)
125120
->getMock();
126121
$this->eventManagerMock = $this->createMock(Manager::class);
127122
$priceCurrencyMock = $this->getMockForAbstractClass(PriceCurrencyInterface::class);
@@ -219,7 +214,15 @@ public function testCollectItemNoDiscount()
219214
$this->shippingAssignmentMock->expects($this->any())->method('getItems')->willReturn([$itemNoDiscount]);
220215
$this->addressMock->expects($this->any())->method('getShippingAmount')->willReturn(true);
221216

222-
$totalMock = $this->createMock(Total::class);
217+
$totalMock = $this->getMockBuilder(Total::class)
218+
->addMethods(
219+
[
220+
'getBaseDiscountAmount'
221+
]
222+
)
223+
->disableOriginalConstructor()
224+
->getMock();
225+
$totalMock->expects($this->any())->method('getBaseDiscountAmount')->willReturn(0.0);
223226

224227
$this->assertInstanceOf(
225228
Discount::class,
@@ -265,7 +268,15 @@ public function testCollectItemHasParent()
265268
$this->addressMock->expects($this->any())->method('getQuote')->willReturn($quoteMock);
266269
$this->addressMock->expects($this->any())->method('getShippingAmount')->willReturn(true);
267270
$this->shippingAssignmentMock->expects($this->any())->method('getItems')->willReturn([$itemWithParentId]);
268-
$totalMock = $this->createMock(Total::class);
271+
$totalMock = $this->getMockBuilder(Total::class)
272+
->addMethods(
273+
[
274+
'getBaseDiscountAmount'
275+
]
276+
)
277+
->disableOriginalConstructor()
278+
->getMock();
279+
$totalMock->expects($this->any())->method('getBaseDiscountAmount')->willReturn(0.0);
269280

270281
$this->assertInstanceOf(
271282
Discount::class,
@@ -334,7 +345,16 @@ public function testCollectItemHasNoChildren()
334345
$this->addressMock->expects($this->any())->method('getShippingAmount')->willReturn(true);
335346
$this->shippingAssignmentMock->expects($this->any())->method('getItems')->willReturn([$itemWithChildren]);
336347

337-
$totalMock = $this->createMock(Total::class);
348+
$totalMock = $this->getMockBuilder(Total::class)
349+
->addMethods(
350+
[
351+
'getBaseDiscountAmount'
352+
]
353+
)
354+
->disableOriginalConstructor()
355+
->getMock();
356+
$totalMock->expects($this->any())->method('getBaseDiscountAmount')->willReturn(0.0);
357+
338358
$this->assertInstanceOf(
339359
Discount::class,
340360
$this->discount->collect($quoteMock, $this->shippingAssignmentMock, $totalMock)
@@ -353,10 +373,11 @@ public function testFetch()
353373

354374
$quoteMock = $this->createMock(Quote::class);
355375
$totalMock = $this->getMockBuilder(Total::class)
356-
->addMethods(['getDiscountAmount', 'getDiscountDescription'])
376+
->addMethods(['getDiscountAmount', 'getDiscountDescription', 'getBaseDiscountAmount'])
357377
->disableOriginalConstructor()
358378
->getMock();
359379

380+
$totalMock->expects($this->any())->method('getBaseDiscountAmount')->willReturn(0.0);
360381
$totalMock->expects($this->once())->method('getDiscountAmount')->willReturn($discountAmount);
361382
$totalMock->expects($this->once())->method('getDiscountDescription')->willReturn($discountDescription);
362383
$this->assertEquals($expectedResult, $this->discount->fetch($quoteMock, $totalMock));

app/code/Magento/SalesRule/Test/Unit/Model/ValidatorTest.php

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -375,8 +375,7 @@ public function testCanApplyDiscount(): void
375375
public function testInitTotalsCanApplyDiscount(): void
376376
{
377377
$rule = $this->getMockBuilder(Rule::class)
378-
->addMethods(['getSimpleAction'])
379-
->onlyMethods(['getActions', 'getId'])
378+
->onlyMethods(['getActions', 'getId', 'getSimpleAction'])
380379
->disableOriginalConstructor()
381380
->getMock();
382381
$item1 = $this->getMockForAbstractClass(
@@ -561,14 +560,14 @@ public function testProcessShippingAmountActions(
561560

562561
$ruleMock = $this->getMockBuilder(Rule::class)
563562
->disableOriginalConstructor()
564-
->addMethods(['getApplyToShipping', 'getSimpleAction', 'getDiscountAmount'])
563+
->addMethods(['getApplyToShipping', 'getDiscountAmount'])
564+
->onlyMethods(['getSimpleAction'])
565565
->getMock();
566566
$ruleMock->method('getApplyToShipping')
567567
->willReturn(true);
568568
$ruleMock->method('getDiscountAmount')
569569
->willReturn($ruleDiscount);
570-
$ruleMock->method('getSimpleAction')
571-
->willReturn($action);
570+
$ruleMock->expects($this->any())->method('getSimpleAction')->willReturn($action);
572571

573572
$iterator = new \ArrayIterator([$ruleMock]);
574573
$this->ruleCollection->method('getIterator')
@@ -632,7 +631,8 @@ public function testProcessShippingAmountWithFullFixedPercentDiscount(
632631
): void {
633632
$ruleMock = $this->getMockBuilder(Rule::class)
634633
->disableOriginalConstructor()
635-
->addMethods(['getApplyToShipping', 'getSimpleAction', 'getDiscountAmount'])
634+
->addMethods(['getApplyToShipping', 'getDiscountAmount'])
635+
->onlyMethods(['getSimpleAction'])
636636
->getMock();
637637
$ruleMock->method('getApplyToShipping')
638638
->willReturn(true);
@@ -714,7 +714,6 @@ protected function setupAddressMock(
714714
->getMock();
715715
$cartExtensionMock = $this->getMockBuilder(CartExtensionInterface::class)
716716
->disableOriginalConstructor()
717-
->addMethods(['getShippingAssignments'])
718717
->getMockForAbstractClass();
719718

720719
$quoteMock->method('getStore')

0 commit comments

Comments
 (0)