Skip to content

Commit 9a72a4f

Browse files
committed
Merge remote-tracking branch 'karyna/php8-compatibility/fix-unit-tests-to-be-comptaible-with-php8' into platform-health
2 parents bc783ff + 4789a2e commit 9a72a4f

File tree

29 files changed

+168
-134
lines changed

29 files changed

+168
-134
lines changed

app/code/Magento/Captcha/Test/Unit/Model/DefaultTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,9 @@ class DefaultTest extends TestCase
5151
'case_sensitive' => '0',
5252
'shown_to_logged_in_user' => ['contact_us' => 1],
5353
'always_for' => [
54-
'user_create',
55-
'user_forgotpassword',
56-
'contact_us',
54+
'user_create' => '1',
55+
'user_forgotpassword' => '1',
56+
'contact_us' => '1'
5757
],
5858
];
5959

app/code/Magento/Catalog/Model/ProductLink/CollectionProvider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ function (array $itemA, array $itemB): int {
8888
$posA = (int)$itemA['position'];
8989
$posB = (int)$itemB['position'];
9090

91-
return $posA <=> $posB;
91+
return (($posA - $posB) > 0) ? 1 : -1; // for PHP 7 and 8 consistency
9292
}
9393
);
9494

app/code/Magento/CatalogImportExport/Test/Unit/Model/Import/ProductTest.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1607,10 +1607,12 @@ function ($name) use ($throwException, $exception) {
16071607
*/
16081608
public function testGetProductCategoriesDataSave(array $categoriesData, string $tableName, array $result)
16091609
{
1610-
$this->_connection->expects($this->at(1))->method('fetchOne')->willReturn('0');
1611-
$this->_connection->expects($this->at(3))->method('fetchOne')->willReturn('-2');
1612-
$this->skuProcessor->expects($this->at(0))->method('getNewSku')->willReturn(['entity_id' => 2]);
1613-
$this->skuProcessor->expects($this->at(1))->method('getNewSku')->willReturn(['entity_id' => 5]);
1610+
$this->_connection->method('fetchOne')->willReturnOnConsecutiveCalls('0', '-2');
1611+
$this->skuProcessor->method('getNewSku')
1612+
->willReturnOnConsecutiveCalls(
1613+
['entity_id' => 2],
1614+
['entity_id' => 5]
1615+
);
16141616
$actualResult = $this->invokeMethod(
16151617
$this->importProduct,
16161618
'getProductCategoriesDataSave',

app/code/Magento/CatalogInventory/Test/Unit/Model/Config/Backend/ManagestockTest.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,18 @@
99

1010
use Magento\CatalogInventory\Model\Config\Backend\Managestock;
1111
use Magento\CatalogInventory\Model\Indexer\Stock\Processor;
12+
use Magento\Framework\App\Config\ScopeConfigInterface;
1213
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
1314
use PHPUnit\Framework\MockObject\MockObject;
1415
use PHPUnit\Framework\TestCase;
1516

1617
class ManagestockTest extends TestCase
1718
{
19+
/**
20+
* @var ScopeConfigInterface|MockObject
21+
*/
22+
private $configMock;
23+
1824
/** @var Processor|MockObject */
1925
protected $stockIndexerProcessor;
2026

@@ -27,10 +33,15 @@ protected function setUp(): void
2733
Processor::class
2834
)->disableOriginalConstructor()
2935
->getMock();
36+
$this->configMock = $this->getMockBuilder(ScopeConfigInterface::class)
37+
->disableOriginalConstructor()
38+
->getMock();
39+
3040
$this->model = (new ObjectManager($this))->getObject(
3141
Managestock::class,
3242
[
33-
'stockIndexerProcessor' => $this->stockIndexerProcessor,
43+
'config' => $this->configMock,
44+
'stockIndexerProcessor' => $this->stockIndexerProcessor
3445
]
3546
);
3647
}
@@ -57,6 +68,8 @@ public function testSaveAndRebuildIndex($newStockValue, $callCount)
5768
{
5869
$this->model->setValue($newStockValue);
5970
$this->stockIndexerProcessor->expects($this->exactly($callCount))->method('markIndexerAsInvalid');
71+
$this->configMock->method('getValue')->willReturn(0); // old value for stock status
72+
6073
$this->model->afterSave();
6174
}
6275
}

app/code/Magento/CatalogRule/Test/Unit/Model/RuleTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ public function validateDataDataProvider(): array
278278
[
279279
[
280280
'simple_action' => 'by_percent',
281-
'discount_amount' => '9,99'
281+
'discount_amount' => '9.99'
282282
],
283283
true
284284
],
@@ -430,8 +430,8 @@ public function isRuleBehaviorChangedDataProvider(): array
430430
}
431431

