Skip to content

Commit f1e92c8

Browse files
committed
Merge remote-tracking branch 'anzin/php8.1-compatibility/fix-unit-tests-to-be-comptaible-with-php8.1' into platform-health
2 parents 7912858 + 07ee647 commit f1e92c8

File tree

19 files changed

+77
-30
lines changed

19 files changed

+77
-30
lines changed

app/code/Magento/Backend/Block/Widget/Grid/Column.php

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@ class Column extends Widget
103103
protected $_isGrouped = false;
104104

105105
/**
106+
* Set property is grouped.
107+
*
106108
* @return void
107109
*/
108110
public function _construct()
@@ -169,7 +171,8 @@ public function getHtmlProperty()
169171
}
170172

171173
/**
172-
* Get Header html
174+
* This method get Header html.
175+
*
173176
* @return string
174177
*/
175178
public function getHeaderHtml()
@@ -222,7 +225,8 @@ public function setSortable($value)
222225
}
223226

224227
/**
225-
* Get header css class name
228+
* Get header css class name.
229+
*
226230
* @return string
227231
*/
228232
public function getHeaderCssClass()
@@ -234,6 +238,8 @@ public function getHeaderCssClass()
234238
}
235239

236240
/**
241+
* This method check if is sortable.
242+
*
237243
* @return bool
238244
* @SuppressWarnings(PHPMD.BooleanGetMethodName)
239245
*/
@@ -256,6 +262,7 @@ public function addHeaderCssClass($className)
256262

257263
/**
258264
* Get header class names
265+
*
259266
* @return string
260267
*/
261268
public function getHeaderHtmlProperty()
@@ -291,6 +298,7 @@ public function getRowField(\Magento\Framework\DataObject $row)
291298
$frameCallback = $this->getFrameCallback();
292299
if (is_array($frameCallback)) {
293300
$this->validateFrameCallback($frameCallback);
301+
//phpcs:ignore Magento2.Functions.DiscouragedFunction
294302
$renderedValue = call_user_func($frameCallback, $renderedValue, $row, $this, false);
295303
}
296304

@@ -334,6 +342,7 @@ public function getRowFieldExport(\Magento\Framework\DataObject $row)
334342
$frameCallback = $this->getFrameCallback();
335343
if (is_array($frameCallback)) {
336344
$this->validateFrameCallback($frameCallback);
345+
//phpcs:ignore Magento2.Functions.DiscouragedFunction
337346
$renderedValue = call_user_func($frameCallback, $renderedValue, $row, $this, true);
338347
}
339348

@@ -412,7 +421,7 @@ public function setRendererType($type, $className)
412421
*/
413422
protected function _getRendererByType()
414423
{
415-
$type = strtolower($this->getType());
424+
$type = strtolower((string) $this->getType());
416425
$rendererClass = isset(
417426
$this->_rendererTypes[$type]
418427
) ? $this->_rendererTypes[$type] : $this->_rendererTypes['default'];
@@ -469,7 +478,7 @@ public function setFilterType($type, $className)
469478
*/
470479
protected function _getFilterByType()
471480
{
472-
$type = $this->getFilterType() ? strtolower($this->getFilterType()) : strtolower($this->getType());
481+
$type = $this->getFilterType() ? strtolower($this->getFilterType()) : strtolower((string) $this->getType());
473482
$filterClass = isset($this->_filterTypes[$type]) ? $this->_filterTypes[$type] : $this->_filterTypes['default'];
474483

475484
return $filterClass;

app/code/Magento/Backend/Block/Widget/Grid/Column/Filter/Date.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ protected function _convertDate($date)
233233
\IntlDateFormatter::NONE,
234234
$adminTimeZone
235235
);
236-
$simpleRes = new \DateTime(null, $adminTimeZone);
236+
$simpleRes = new \DateTime('now', $adminTimeZone);
237237
$simpleRes->setTimestamp($formatter->parse($date));
238238
$simpleRes->setTime(0, 0, 0);
239239
$simpleRes->setTimezone(new \DateTimeZone('UTC'));

app/code/Magento/Backend/Block/Widget/Grid/Column/Renderer/Concat.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,12 @@ public function render(\Magento\Framework\DataObject $row)
3030
&& is_callable([$row, $method])
3131
&& substr_compare('get', $method, 1, 3) !== 0
3232
) {
33+
//phpcs:ignore Magento2.Functions.DiscouragedFunction
3334
$data = call_user_func([$row, $method]);
3435
} else {
3536
$data = $row->getData($method);
3637
}
37-
if (strlen($data) > 0) {
38+
if (strlen((string) $data) > 0) {
3839
$dataArr[] = $data;
3940
}
4041
}

