Skip to content

Commit 9d12bff

Browse files
committed
AC-15495: [CE] PHPUnit 12: Upgrade Utility & Support Modules related test cases
1 parent 7e4c12d commit 9d12bff

File tree

56 files changed

+530
-811
lines changed

Some content is hidden

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

56 files changed

+530
-811
lines changed

app/code/Magento/Marketplace/Test/Unit/Block/PartnersTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
namespace Magento\Marketplace\Test\Unit\Block;
99

1010
use Magento\Marketplace\Block\Partners;
11+
use Magento\Marketplace\Model\Partners as PartnersModel;
1112
use PHPUnit\Framework\MockObject\MockObject;
1213
use PHPUnit\Framework\TestCase;
1314

@@ -57,10 +58,10 @@ public function getPartnersBlockMock($methods = null)
5758
/**
5859
* Gets partners model mock
5960
*
60-
* @return MockObject|\Magento\Marketplace\Model\Partners
61+
* @return MockObject|PartnersModel
6162
*/
6263
public function getPartnersModelMock($methods)
6364
{
64-
return $this->createPartialMock(\Magento\Marketplace\Model\Partners::class, $methods);
65+
return $this->createPartialMock(PartnersModel::class, $methods);
6566
}
6667
}

app/code/Magento/Marketplace/Test/Unit/Controller/Index/IndexTest.php

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

88
namespace Magento\Marketplace\Test\Unit\Controller\Index;
99

10+
use Magento\Framework\TestFramework\Unit\Helper\MockCreationTrait;
1011
use Magento\Framework\View\Page\Config;
1112
use Magento\Framework\View\Page\Title;
1213
use Magento\Framework\View\Result\Page;
@@ -17,6 +18,8 @@
1718