432432
/**
433-
* @return void
434-
*/
433+
* @return void
434+
*/
435435
public function testGetConditionsFieldSetId(): void
436436
{
437437
$formName = 'form_name';
@@ -441,8 +441,8 @@ public function testGetConditionsFieldSetId(): void
441441
}
442442

443443
/**
444-
* @return void
445-
*/
444+
* @return void
445+
*/
446446
public function testReindex(): void
447447
{
448448
$this->ruleProductProcessor->expects($this->once())->method('reindexList');

app/code/Magento/CatalogUrlRewrite/Observer/AfterImportDataObserver.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
67
namespace Magento\CatalogUrlRewrite\Observer;
78

89
use Magento\Catalog\Model\Category;
@@ -397,7 +398,7 @@ private function generateUrls()
397398
*/
398399
private function isGlobalScope($storeId)
399400
{
400-
return null === $storeId || $storeId == Store::DEFAULT_STORE_ID;
401+
return null === $storeId || Store::DEFAULT_STORE_ID === (int) $storeId;
401402
}
402403

403404
/**

app/code/Magento/Customer/Test/Unit/Model/Metadata/Form/FileTest.php

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

88
namespace Magento\Customer\Test\Unit\Model\Metadata\Form;
99

10+
use Magento\Customer\Model\Customer;
1011
use Magento\Customer\Model\FileProcessor;
1112
use Magento\Customer\Model\FileProcessorFactory;
1213
use Magento\Customer\Model\Metadata\ElementFactory;
@@ -362,8 +363,8 @@ public function validateValueToUploadDataProvider(): array
362363
}
363364

364365
/**
365-
* @return void
366-
*/
366+
* @return void
367+
*/
367368
public function testCompactValueIsAjax(): void
368369
{
369370
$model = $this->initialize(
@@ -378,8 +379,8 @@ public function testCompactValueIsAjax(): void
378379
}
379380

380381
/**
381-
* @return void
382-
*/
382+
* @return void
383+
*/
383384
public function testCompactValueNoDelete(): void
384385
{
385386
$this->attributeMetadataMock->expects($this->any())->method('isRequired')->will($this->returnValue(false));
@@ -388,7 +389,7 @@ public function testCompactValueNoDelete(): void
388389
[
389390
'value' => 'value',
390391
'isAjax' => false,
391-
'entityTypeCode' => self::ENTITY_TYPE
392+
'entityTypeCode' => Customer::ENTITY
392393
]
393394
);
394395

@@ -401,8 +402,8 @@ public function testCompactValueNoDelete(): void
401402
}
402403

403404
/**
404-
* @return void
405-
*/
405+
* @return void
406+
*/
406407
public function testCompactValueDelete(): void
407408
{
408409
$this->attributeMetadataMock->expects($this->any())->method('isRequired')->will($this->returnValue(false));
@@ -431,8 +432,8 @@ public function testCompactValueDelete(): void
431432
}
432433

433434
/**
434-
* @return void
435-
*/
435+
* @return void
436+
*/
436437
public function testCompactValueTmpFile(): void
437438
{
438439
$value = ['tmp_name' => 'tmp.file', 'name' => 'new.file'];
@@ -486,8 +487,8 @@ public function testCompactValueTmpFile(): void
486487
}
487488

488489
/**
489-
* @return void
490-
*/
490+
* @return void
491+
*/
491492
public function testRestoreValue(): void
492493
{
493494
$value = 'value';
@@ -537,8 +538,8 @@ public function outputValueDataProvider(): array
537538
}
538539

539540
/**
540-
* @return void
541-
*/
541+
* @return void
542+
*/
542543
public function testOutputValueJson(): void
543544
{
544545
$value = 'value';
@@ -591,8 +592,8 @@ private function initialize(array $data)
591592
}
592593

593594
/**
594-
* @return void
595-
*/
595+
* @return void
596+
*/
596597
public function testExtractValueFileUploaderUIComponent(): void
597598
{
598599
$attributeCode = 'img1';
@@ -631,8 +632,8 @@ public function testExtractValueFileUploaderUIComponent(): void
631632
}
632633

633634
/**
634-
* @return void
635-
*/
635+
* @return void
636+
*/
636637
public function testCompactValueRemoveUiComponentValue(): void
637638
{
638639
$value = 'value';
@@ -641,7 +642,7 @@ public function testCompactValueRemoveUiComponentValue(): void
641642
[
642643
'value' => $value,
643644
'isAjax' => false,
644-
'entityTypeCode' => self::ENTITY_TYPE
645+
'entityTypeCode' => Customer::ENTITY
645646
]
646647
);
647648

@@ -654,8 +655,8 @@ public function testCompactValueRemoveUiComponentValue(): void
654655
}
655656

