Skip to content

Commit 8d7e504

Browse files
committed
Merge remote-tracking branch 'origin/MC-38546' into 2.4-develop-pr122
2 parents 68d61dd + 20f138c commit 8d7e504

File tree

5 files changed

+57
-24
lines changed

5 files changed

+57
-24
lines changed

app/code/Magento/Catalog/Test/Unit/Model/Product/Type/PriceTest.php

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
use Magento\Store\Model\StoreManagerInterface;
2222
use Magento\Store\Model\Website;
2323
use PHPUnit\Framework\MockObject\MockObject;
24+
use PHPUnit\Framework\MockObject\RuntimeException;
2425
use PHPUnit\Framework\TestCase;
2526

2627
/**
@@ -110,7 +111,7 @@ protected function setUp(): void
110111
$this->groupManagementMock->expects($this->any())->method('getAllCustomersGroup')
111112
->willReturn($group);
112113
$this->tierPriceExtensionFactoryMock = $this->getMockBuilder(ProductTierPriceExtensionFactory::class)
113-
->setMethods(['create'])
114+
->onlyMethods(['create'])
114115
->disableOriginalConstructor()
115116
->getMock();
116117
$this->model = $this->objectManagerHelper->getObject(
@@ -182,9 +183,7 @@ function () {
182183
);
183184

184185
// create sample TierPrice objects that would be coming from a REST call
185-
$tierPriceExtensionMock = $this->getMockBuilder(ProductTierPriceExtensionInterface::class)
186-
->setMethods(['getWebsiteId', 'setWebsiteId', 'getPercentageValue', 'setPercentageValue'])
187-
->getMockForAbstractClass();
186+
$tierPriceExtensionMock = $this->getProductTierPriceExtensionInterfaceMock();
188187
$tierPriceExtensionMock->expects($this->any())->method('getWebsiteId')->willReturn($expectedWebsiteId);
189188
$tierPriceExtensionMock->expects($this->any())->method('getPercentageValue')->willReturn(null);
190189
$tp1 = $this->objectManagerHelper->getObject(TierPrice::class);
@@ -226,9 +225,7 @@ function () {
226225
$this->assertEquals($tps[$i]->getQty(), $tpData['price_qty'], 'Qty does not match');
227226
}
228227

229-
$tierPriceExtensionMock = $this->getMockBuilder(ProductTierPriceExtensionInterface::class)
230-
->setMethods(['getWebsiteId', 'setWebsiteId', 'getPercentageValue', 'setPercentageValue'])
231-
->getMockForAbstractClass();
228+
$tierPriceExtensionMock = $this->getProductTierPriceExtensionInterfaceMock();
232229
$tierPriceExtensionMock->expects($this->any())->method('getPercentageValue')->willReturn(50);
233230
$tierPriceExtensionMock->expects($this->any())->method('setWebsiteId');
234231
$this->tierPriceExtensionFactoryMock->expects($this->any())
@@ -289,14 +286,30 @@ function () {
289286
return $this->objectManagerHelper->getObject(TierPrice::class);
290287
}
291288
);
292-
$tierPriceExtensionMock = $this->getMockBuilder(ProductTierPriceExtensionInterface::class)
293-
->onlyMethods(['getPercentageValue', 'setPercentageValue'])
294-
->getMockForAbstractClass();
289+
$tierPriceExtensionMock = $this->getProductTierPriceExtensionInterfaceMock();
295290
$tierPriceExtensionMock->method('getPercentageValue')
296291
->willReturn(50);
297292
$this->tierPriceExtensionFactoryMock->method('create')
298293
->willReturn($tierPriceExtensionMock);
299294

300295
$this->assertInstanceOf(TierPrice::class, $this->model->getTierPrices($this->product)[0]);
301296
}
297+
298+
/**
299+
* Build ProductTierPriceExtensionInterface mock.
300+
*
301+
* @return MockObject
302+
*/
303+
private function getProductTierPriceExtensionInterfaceMock(): MockObject
304+
{
305+
$mockBuilder = $this->getMockBuilder(ProductTierPriceExtensionInterface::class)
306+
->disableOriginalConstructor();
307+
try {
308+
$mockBuilder->addMethods(['getPercentageValue', 'setPercentageValue', 'setWebsiteId', 'getWebsiteId']);
309+
} catch (RuntimeException $e) {
310+
// ProductTierPriceExtensionInterface already generated and has all necessary methods.
311+
}
312+
313+
return $mockBuilder->getMock();
314+
}
302315
}

dev/tests/integration/framework/tests/unit/testsuite/Magento/Test/Bootstrap/MemoryTest.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
*/
1010
namespace Magento\Test\Bootstrap;
1111