app/code/Magento/Bundle/Model/Option/Validator.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,10 @@ public function __construct(NotEmptyFactory $notEmptyFactory)
2626
}
2727

2828
/**
29+
* This method check is valid value.
30+
*
2931
* @param \Magento\Bundle\Model\Option $value
32+
*
3033
* @return boolean
3134
* @throws Zend_Validate_Exception If validation of $value is impossible
3235
*/
@@ -38,10 +41,12 @@ public function isValid($value)
3841
}
3942

4043
/**
44+
* This method validate required fields.
45+
*
4146
* @param \Magento\Bundle\Model\Option $value
47+
*
4248
* @return void
43-
* @throws Zend_Validate_Exception
44-
* @throws \Exception
49+
* @throws \Exception|Zend_Validate_Exception
4550
*/
4651
protected function validateRequiredFields($value)
4752
{
@@ -51,7 +56,7 @@ protected function validateRequiredFields($value)
5156
'type' => $value->getType()
5257
];
5358
foreach ($requiredFields as $requiredField => $requiredValue) {
54-
if (!$this->notEmpty->isValid(trim($requiredValue))) {
59+
if (!$this->notEmpty->isValid(trim((string) $requiredValue))) {
5560
$messages[$requiredField] =
5661
__('"%fieldName" is required. Enter and try again.', ['fieldName' => $requiredField]);
5762
}

app/code/Magento/Paypal/Model/Express.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -843,7 +843,7 @@ protected function _isTransactionExpired(Transaction $transaction, $period)
843843
$transactionClosingDate->setTime(11, 49, 00);
844844
$transactionClosingDate->modify('+' . $period . ' days');
845845

846-
$currentTime = new \DateTime(null, new \DateTimeZone('US/Pacific'));
846+
$currentTime = new \DateTime('now', new \DateTimeZone('US/Pacific'));
847847

848848
if ($currentTime > $transactionClosingDate) {
849849
return true;

app/code/Magento/Reports/Model/ResourceModel/Order/Collection.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ protected function _getRangeExpression($range)
352352
protected function _getRangeExpressionForAttribute($range, $attribute)
353353
{
354354
$expression = $this->_getRangeExpression($range);
355-
return str_replace('{{attribute}}', $this->getConnection()->quoteIdentifier($attribute), $expression);
355+
return str_replace('{{attribute}}', $this->getConnection()->quoteIdentifier($attribute), (string) $expression);
356356
}
357357

358358
/**
@@ -369,7 +369,7 @@ protected function _getTZRangeOffsetExpression($range, $attribute, $from = null,
369369
return str_replace(
370370
'{{attribute}}',
371371
$this->_reportOrderFactory->create()->getStoreTZOffsetQuery($this->getMainTable(), $attribute, $from, $to),
372-
$this->_getRangeExpression($range)
372+
(string) $this->_getRangeExpression($range)
373373
);
374374
}
375375

app/code/Magento/Reports/Test/Unit/Model/ResourceModel/Order/CollectionTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,11 @@ public function testPrepareSummary($useAggregatedData, $mainTable, $isFilter, $g
261261
->expects($getIfNullSqlResult)
262262
->method('getIfNullSql');
263263

264+
$this->connectionMock->expects($this->once())
265+
->method('getDateFormatSql')
266+
->with('{{attribute}}', '%Y-%m')
267+
->willReturn(new \Zend_Db_Expr('DATE_FORMAT(%2021-%10, %Y-%m)'));
268+
264269
$this->collection->prepareSummary($range, $customStart, $customEnd, $isFilter);
265270
}
266271

app/code/Magento/Rule/Model/Condition/Product/AbstractProduct.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -546,7 +546,7 @@ public function validate(\Magento\Framework\Model\AbstractModel $model)
546546
$attr = $model->getResource()->getAttribute($attrCode);
547547

548548
if ($attr && $attr->getBackendType() == 'datetime' && !is_int($this->getValue())) {
549-
$this->setValue(strtotime($this->getValue()));
549+
$this->setValue(strtotime((string) $this->getValue()));
550550
$value = strtotime($model->getData($attrCode));
551551
return $this->validateAttribute($value);
552552
}

app/code/Magento/Rule/Model/Condition/Sql/Builder.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,15 +173,21 @@ protected function _getMappedSqlCondition(
173173
) {
174174
$sql = str_replace(
175175
':field',
176-
$this->_connection->getIfNullSql($this->_connection->quoteIdentifier($argument), $defaultValue),
176+
(string) $this->_connection->getIfNullSql(
177+
$this->_connection->quoteIdentifier($argument),
178+
$defaultValue
179+
),
177180
$this->stringConditionOperatorMap[$conditionOperator]
178181
);
179182
$bindValue = $condition->getBindArgumentValue();
180183
$expression = $value . $this->_connection->quoteInto($sql, "%$bindValue%");
181184
} else {
182185
$sql = str_replace(
183186
':field',
184-
$this->_connection->getIfNullSql($this->_connection->quoteIdentifier($argument), $defaultValue),
187+
(string) $this->_connection->getIfNullSql(
188+
$this->_connection->quoteIdentifier($argument),
189+
$defaultValue
190+
),
185191
$this->_conditionOperatorMap[$conditionOperator]
186192
);
187193
$bindValue = $condition->getBindArgumentValue();

app/code/Magento/Shipping/Model/Simplexml/Element.php

Lines changed: 2 additions & 3 deletions
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\Shipping\Model\Simplexml;
78

89
/**
@@ -21,9 +22,7 @@ class Element extends \Magento\Framework\Simplexml\Element
2122
*/
2223
public function addAttribute($name, $value = null, $namespace = null)
2324
{
24-
if ($value !== null) {
25-
$value = $this->xmlentities($value);
26-
}
25+
$value = $value !== null ? $this->xmlentities($value) : '';
2726
parent::addAttribute($name, $value, $namespace);
2827
}
2928

app/code/Magento/Usps/Model/Carrier.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -478,8 +478,8 @@ protected function _getXmlQuotes()
478478
$service = $r->getService();
479479
}
480480

481-
if (strpos($r->getContainer(), 'FLAT RATE ENVELOPE') !== false ||
482-
strpos($r->getContainer(), 'FLAT RATE BOX') !== false
481+
if ($r->getContainer() !== null && (strpos($r->getContainer(), 'FLAT RATE ENVELOPE') !== false ||
482+
strpos($r->getContainer(), 'FLAT RATE BOX') !== false)
483483
) {
484484
$service = 'Priority';
485485
}

app/code/Magento/Webapi/Model/Soap/Wsdl/ComplexTypeStrategy.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ public function addAnnotation(\DOMElement $element, $documentation, $default = n
222222
$appInfoNode->setAttributeNS(
223223
Wsdl::XML_NS_URI,
224224
Wsdl::XML_NS . ':' . self::APP_INF_NS,
225-
$this->getContext()->getTargetNamespace()
225+
(string) $this->getContext()->getTargetNamespace()
226226
);
227227

228228
$this->_processDefaultValueAnnotation($elementType, $default, $appInfoNode);

app/code/Magento/Webapi/Test/Unit/Model/Rest/Swagger/GeneratorTest.php

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

88
namespace Magento\Webapi\Test\Unit\Model\Rest\Swagger;
99

10+
use Magento\Framework\App\ProductMetadata;
1011
use Magento\Framework\Exception\LocalizedException;
1112
use Magento\Framework\Reflection\TypeProcessor;
1213
use Magento\Framework\Serialize\Serializer\Json;
@@ -62,6 +63,14 @@ class GeneratorTest extends TestCase
6263
*/
6364
private $serializer;
6465

66+
/**
67+
* @var ProductMetadata|MockObject
68+
*/
69+
private $productMetadata;
70+
71+
/**
72+
* @inheritdoc
73+
*/
6574
protected function setUp(): void
6675
{
6776
$this->serviceMetadataMock = $this->getMockBuilder(
@@ -127,6 +136,7 @@ function ($value) {
127136
return json_encode($value);
128137
}
129138
);
139+
$this->productMetadata = $this->createMock(ProductMetadata::class);
130140

131141
$this->generator = $this->objectManager->getObject(
132142
Generator::class,
@@ -137,7 +147,8 @@ function ($value) {
137147
'serviceMetadata' => $this->serviceMetadataMock,
138148
'serviceTypeList' => $this->customAttributeTypeLocatorMock,
139149
'authorization' => $authorizationMock,
140-
'serializer' => $this->serializer
150+
'serializer' => $this->serializer,
151+
'productMetadata' => $this->productMetadata
141152
]
142153
);
143154
}
@@ -169,6 +180,10 @@ public function testGenerate($serviceMetadata, $typeData, $schema)
169180
]
170181
);
171182

183+
$this->productMetadata->expects($this->once())
184+
->method('getVersion')
185+
->willReturn('UNKNOWN');
186+
172187
$this->assertEquals(
173188
$schema,
174189
$this->generator->generate(
@@ -309,7 +324,7 @@ public function generateDataProvider()
309324
],
310325
],
311326
],
312-
'class' => \Magento\TestModule5\Service\V2\AllSoapAndRestInterface::class,
327+
'class' => 'Magento\TestModule5\Service\V2\AllSoapAndRestInterface',
313328
'description' => 'AllSoapAndRestInterface',
314329
'routes' => [
315330
'/V1/testModule5' => [
@@ -362,7 +377,7 @@ public function generateDataProvider()
362377
],
363378
],
364379
],
365-
'class' => \Magento\TestModule5\Service\V2\AllSoapAndRestInterface::class,
380+
'class' => 'Magento\TestModule5\Service\V2\AllSoapAndRestInterface',
366381
'description' => 'AllSoapAndRestInterface',
367382
'routes' => [
368383
'/V1/testModule5' => [

app/code/Magento/Widget/Model/Widget/Instance.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ public function setType($type)
377377
*/
378378
public function getType()
379379
{
380-
return $this->_getData('instance_type');
380+
return (string) $this->_getData('instance_type');
381381
}
382382

383383
/**
@@ -706,7 +706,7 @@ private function validateLayoutUpdateXml(string $xml): void
706706
/**
707707
* Check if widget parameter doesn't contains payload
708708
*
709-
* @param $param
709+
* @param string $param
710710
* @throws LocalizedException
711711
*/
712712
private function validateWidgetParameters(string $param): void

app/code/Magento/Wishlist/Controller/Index/Send.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ public function execute()
198198
if (strlen($message) > $textLimit) {
199199
$error = __('Message length must not exceed %1 symbols', $textLimit);
200200
} else {
201-
$message = nl2br($this->escaper->escapeHtml($message));
201+
$message = nl2br((string) $this->escaper->escapeHtml($message));
202202
if (empty($emails)) {
203203
$error = __('Please enter an email address.');
204204
} else {

app/code/Magento/Wishlist/Pricing/ConfiguredPrice/Downloadable.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ private function getLinkPrice()
4242
$customOption = $this->getProduct()->getCustomOption('downloadable_link_ids');
4343
if ($customOption) {
4444
$links = $this->getLinks();
45-
$linkIds = explode(',', $customOption->getValue());
45+
$linkIds = explode(',', (string) $customOption->getValue());
4646
foreach ($linkIds as $linkId) {
4747
if (isset($links[$linkId])) {
4848
$result += $links[$linkId]->getPrice();
@@ -54,6 +54,8 @@ private function getLinkPrice()
5454
}
5555

5656
/**
57+
* This method get downloadable product links.
58+
*
5759
* @return \Magento\Downloadable\Model\Link[]
5860
*/
5961
private function getLinks()

lib/internal/Magento/Framework/Oauth/Helper/Request.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,9 @@ protected function _processRequest($authHeaderValue, $contentTypeHeader, $reques
8484
return [];
8585
}
8686

87-
if ($contentTypeHeader && 0 === strpos($contentTypeHeader, \Zend_Http_Client::ENC_URLENCODED)) {
87+
if ($requestBodyString !== null && $contentTypeHeader &&
88+
0 === strpos($contentTypeHeader, \Zend_Http_Client::ENC_URLENCODED)
89+
) {
8890
$protocolParamsNotSet = !$protocolParams;
8991

9092
parse_str($requestBodyString, $protocolBodyParams);

lib/internal/Magento/Framework/Stdlib/DateTime/Timezone.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ public function date($date = null, $locale = null, $useTimezone = true, $include
200200
break;
201201
}
202202

203-
return (new \DateTime(null, new \DateTimeZone($timezone)))->setTimestamp($date);
203+
return (new \DateTime('now', new \DateTimeZone($timezone)))->setTimestamp($date);
204204
}
205205

206206
/**

lib/internal/Magento/Framework/View/Test/Unit/Design/Theme/ImageTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,9 @@ public function testCreatePreviewImage(): void
214214
'/media_path/theme/preview',
215215
$this->anything()
216216
);
217+
$this->_imageMock->expects($this->any())
218+
->method('getImageType')
219+
->willReturn(1);
217220
$this->_model->createPreviewImage('/some/path/to/image.png');
218221
$this->assertNotNull($this->_themeMock->getData('preview_image'));
219222
}

0 commit comments

Comments
 (0)