Skip to content

Commit 3dfe3b2

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

File tree

7 files changed

+59
-19
lines changed

7 files changed

+59
-19
lines changed

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,10 @@ public function testGetConditions()
133133
{
134134
$conditionsArray = ['conditions' => 'serialized'];
135135
$serializedConditions = json_encode($conditionsArray);
136-
$conditions = $this->createPartialMockWithReflection(Combine::class, ['loadArray', 'setRule', 'setId', 'setPrefix']);
136+
$conditions = $this->createPartialMockWithReflection(
137+
Combine::class,
138+
['loadArray', 'setRule', 'setId', 'setPrefix']
139+
);
137140

138141
$conditions->expects($this->once())->method('setRule')->willReturnSelf();
139142
$conditions->expects($this->once())->method('setId')->willReturnSelf();
@@ -152,7 +155,10 @@ public function testGetActions()
152155
{
153156
$actionsArray = ['actions' => 'some_actions'];
154157
$actionsSerialized = json_encode($actionsArray);
155-
$actions = $this->createPartialMockWithReflection(Collection::class, ['loadArray', 'setRule', 'setId', 'setPrefix']);
158+
$actions = $this->createPartialMockWithReflection(
159+
Collection::class,
160+
['loadArray', 'setRule', 'setId', 'setPrefix']
161+
);
156162

157163
$actions->expects($this->once())->method('setRule')->willReturnSelf();
158164
$actions->expects($this->once())->method('setId')->willReturnSelf();

app/code/Magento/Rule/Test/Unit/Model/Condition/Product/AbstractProductTest.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,10 @@ public function testPrepareValueOptions(
335335
->with($expectedAttrObjSourceAllOptionsParam, true)
336336
->willReturn($attrObjectSourceAllOptionsValue);
337337

338-
$attributeObjectMock = $this->createPartialMockWithReflection(Attribute::class, ['usesSource', 'getFrontendInput', 'getSource', 'getAllOptions']);
338+
$attributeObjectMock = $this->createPartialMockWithReflection(
339+
Attribute::class,
340+
['usesSource', 'getFrontendInput', 'getSource', 'getAllOptions']
341+
);
339342
$attributeObjectMock->method('usesSource')->willReturn(true);
340343
$attributeObjectMock
341344
->expects((null === $attributeObjectFrontendInput) ? $this->never() : $this->once())
@@ -360,7 +363,10 @@ public function testPrepareValueOptions(
360363
$configProperty->setAccessible(true);
361364
$configProperty->setValue($this->_condition, $configValueMock);
362365

363-
$attrSetCollectionValueMock = $this->createPartialMock(Collection::class, ['setEntityTypeFilter', 'load', 'toOptionArray']);
366+
$attrSetCollectionValueMock = $this->createPartialMock(
367+
Collection::class,
368+
['setEntityTypeFilter', 'load', 'toOptionArray']
369+
);
364370

365371
$attrSetCollectionValueMock->method('setEntityTypeFilter')->willReturnSelf();
366372
$attrSetCollectionValueMock->method('load')->willReturnSelf();

app/code/Magento/Rule/Test/Unit/Model/Condition/Sql/BuilderTest.php

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,10 @@ protected function setUp(): void
5353
*/
5454
public function testAttachConditionToCollection(): void
5555
{
56-
$collection = $this->createPartialMockWithReflection(AbstractCollection::class, ['getResource', 'getSelect', 'getStoreId', 'getDefaultStoreId']);
56+
$collection = $this->createPartialMockWithReflection(
57+
AbstractCollection::class,
58+
['getResource', 'getSelect', 'getStoreId', 'getDefaultStoreId']
59+
);
5760
$combine = $this->createPartialMock(Combine::class, ['getConditions']);
5861
$resource = $this->createPartialMock(Mysql::class, ['getConnection']);
5962
$select = $this->createPartialMock(Select::class, ['where']);
@@ -87,7 +90,10 @@ public function testAttachConditionToCollection(): void
8790
*/
8891
public function testAttachConditionAsHtmlToCollection(): void
8992
{
90-
$abstractCondition = $this->createPartialMockWithReflection(AbstractCondition::class, ['getOperatorForValidate', 'getMappedSqlField', 'getAttribute', 'getBindArgumentValue']);
93+
$abstractCondition = $this->createPartialMockWithReflection(
94+
AbstractCondition::class,
95+
['getOperatorForValidate', 'getMappedSqlField', 'getAttribute', 'getBindArgumentValue']
96+
);
9197

9298
$abstractCondition->expects($this->once())->method('getMappedSqlField')->willReturn('argument');
9399
$abstractCondition->expects($this->once())->method('getOperatorForValidate')->willReturn('>');
@@ -104,7 +110,10 @@ public function testAttachConditionAsHtmlToCollection(): void
104110
'getSelect'
105111
]
106112
);
107-
$combine = $this->createPartialMockWithReflection(Combine::class, ['getConditions', 'getValue', 'getAggregator']);
113+
$combine = $this->createPartialMockWithReflection(
114+
Combine::class,
115+
['getConditions', 'getValue', 'getAggregator']
116+
);
108117

109118
$resource = $this->createPartialMock(Mysql::class, ['getConnection']);
110119
$select = $this->createPartialMock(Select::class, ['where']);

app/code/Magento/Rule/Test/Unit/Model/Renderer/ActionsTest.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,10 @@ protected function setUp(): void
4343

4444
public function testRender()
4545
{
46-
$rule = $this->createPartialMock(AbstractModel::class, ['getActions', '__sleep', '__wakeup', 'getConditionsInstance', 'getActionsInstance']);
46+
$rule = $this->createPartialMock(
47+
AbstractModel::class,
48+
['getActions', '__sleep', '__wakeup', 'getConditionsInstance', 'getActionsInstance']
49+
);
4750
$actions = $this->createPartialMock(Collection::class, ['asHtmlRecursive']);
4851

4952
$this->_element->expects($this->any())

app/code/Magento/Rule/Test/Unit/Model/Renderer/ConditionsTest.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,10 @@ protected function setUp(): void
4343

4444
public function testRender()
4545
{
46-
$rule = $this->createPartialMock(AbstractModel::class, ['getConditions', '__sleep', '__wakeup', 'getConditionsInstance', 'getActionsInstance']);
46+
$rule = $this->createPartialMock(
47+
AbstractModel::class,
48+
['getConditions', '__sleep', '__wakeup', 'getConditionsInstance', 'getActionsInstance']
49+
);
4750
$conditions = $this->createPartialMock(Combine::class, ['asHtmlRecursive']);
4851

4952
$this->_element->expects($this->any())

app/code/Magento/Sitemap/Test/Unit/Model/ResourceModel/Cms/PageTest.php

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -140,15 +140,7 @@ public function testGetCollection()
140140
)->willReturnSelf();
141141
$select->expects($this->exactly(3))
142142
->method('where')
143-
->willReturnCallback(function ($arg1, $arg2 = null) use ($pageIdentifiers, $storeId, $select) {
144-
if ($arg1 == 'main_table.is_active = 1') {
145-
return $select;
146-
} elseif ($arg1 == 'main_table.identifier NOT IN (?)' && $arg2 == array_values($pageIdentifiers)) {
147-
return $select;
148-
} elseif ($arg1 == 'store_table.store_id IN(?)' && $arg2 == [0, $storeId]) {
149-
return $select;
150-
}
151-
});
143+
->willReturnCallback($this->getWhereCallbackForSelect($pageIdentifiers, $storeId, $select));
152144

153145
$connection = $this->createMock(AdapterInterface::class);
154146
$connection->expects($this->once())
@@ -190,4 +182,25 @@ public function testGetCollection()
190182
$resultPage = array_shift($result);
191183
$this->assertEquals($expectedPage, $resultPage);
192184
}
185+
186+
/**
187+
* Get callback for select where method.
188+
*
189+
* @param array<string, string> $pageIdentifiers
190+
* @param int $storeId
191+
* @param MockObject $select
192+
* @return callable
193+
*/
194+
private function getWhereCallbackForSelect(array $pageIdentifiers, int $storeId, MockObject $select): callable
195+
{
196+
return function ($arg1, $arg2 = null) use ($pageIdentifiers, $storeId, $select) {
197+
if ($arg1 == 'main_table.is_active = 1') {
198+
return $select;
199+
} elseif ($arg1 == 'main_table.identifier NOT IN (?)' && $arg2 == array_values($pageIdentifiers)) {
200+
return $select;
201+
} elseif ($arg1 == 'store_table.store_id IN(?)' && $arg2 == [0, $storeId]) {
202+
return $select;
203+
}
204+
};
205+
}
193206
}

app/code/Magento/Sitemap/Test/Unit/Model/SitemapTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,7 @@ protected function prepareSitemapModelMock(
463463

464464
$this->store->expects($this->atLeastOnce())
465465
->method('getBaseUrl')
466-
->with($this->isString(), false)
466+
->with($this->callback('is_string'), false)
467467
->willReturn('http://store.com/');
468468

469469
return $model;

0 commit comments

Comments
 (0)