Skip to content

Commit 8806093

Browse files
author
silinmykola
committed
Fix Magento Unit Tests to be compatible with PHP 8.1
1 parent 4abe8ff commit 8806093

File tree

15 files changed

+74
-25
lines changed

15 files changed

+74
-25
lines changed

app/code/Magento/Catalog/Test/Unit/Controller/Adminhtml/Product/Attribute/SaveTest.php

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,10 @@ class SaveTest extends AttributeTest
121121
protected function setUp(): void
122122
{
123123
parent::setUp();
124-
$this->filterManagerMock = $this->createMock(FilterManager::class);
124+
$this->filterManagerMock = $this->getMockBuilder(FilterManager::class)
125+
->addMethods(['stripTags'])
126+
->disableOriginalConstructor()
127+
->getMock();
125128
$this->productHelperMock = $this->createMock(ProductHelper::class);
126129
$this->attributeSetMock = $this->createMock(AttributeSetInterface::class);
127130
$this->builderMock = $this->createMock(Build::class);
@@ -132,34 +135,38 @@ protected function setUp(): void
132135
$this->sessionMock = $this->createMock(Session::class);
133136
$this->layoutFactoryMock = $this->createMock(LayoutFactory::class);
134137
$this->buildFactoryMock = $this->getMockBuilder(BuildFactory::class)
135-
->setMethods(['create'])
138+
->onlyMethods(['create'])
136139
->disableOriginalConstructor()
137140
->getMock();
138141
$this->attributeFactoryMock = $this->getMockBuilder(AttributeFactory::class)
139-
->setMethods(['create'])
142+
->onlyMethods(['create'])
140143
->disableOriginalConstructor()
141144
->getMock();
142145
$this->validatorFactoryMock = $this->getMockBuilder(ValidatorFactory::class)
143-
->setMethods(['create'])
146+
->onlyMethods(['create'])
144147
->disableOriginalConstructor()
145148
->getMock();
146149
$this->groupCollectionFactoryMock = $this->getMockBuilder(CollectionFactory::class)
147-
->setMethods(['create'])
150+
->onlyMethods(['create'])
148151
->disableOriginalConstructor()
149152
->getMock();
150153
$this->redirectMock = $this->getMockBuilder(ResultRedirect::class)
151-
->setMethods(['setData', 'setPath'])
154+
->onlyMethods(['setPath'])
155+
->addMethods(['setData'])
152156
->disableOriginalConstructor()
153157
->getMock();
154158
$this->productAttributeMock = $this->getMockBuilder(ProductAttributeInterface::class)
155-
->setMethods(
159+
->onlyMethods(
160+
[
161+
'getBackendType',
162+
'getFrontendClass'
163+
]
164+
)->addMethods(
156165
[
157166
'getId',
158167
'get',
159168
'getBackendTypeByInput',
160169
'getDefaultValueByInput',
161-
'getBackendType',
162-
'getFrontendClass',
163170
'addData',
164171
'save'
165172
]
@@ -292,7 +299,9 @@ public function testExecute()
292299
'new_attribute_set_name' => 'Test attribute set name',
293300
'frontend_input' => 'test_frontend_input',
294301
];
295-
302+
$this->filterManagerMock
303+
->method('stripTags')
304+
->willReturn('Test attribute set name');
296305
$this->requestMock->expects($this->any())
297306
->method('getParam')
298307
->willReturnMap([

app/code/Magento/Catalog/Test/Unit/Model/Category/FileInfoTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,9 @@ function ($arg) use ($baseDirectory, $pubDirectory) {
116116
$this->pubDirectory->method('getAbsolutePath')
117117
->willReturn('/a/b/c/pub/');
118118

119+
$this->store->method('getBaseUrl')
120+
->willReturn('');
121+
119122
$this->model = new FileInfo(
120123
$this->filesystem,
121124
$this->mime,

app/code/Magento/Customer/Model/Metadata/Form/Text.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ private function validateLength($value, AttributeMetadataInterface $attribute, a
126126
// validate length
127127
$label = __($attribute->getStoreLabel());
128128

129-
$length = $this->_string->strlen(trim($value));
129+
$length = $this->_string->strlen(trim((string) $value));
130130

131131
$validateRules = $attribute->getValidationRules();
132132

app/code/Magento/Customer/Test/Unit/Block/Adminhtml/Edit/Tab/View/PersonalInfoTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ public function getStoreLastLoginDateDataProvider()
246246
{
247247
return [
248248
['2015-03-04 12:00:00', '2015-03-04 12:00:00'],
249-
['Never', null]
249+
['Never', '']
250250
];
251251
}
252252

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ public function testExtractValueNoRequestScope($expected, $attributeCode = '', $
130130
'entityTypeCode' => self::ENTITY_TYPE,
131131
]
132132
);
133-
133+
$model->setRequestScope('');
134134
$this->assertEquals($expected, $model->extractValue($this->requestMock));
135135
if (!empty($attributeCode)) {
136136
unset($_FILES[$attributeCode]);

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,6 @@ public function outputValueTextDataProvider()
143143
{
144144
return [
145145
'empty' => ['', ''],
146-
'null' => [null, ''],
147146
'number' => [14, 'fourteen'],
148147
'string' => ['some key', 'some string'],
149148
'array' => [[14, 'some key'], 'fourteen, some string'],

app/code/Magento/MediaStorage/Test/Unit/App/MediaTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ protected function createMediaModel(bool $isAllowed = true): Media
264264
$this->syncFactoryMock,
265265
$this->responseMock,
266266
$isAllowedCallback,
267-
false,
267+
self::MEDIA_DIRECTORY,
268268
self::CACHE_FILE_PATH,
269269
self::RELATIVE_FILE_PATH,
270270
$this->filesystemMock,

app/code/Magento/Paypal/Test/Unit/Model/Api/NvpTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ public function callDataProvider()
197197
10417
198198
],
199199
[
200-
"\r\n" . 'ACK[7]=Failure&L_ERRORCODE0[5]=10417&L_SHORTMESSAGE0[8]=Message.',
200+
"\r\n" . 'ACK[7]=Failure&L_ERRORCODE0[5]=10417&L_SHORTMESSAGE0[8]=Message.&L_LONGMESSAGE0[15]=',
201201
[10417, 10422],
202202
ProcessableException::class,
203203
'PayPal gateway has rejected request. #10417: Message.',

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@ public function testValidateSetEntityAttributeValuesWithResource()
208208
->disableOriginalConstructor()
209209
->getMockForAbstractClass();
210210
$product->setAtribute('attribute');
211+
$product->setData('someAttribute', '');
211212
$product->setId(12);
212213

213214
$this->_configProperty->setValue(

app/code/Magento/Theme/Test/Unit/Model/Wysiwyg/StorageTest.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,10 @@ public function testDeleteDirectory(): void
462462
->willReturn($this->storageRoot);
463463
$this->directoryWrite->expects($this->once())->method('delete')->with($directoryPath);
464464
$this->directoryWrite->expects($this->once())->method('getAbsolutePath')->willreturn('');
465-
465+
$this->filesystemDriver->expects($this->once())
466+
->method('getRealPathSafety')
467+
->with('')
468+
->willReturn('');
466469
$this->storageModel->deleteDirectory($directoryPath);
467470
}
468471

@@ -478,7 +481,10 @@ public function testDeleteRootDirectory(): void
478481
$this->helperStorage->expects($this->atLeastOnce())
479482
->method('getStorageRoot')
480483
->willReturn($this->storageRoot);
481-
484+
$this->filesystemDriver->expects($this->once())
485+
->method('getRealPathSafety')
486+
->with('')
487+
->willReturn('');
482488
$this->storageModel->deleteDirectory($directoryPath);
483489
}
484490

0 commit comments

Comments
 (0)