1819
class IndexTest extends TestCase
1920
{
21+
use MockCreationTrait;
22+
2023
/**
2124
* @var MockObject|Index
2225
*/
@@ -32,11 +35,10 @@ protected function setUp(): void
3235
*/
3336
public function testExecute()
3437
{
35-
$pageMock = $this->getMockBuilder(Page::class)
36-
->addMethods(['setActiveMenu', 'addBreadcrumb'])
37-
->onlyMethods(['getConfig'])
38-
->disableOriginalConstructor()
39-
->getMock();
38+
$pageMock = $this->createPartialMockWithReflection(
39+
Page::class,
40+
['setActiveMenu', 'addBreadcrumb', 'getConfig']
41+
);
4042
$pageMock->expects($this->once())
4143
->method('setActiveMenu');
4244
$pageMock->expects($this->once())

app/code/Magento/Marketplace/Test/Unit/Controller/Partners/IndexTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ public function getLayoutFactoryMock($methods = null)
101101
*/
102102
public function getLayoutMock()
103103
{
104-
return $this->getMockForAbstractClass(LayoutInterface::class);
104+
return $this->createMock(LayoutInterface::class);
105105
}
106106

107107
/**
@@ -125,6 +125,6 @@ public function getRequestMock($methods = null)
125125
*/
126126
public function getBlockInterfaceMock()
127127
{
128-
return $this->getMockForAbstractClass(BlockInterface::class);
128+
return $this->createMock(BlockInterface::class);
129129
}
130130
}

app/code/Magento/Marketplace/Test/Unit/Helper/CacheTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ class CacheTest extends TestCase
3333

3434
protected function setUp(): void
3535
{
36-
$this->cache = $this->getMockForAbstractClass(CacheInterface::class);
37-
$this->serializer = $this->getMockForAbstractClass(SerializerInterface::class);
36+
$this->cache = $this->createMock(CacheInterface::class);
37+
$this->serializer = $this->createMock(SerializerInterface::class);
3838
$objectManagerHelper = new ObjectManager($this);
3939
$this->cacheHelper = $objectManagerHelper->getObject(
4040
Cache::class,

app/code/Magento/Marketplace/Test/Unit/Model/PartnersTest.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
namespace Magento\Marketplace\Test\Unit\Model;
99

1010
use Magento\Framework\HTTP\Client\Curl;
11+
use Magento\Marketplace\Block\Partners as PartnersBlock;
1112
use Magento\Marketplace\Helper\Cache;
1213
use Magento\Marketplace\Model\Partners;
1314
use PHPUnit\Framework\MockObject\MockObject;
@@ -20,6 +21,9 @@ class PartnersTest extends TestCase
2021
*/
2122
private $partnersModelMock;
2223

24+
/**
25+
* @var string
26+
*/
2327
private $returnPackages = '
2428
{
2529
"partners": {
@@ -126,11 +130,11 @@ public function testGetPartnersException()
126130
/**
127131
* Gets partners block mock
128132
*
129-
* @return MockObject|\Magento\Marketplace\Block\Partners
133+
* @return MockObject|PartnersBlock
130134
*/
131135
public function getPartnersBlockMock($methods = null)
132136
{
133-
return $this->createPartialMock(\Magento\Marketplace\Block\Partners::class, $methods);
137+
return $this->createPartialMock(PartnersBlock::class, $methods);
134138
}
135139

136140
/**

app/code/Magento/RequireJs/Test/Unit/Block/Html/Head/ConfigTest.php

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ protected function setUp(): void
6262
$this->config = $this->createMock(\Magento\Framework\RequireJs\Config::class);
6363
$this->fileManager = $this->createMock(FileManager::class);
6464
$this->pageConfig = $this->createMock(\Magento\Framework\View\Page\Config::class);
65-
$this->bundleConfig = $this->getMockForAbstractClass(ConfigInterface::class);
65+
$this->bundleConfig = $this->createMock(ConfigInterface::class);
6666
}
6767

6868
public function testSetLayout()
@@ -72,16 +72,16 @@ public function testSetLayout()
7272
->method('isBundlingJsFiles')
7373
->willReturn(true);
7474
$filePath = 'require_js_fie_path';
75-
$asset = $this->getMockForAbstractClass(LocalInterface::class);
75+
$asset = $this->createMock(LocalInterface::class);
7676
$asset->expects($this->atLeastOnce())
7777
->method('getFilePath')
7878
->willReturn($filePath);
79-
$requireJsAsset = $this->getMockForAbstractClass(LocalInterface::class);
79+
$requireJsAsset = $this->createMock(LocalInterface::class);
8080
$requireJsAsset
8181
->expects($this->atLeastOnce())
8282
->method('getFilePath')
8383
->willReturn('/path/to/require/require.js');
84-
$minResolverAsset = $this->getMockForAbstractClass(LocalInterface::class);
84+
$minResolverAsset = $this->createMock(LocalInterface::class);
8585
$minResolverAsset
8686
->expects($this->atLeastOnce())
8787
->method('getFilePath')
@@ -108,11 +108,9 @@ public function testSetLayout()
108108
->method('createMinResolverAsset')
109109
->willReturn($minResolverAsset);
110110

111-
$layout = $this->getMockForAbstractClass(LayoutInterface::class);
111+
$layout = $this->createMock(LayoutInterface::class);
112112

113-
$assetCollection = $this->getMockBuilder(GroupedCollection::class)
114-
->disableOriginalConstructor()
115-
->getMock();
113+
$assetCollection = $this->createMock(GroupedCollection::class);
116114
$this->pageConfig->expects($this->atLeastOnce())
117115
->method('getAssetCollection')
118116
->willReturn($assetCollection);
@@ -122,9 +120,7 @@ public function testSetLayout()
122120
->method('insert')
123121
->willReturn(true);
124122

125-
$this->minificationMock = $this->getMockBuilder(Minification::class)
126-
->disableOriginalConstructor()
127-
->getMock();
123+
$this->minificationMock = $this->createMock(Minification::class);
128124
$this->minificationMock
129125
->expects($this->any())
130126
->method('isEnabled')

app/code/Magento/RequireJs/Test/Unit/Model/FileManagerTest.php

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use Magento\Framework\View\Asset\File\FallbackContext;
1919
use Magento\Framework\View\Asset\Repository;
2020
use Magento\RequireJs\Model\FileManager;
21+
use PHPUnit\Framework\Attributes\DataProvider;
2122
use PHPUnit\Framework\MockObject\MockObject;
2223
use PHPUnit\Framework\TestCase;
2324

@@ -65,14 +66,14 @@ protected function setUp(): void
6566
$this->appState = $this->createMock(State::class);
6667
$this->assetRepoMock = $this->createMock(Repository::class);
6768
$this->object = new FileManager($this->configMock, $this->fileSystem, $this->appState, $this->assetRepoMock);
68-
$this->dir = $this->getMockForAbstractClass(WriteInterface::class);
69+
$this->dir = $this->createMock(WriteInterface::class);
6970
$this->asset = $this->createMock(File::class);
7071
}
7172

7273
/**
7374
* @param bool $exists
74-
* @dataProvider createRequireJsAssetDataProvider
7575
*/
76+
#[DataProvider('createRequireJsAssetDataProvider')]
7677
public function testCreateRequireJsConfigAsset($exists)
7778
{
7879
$this->configMock->expects($this->once())
@@ -138,10 +139,7 @@ public function testCreateRequireJsAssetDevMode()
138139
public function testCreateBundleJsPool()
139140
{
140141
unset($this->configMock);
141-
$dirRead = $this->getMockBuilder(Read::class)
142-
->setMockClassName('libDir')
143-
->disableOriginalConstructor()
144-
->getMock();
142+
$dirRead = $this->createMock(Read::class);
145143
$context = $this->createMock(FallbackContext::class);
146144
$assetRepo = $this->createMock(Repository::class);
147145
$config = $this->createMock(Config::class);
@@ -241,9 +239,7 @@ public function testCreateRequireJsMixinsAsset()
241239

242240
public function testClearBundleJsPool()
243241
{
244-
$context = $this->getMockBuilder(FallbackContext::class)
245-
->disableOriginalConstructor()
246-
->getMock();
242+
$context = $this->createMock(FallbackContext::class);
247243
$this->fileSystem->expects($this->once())
248244
->method('getDirectoryWrite')
249245
->with(DirectoryList::STATIC_VIEW)

app/code/Magento/Rule/Test/Unit/Model/AbstractModelTest.php

Lines changed: 38 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use Magento\Framework\Registry;
1818
use Magento\Framework\Serialize\Serializer\Json;
1919
use Magento\Framework\Stdlib\DateTime\TimezoneInterface;
20+
use Magento\Framework\TestFramework\Unit\Helper\MockCreationTrait;
2021
use Magento\Rule\Model\AbstractModel;
2122
use Magento\Rule\Model\Action\Collection;
2223
use Magento\Rule\Model\Condition\Combine;
@@ -30,6 +31,7 @@
3031
*/
3132
class AbstractModelTest extends TestCase
3233
{
34+
use MockCreationTrait;
3335

3436
/**
3537
* @var AbstractModel|MockObject
@@ -63,59 +65,40 @@ class AbstractModelTest extends TestCase
6365

6466
protected function setUp(): void
6567
{
66-
$this->localeDateMock = $this->getMockBuilder(TimezoneInterface::class)
67-
->disableOriginalConstructor()
68-
->getMockForAbstractClass();
69-
70-
$this->formFactoryMock = $this->getMockBuilder(FormFactory::class)
71-
->disableOriginalConstructor()
72-
->getMock();
73-
74-
$this->registryMock = $this->getMockBuilder(Registry::class)
75-
->disableOriginalConstructor()
76-
->getMock();
77-
78-
$this->contextMock = $this->getMockBuilder(Context::class)
79-
->disableOriginalConstructor()
80-
->onlyMethods(['getEventDispatcher'])
81-
->getMock();
82-
83-
$this->eventManagerMock = $this->getMockBuilder(ManagerInterface::class)
84-
->disableOriginalConstructor()
85-
->onlyMethods(['dispatch'])
86-
->getMockForAbstractClass();
68+
$this->localeDateMock = $this->createMock(TimezoneInterface::class);
69+
70+
$this->formFactoryMock = $this->createMock(FormFactory::class);
71+
72+
$this->registryMock = $this->createMock(Registry::class);
73+
74+
$this->contextMock = $this->createPartialMock(Context::class, ['getEventDispatcher']);
75+
76+
$this->eventManagerMock = $this->createMock(ManagerInterface::class);
8777
$this->contextMock->expects($this->any())
8878
->method('getEventDispatcher')
8979
->willReturn($this->eventManagerMock);
9080

91-
$resourceMock = $this->getMockBuilder(AbstractResource::class)
92-
->disableOriginalConstructor()
93-
->getMock();
94-
$resourceCollectionMock = $this->getMockBuilder(AbstractDb::class)
95-
->disableOriginalConstructor()
96-
->getMock();
97-
$extensionFactory = $this->getMockBuilder(ExtensionAttributesFactory::class)
98-
->disableOriginalConstructor()
99-
->getMock();
100-
$customAttributeFactory = $this->getMockBuilder(AttributeValueFactory::class)
101-
->disableOriginalConstructor()
102-
->getMock();
103-
104-
$this->model = $this->getMockForAbstractClass(
105-
AbstractModel::class,
106-
[
107-
'context' => $this->contextMock,
108-
'registry' => $this->registryMock,
109-
'formFactory' => $this->formFactoryMock,
110-
'localeDate' => $this->localeDateMock,
111-
'resource' => $resourceMock,
112-
'resourceCollection' => $resourceCollectionMock,
113-
'data' => [],
114-
'extensionFactory' => $extensionFactory,
115-
'customAttributeFactory' => $customAttributeFactory,
116-
'serializer' => $this->getSerializerMock(),
117-
]
118-
);
81+
$resourceMock = $this->createMock(AbstractResource::class);
82+
$resourceCollectionMock = $this->createMock(AbstractDb::class);
83+
$extensionFactory = $this->createMock(ExtensionAttributesFactory::class);
84+
$customAttributeFactory = $this->createMock(AttributeValueFactory::class);
85+
86+
$this->model = $this->createPartialMock(AbstractModel::class, ['getConditionsInstance', 'getActionsInstance']);
87+
88+
$constructorArgs = [
89+
$this->contextMock,
90+
$this->registryMock,
91+
$this->formFactoryMock,
92+
$this->localeDateMock,
93+
$resourceMock,
94+
$resourceCollectionMock,
95+
[],
96+
$extensionFactory,
97+
$customAttributeFactory,
98+
$this->getSerializerMock(),
99+
];
100+
101+
$this->model->__construct(...$constructorArgs);
119102
}
120103

121104
/**
@@ -125,10 +108,7 @@ protected function setUp(): void
125108
*/
126109
private function getSerializerMock()
127110
{
128-
$serializerMock = $this->getMockBuilder(Json::class)
129-
->disableOriginalConstructor()
130-
->onlyMethods(['serialize', 'unserialize'])
131-
->getMock();
111+
$serializerMock = $this->createPartialMock(Json::class, ['serialize', 'unserialize']);
132112

133113
$serializerMock->expects($this->any())
134114
->method('serialize')
@@ -153,11 +133,7 @@ public function testGetConditions()
153133
{
154134
$conditionsArray = ['conditions' => 'serialized'];
155135
$serializedConditions = json_encode($conditionsArray);
156-
$conditions = $this->getMockBuilder(Combine::class)
157-
->addMethods(['setRule', 'setId', 'setPrefix'])
158-
->onlyMethods(['loadArray'])
159-
->disableOriginalConstructor()
160-
->getMock();
136+
$conditions = $this->createPartialMockWithReflection(Combine::class, ['loadArray', 'setRule', 'setId', 'setPrefix']);
161137

162138
$conditions->expects($this->once())->method('setRule')->willReturnSelf();
163139
$conditions->expects($this->once())->method('setId')->willReturnSelf();
@@ -176,11 +152,7 @@ public function testGetActions()
176152
{
177153
$actionsArray = ['actions' => 'some_actions'];
178154
$actionsSerialized = json_encode($actionsArray);
179-
$actions = $this->getMockBuilder(Collection::class)
180-
->addMethods(['setRule', 'setId', 'setPrefix'])
181-
->onlyMethods(['loadArray'])
182-
->disableOriginalConstructor()
183-
->getMock();
155+
$actions = $this->createPartialMockWithReflection(Collection::class, ['loadArray', 'setRule', 'setId', 'setPrefix']);
184156

185157
$actions->expects($this->once())->method('setRule')->willReturnSelf();
186158
$actions->expects($this->once())->method('setId')->willReturnSelf();
@@ -197,15 +169,9 @@ public function testGetActions()
197169

198170
public function testBeforeSave()
199171
{
200-
$conditions = $this->getMockBuilder(Combine::class)
201-
->onlyMethods(['asArray'])
202-
->disableOriginalConstructor()
203-
->getMock();
204-
205-
$actions = $this->getMockBuilder(Collection::class)
206-
->onlyMethods(['asArray'])
207-
->disableOriginalConstructor()
208-
->getMock();
172+
$conditions = $this->createPartialMock(Combine::class, ['asArray']);
173+
174+
$actions = $this->createPartialMock(Collection::class, ['asArray']);
209175

210176
$this->model->setConditions($conditions);
211177
$this->model->setActions($actions);

app/code/Magento/Rule/Test/Unit/Model/ActionFactoryTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class ActionFactoryTest extends TestCase
3232

3333
protected function setUp(): void
3434
{
35-
$this->objectManagerMock = $this->getMockForAbstractClass(ObjectManagerInterface::class);
35+
$this->objectManagerMock = $this->createMock(ObjectManagerInterface::class);
3636

3737
$this->objectManagerHelper = new ObjectManagerHelper($this);
3838
$this->actionFactory = $this->objectManagerHelper->getObject(

0 commit comments

Comments
 (0)