12+
use Magento\TestFramework\MemoryLimit;
13+
1214
class MemoryTest extends \PHPUnit\Framework\TestCase
1315
{
1416
/**
@@ -17,7 +19,7 @@ class MemoryTest extends \PHPUnit\Framework\TestCase
1719
protected $_object;
1820

1921
/**
20-
* @var \Magento\TestFramework\MemoryLimit|\PHPUnit\Framework\MockObject\MockObject
22+
* @var MemoryLimit|\PHPUnit\Framework\MockObject\MockObject
2123
*/
2224
protected $_memoryLimit;
2325

@@ -28,8 +30,10 @@ class MemoryTest extends \PHPUnit\Framework\TestCase
2830

2931
protected function setUp(): void
3032
{
31-
$this->_memoryLimit = $this->createPartialMock(\Magento\TestFramework\MemoryLimit::class, ['printStats']);
32-
$this->_activationPolicy = $this->createPartialMock(\stdClass::class, ['register_shutdown_function']);
33+
$this->_memoryLimit = $this->createPartialMock(MemoryLimit::class, ['printStats']);
34+
$this->_activationPolicy = $this->getMockBuilder(\stdClass::class)
35+
->addMethods(['register_shutdown_function'])
36+
->getMock();
3337
$this->_object = new \Magento\TestFramework\Bootstrap\Memory(
3438
$this->_memoryLimit,
3539
[$this->_activationPolicy, 'register_shutdown_function']

dev/tests/integration/framework/tests/unit/testsuite/Magento/Test/EventManagerTest.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,12 @@ class EventManagerTest extends \PHPUnit\Framework\TestCase
2828

2929
protected function setUp(): void
3030
{
31-
$this->_subscriberOne = $this->createPartialMock(\stdClass::class, ['testEvent']);
32-
$this->_subscriberTwo = $this->createPartialMock(\stdClass::class, ['testEvent']);
31+
$this->_subscriberOne = $this->getMockBuilder(\stdClass::class)
32+
->addMethods(['testEvent'])
33+
->getMock();
34+
$this->_subscriberTwo = $this->getMockBuilder(\stdClass::class)
35+
->addMethods(['testEvent'])
36+
->getMock();
3337
$this->_eventManager = new \Magento\TestFramework\EventManager(
3438
[$this->_subscriberOne, $this->_subscriberTwo]
3539
);

dev/tests/integration/framework/tests/unit/testsuite/Magento/Test/Helper/BootstrapTest.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,11 @@ protected function setUp(): void
4747
\Magento\TestFramework\Application::class,
4848
['getTempDir', 'getInitParams', 'reinitialize', 'run']
4949
);
50-
$this->_bootstrap = $this->createPartialMock(
51-
\Magento\TestFramework\Bootstrap::class,
52-
['getApplication', 'getDbVendorName']
53-
);
50+
$this->_bootstrap = $this->getMockBuilder(\Magento\TestFramework\Bootstrap::class)
51+
->disableOriginalConstructor()
52+
->addMethods(['getDbVendorName'])
53+
->onlyMethods(['getApplication'])
54+
->getMock();
5455
$this->_bootstrap->expects(
5556
$this->any()
5657
)->method(

lib/internal/Magento/Framework/Mview/Test/Unit/ViewTest.php

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
/**
34
* Copyright © Magento, Inc. All rights reserved.
45
* See COPYING.txt for license details.
@@ -7,12 +8,13 @@
78

89
namespace Magento\Framework\Mview\Test\Unit;
910

10-
use Laminas\Log\Filter\Mock;
1111
use Magento\Framework\Mview\ActionFactory;
1212
use Magento\Framework\Mview\ActionInterface;
1313
use Magento\Framework\Mview\ConfigInterface;
1414
use Magento\Framework\Mview\View;
1515
use Magento\Framework\Mview\View\Changelog;
16+
use Magento\Framework\Mview\View\ChangeLogBatchWalkerFactory;
17+
use Magento\Framework\Mview\View\ChangeLogBatchWalkerInterface;
1618
use Magento\Framework\Mview\View\StateInterface;
1719
use Magento\Framework\Mview\View\Subscription;
1820
use Magento\Framework\Mview\View\SubscriptionFactory;
@@ -55,7 +57,7 @@ class ViewTest extends TestCase
5557
protected $subscriptionFactoryMock;
5658

5759
/**
58-
* @var MockObject|View\ChangeLogBatchIteratorInterface
60+
* @var MockObject|ChangeLogBatchWalkerInterface
5961
*/
6062
private $iteratorMock;
6163

@@ -73,7 +75,15 @@ protected function setUp(): void
7375
true,
7476
['getView']
7577
);
76-
$this->iteratorMock = $this->createMock(View\ChangeLogBatchIteratorInterface::class);
78+
$this->iteratorMock = $this->getMockBuilder(ChangeLogBatchWalkerInterface::class)
79+
->disableOriginalConstructor()
80+
->onlyMethods(['walk'])
81+
->getMockForAbstractClass();
82+
$changeLogBatchWalkerFactory = $this->getMockBuilder(ChangeLogBatchWalkerFactory::class)
83+
->disableOriginalConstructor()
84+
->onlyMethods(['create'])
85+
->getMockForAbstractClass();
86+
$changeLogBatchWalkerFactory->method('create')->willReturn($this->iteratorMock);
7787
$this->actionFactoryMock = $this->createPartialMock(ActionFactory::class, ['get']);
7888
$this->stateMock = $this->createPartialMock(
7989
State::class,
@@ -107,7 +117,7 @@ protected function setUp(): void
107117
$this->subscriptionFactoryMock,
108118
[],
109119
[],
110-
$this->iteratorMock
120+
$changeLogBatchWalkerFactory
111121
);
112122
}
113123

@@ -485,7 +495,7 @@ public function testUpdateWithException()
485495
);
486496
$this->iteratorMock->expects($this->any())
487497
->method('walk')
488-
->willReturn([2,3]);
498+
->willReturn([2, 3]);
489499

490500
$actionMock = $this->createPartialMock(ActionInterface::class, ['execute']);
491501
$actionMock->expects($this->once())->method('execute')->with($listId)->willReturnCallback(
@@ -796,6 +806,7 @@ protected function getViewData()
796806
'action_class' => 'Some\Class\Name',
797807
'group' => 'some_group',
798808
'subscriptions' => ['some_entity' => ['name' => 'some_entity', 'column' => 'entity_id']],
809+
'walker' => ChangeLogBatchWalkerInterface::class
799810
];
800811
}
801812
}

0 commit comments

Comments
 (0)