Skip to content

Commit cbf9754

Browse files
committed
fix unit tests issues found by phpmd
1 parent 2c71908 commit cbf9754

File tree

9 files changed

+61
-12
lines changed

9 files changed

+61
-12
lines changed

app/code/Magento/Catalog/Test/Unit/Model/Layer/Filter/CategoryTest.php

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ class CategoryTest extends TestCase
7676

7777
/**
7878
* @inheritDoc
79+
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
7980
*/
8081
protected function setUp(): void
8182
{
@@ -105,8 +106,7 @@ protected function setUp(): void
105106
'getChildrenCategories',
106107
'getIsActive'
107108
]
108-
)
109-
->getMock();
109+
)->getMock();
110110

111111
$this->dataProvider
112112
->method('getCategory')
@@ -153,8 +153,7 @@ protected function setUp(): void
153153
'setValue',
154154
'setCount'
155155
]
156-
)
157-
->getMock();
156+
)->getMock();
158157
$filterItem->expects($this->any())
159158
->method($this->anything())->willReturnSelf();
160159
$this->filterItemFactory->expects($this->any())
@@ -192,12 +191,23 @@ protected function setUp(): void
192191
public function testApplyWithEmptyRequest($requestValue, $idValue): void
193192
{
194193
$requestField = 'test_request_var';
194+
$idField = 'id';
195195

196196
$this->target->setRequestVar($requestField);
197197

198198
$this->request
199199
->method('getParam')
200-
->with($requestField);
200+
->with($requestField)
201+
->willReturnCallback(
202+
function ($field) use ($requestField, $idField, $requestValue, $idValue) {
203+
switch ($field) {
204+
case $requestField:
205+
return $requestValue;
206+
case $idField:
207+
return $idValue;
208+
}
209+
}
210+
);
201211

202212
$result = $this->target->apply($this->request);
203213
$this->assertSame($this->target, $result);

app/code/Magento/Catalog/Test/Unit/Model/Layer/Filter/PriceTest.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,17 @@ public function testApplyWithEmptyRequest($requestValue, $idValue): void
203203

204204
$this->request
205205
->method('getParam')
206-
->with($requestField);
206+
->with($requestField)
207+
->willReturnCallback(
208+
function ($field) use ($requestField, $idField, $requestValue, $idValue) {
209+
switch ($field) {
210+
case $requestField:
211+
return $requestValue;
212+
case $idField:
213+
return $idValue;
214+
}
215+
}
216+
);
207217

208218
$result = $this->target->apply($this->request);
209219
$this->assertSame($this->target, $result);

app/code/Magento/CatalogSearch/Test/Unit/Model/Layer/Filter/CategoryTest.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,17 @@ public function testApplyWithEmptyRequest($requestValue, $idValue): void
173173
->willReturn([]);
174174

175175
$this->request->method('getParam')
176-
->withConsecutive([$requestField]);
176+
->withConsecutive([$requestField])
177+
->willReturnOnConsecutiveCalls(
178+
function ($field) use ($requestField, $idField, $requestValue, $idValue) {
179+
switch ($field) {
180+
case $requestField:
181+
return $requestValue;
182+
case $idField:
183+
return $idValue;
184+
}
185+
}
186+
);
177187

178188
$result = $this->target->apply($this->request);
179189
$this->assertSame($this->target, $result);

app/code/Magento/CatalogSearch/Test/Unit/Model/Layer/Filter/DecimalTest.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323

2424
/**
2525
* Test for \Magento\CatalogSearch\Model\Layer\Filter\Decimal
26+
*
27+
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
2628
*/
2729
class DecimalTest extends TestCase
2830
{
@@ -177,7 +179,17 @@ public function testApplyWithEmptyRequest(?int $requestValue, $idValue): void
177179

178180
$this->request
179181
->method('getParam')
180-
->with($requestField);
182+
->with($requestField)
183+
->willReturnCallback(
184+
function ($field) use ($requestField, $idField, $requestValue, $idValue) {
185+
switch ($field) {
186+
case $requestField:
187+
return $requestValue;
188+
case $idField:
189+
return $idValue;
190+
}
191+
}
192+
);
181193

182194
$result = $this->target->apply($this->request);
183195
$this->assertSame($this->target, $result);

app/code/Magento/Theme/Test/Unit/Helper/StorageTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -531,7 +531,7 @@ private function initializeDefaultRequestMock(): void
531531
private function resetRequestMock(array $withArgs, array $willReturnArgs): void
532532
{
533533
array_unshift($withArgs, [Storage::PARAM_THEME_ID], [Storage::PARAM_CONTENT_TYPE]);
534-
array_unshift($willReturnArgs, 6, \Magento\Theme\Model\Wysiwyg\Storage::TYPE_IMAGE);
534+
array_unshift($willReturnArgs, 6, \Magento\Theme\Model\Wysiwyg\Storage::TYPE_IMAGE);
535535
$this->request = $this->createMock(Http::class);
536536
$this->contextHelper = $this->createMock(Context::class);
537537
$this->contextHelper->expects($this->any())->method('getUrlEncoder')->willReturn($this->urlEncoder);

app/code/Magento/Theme/Test/Unit/Model/CopyServiceTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525

2626
/**
2727
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
28+
* @SuppressWarnings(PHPMD.TooManyFields)
29+
* @SuppressWarnings(PHPMD.UnusedPrivateField)
2830
*/
2931
class CopyServiceTest extends TestCase
3032
{

lib/internal/Magento/Framework/App/Test/Unit/PageCache/KernelTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ public function dataProviderForResultWithoutCachedData(): array
234234
* @return void
235235
* @dataProvider testProcessSaveCacheDataProvider
236236
*/
237-
public function testProcessSaveCache($httpCode, $at): void
237+
public function testProcessSaveCache($httpCode): void
238238
{
239239
$this->serializer->expects($this->once())
240240
->method('serialize')
@@ -276,8 +276,8 @@ function ($value) {
276276
public function testProcessSaveCacheDataProvider(): array
277277
{
278278
return [
279-
[200, [3, 4, 5]],
280-
[404, [4, 5, 6]]
279+
[200],
280+
[404]
281281
];
282282
}
283283

lib/internal/Magento/Framework/Composer/Test/Unit/DependencyCheckerTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ class DependencyCheckerTest extends TestCase
1616
{
1717
/**
1818
* @return void
19+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
1920
*/
2021
public function testCheckDependencies(): void
2122
{
@@ -59,6 +60,7 @@ function ($input, $buffer) {
5960

6061
/**
6162
* @return void
63+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
6264
*/
6365
public function testCheckDependenciesExcludeSelf(): void
6466
{

setup/src/Magento/Setup/Test/Unit/Model/InstallerTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -549,6 +549,7 @@ public function installDataProvider()
549549
* @throws \Magento\Framework\Exception\FileSystemException
550550
* @throws \Magento\Framework\Exception\LocalizedException
551551
* @throws \Magento\Framework\Exception\RuntimeException
552+
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
552553
*/
553554
public function testInstallWithInvalidRemoteStorageConfiguration(bool $isDeploymentConfigWritable)
554555
{
@@ -732,6 +733,7 @@ public function installWithInvalidRemoteStorageConfigurationDataProvider()
732733
* @throws \Magento\Framework\Exception\FileSystemException
733734
* @throws \Magento\Framework\Exception\LocalizedException
734735
* @throws \Magento\Framework\Exception\RuntimeException
736+
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
735737
*/
736738
public function testInstallWithUnresolvableRemoteStorageValidator()
737739
{
@@ -911,6 +913,7 @@ public function testInstallWithUnresolvableRemoteStorageValidator()
911913
* @throws \Magento\Framework\Exception\FileSystemException
912914
* @throws \Magento\Framework\Exception\LocalizedException
913915
* @throws \Magento\Framework\Exception\RuntimeException
916+
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
914917
*/
915918
public function testInstallWithInvalidRemoteStorageConfigurationWithEarlyException(\Exception $exception)
916919
{

0 commit comments

Comments
 (0)