656657
/**
657-
* @return void
658-
*/
658+
* @return void
659+
*/
659660
public function testCompactValueNoAction(): void
660661
{
661662
$value = 'value';
@@ -672,8 +673,8 @@ public function testCompactValueNoAction(): void
672673
}
673674

674675
/**
675-
* @return void
676-
*/
676+
* @return void
677+
*/
677678
public function testCompactValueUiComponent(): void
678679
{
679680
$value = [
@@ -697,8 +698,8 @@ public function testCompactValueUiComponent(): void
697698
}
698699

699700
/**
700-
* @return void
701-
*/
701+
* @return void
702+
*/
702703
public function testCompactValueInputField(): void
703704
{
704705
$value = [
@@ -769,8 +770,8 @@ public function testCompactValueInputField(): void
769770
}
770771

771772
/**
772-
* @return void
773-
*/
773+
* @return void
774+
*/
774775
public function testCompactValueInputFieldWithException(): void
775776
{
776777
$value = [

app/code/Magento/ImportExport/Test/Unit/Model/Import/EntityAbstractTest.php

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ protected function _getModelDependencies()
7171
$resource = $this->createMock(ResourceConnection::class);
7272

7373
$data = [
74-
'coreString' => $string,
74+
'string' => $string,
7575
'scopeConfig' => $scopeConfig,
7676
'importFactory' => $importFactory,
7777
'resourceHelper' => $resourceHelper,
@@ -369,13 +369,17 @@ public function dataProviderForTestGetBehaviorWithRowData()
369369
* @covers \Magento\ImportExport\Model\Import\AbstractEntity::getBehavior
370370
*
371371
* @dataProvider dataProviderForTestGetBehaviorWithRowData
372-
* @param $inputBehavior
373-
* @param $rowData
374-
* @param $expectedBehavior
375-
* @param null $availableBehaviors
372+
* @param string $inputBehavior
373+
* @param array|null $rowData
374+
* @param string $expectedBehavior
375+
* @param array|null $availableBehaviors
376376
*/
377-
public function testGetBehaviorWithRowData($inputBehavior, $rowData, $expectedBehavior, $availableBehaviors = null)
378-
{
377+
public function testGetBehaviorWithRowData(
378+
string $inputBehavior,
379+
?array $rowData,
380+
string $expectedBehavior,
381+
?array $availableBehaviors = null
382+
) {
379383
$property = new \ReflectionProperty($this->_model, '_availableBehaviors');
380384
$property->setAccessible(true);
381385

app/code/Magento/Quote/Test/Unit/Model/Quote/Item/UpdaterTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ public function testUpdateNotQtyDecimal($qty, $expectedQty)
142142
->method('getProduct')
143143
->willReturn($this->productMock);
144144

145-
$result = $this->object->update($this->itemMock, ['qty' => $qty]);
145+
$result = $this->object->update($this->itemMock, ['qty' => (double) $qty]);
146146
$this->assertEquals($result, $this->object);
147147
}
148148

@@ -211,7 +211,7 @@ public function testUpdateQtyDecimal($qty, $expectedQty)
211211
->method('getProduct')
212212
->willReturn($this->productMock);
213213

214-
$object = $this->object->update($this->itemMock, ['qty' => $qty]);
214+
$object = $this->object->update($this->itemMock, ['qty' => (double) $qty]);
215215
$this->assertEquals($this->object, $object);
216216
}
217217

app/code/Magento/Quote/Test/Unit/Model/QuoteManagementTest.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -717,6 +717,8 @@ public function testAssignCustomer(): void
717717

718718
/**
719719
* @return void
720+
*
721+
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
720722
*/
721723
public function testSubmit(): void
722724
{
@@ -861,7 +863,7 @@ public function testPlaceOrderIfCustomerIsGuest(): void
861863
->setConstructorArgs(
862864
[
863865
'eventManager' => $this->eventManager,
864-
'quoteValidator' => $this->submitQuoteValidator,
866+
'submitQuoteValidator' => $this->submitQuoteValidator,
865867
'orderFactory' => $this->orderFactory,
866868
'orderManagement' => $this->orderManagement,
867869
'customerManagement' => $this->customerManagement,
@@ -929,7 +931,7 @@ public function testPlaceOrder(): void
929931
->setConstructorArgs(
930932
[
931933
'eventManager' => $this->eventManager,
932-
'quoteValidator' => $this->submitQuoteValidator,
934+
'submitQuoteValidator' => $this->submitQuoteValidator,
933935
'orderFactory' => $this->orderFactory,
934936
'orderManagement' => $this->orderManagement,
935937
'customerManagement' => $this->customerManagement,

0 commit comments

Comments
 (0)