Skip to content

Commit a6a659f

Browse files
committed
Fixed php 8.1 deprecations to pass Unit Tests
1 parent 1ef4504 commit a6a659f

File tree

7 files changed

+20
-7
lines changed

7 files changed

+20
-7
lines changed

app/code/Magento/Config/Test/Unit/Block/System/Config/Form/Field/Select/AllowspecificTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ function (string $tag, array $attributes, string $content): string {
5959
'secureRenderer' => $secureRendererMock
6060
]
6161
);
62-
$this->_object->setData('html_id', 'spec_element');
62+
$this->_object->setId('spec_element');
6363
$this->_formMock = $this->getMockBuilder(Form::class)
6464
->addMethods(['getHtmlIdPrefix', 'getHtmlIdSuffix'])
6565
->onlyMethods(['getElement'])

app/code/Magento/Customer/Test/Unit/Model/ResourceModel/GroupTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,8 @@ public function testSaveWithReservedId()
131131
->willReturn([]);
132132
$this->groupModel->expects($this->once())->method('setId')
133133
->with($expectedId);
134+
$this->groupModel->expects($this->once())->method('getCode')
135+
->willReturn('customer_group_code');
134136

135137
$dbAdapter = $this->getMockBuilder(AdapterInterface::class)
136138
->disableOriginalConstructor()

app/code/Magento/Store/Model/Store.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -666,12 +666,13 @@ public function getBaseUrl($type = UrlInterface::URL_TYPE_LINK, $secure = null)
666666
throw new \InvalidArgumentException('Invalid base url type');
667667
}
668668

669-
if (false !== strpos($url, self::BASE_URL_PLACEHOLDER)) {
669+
if (is_string($url) && false !== strpos($url, self::BASE_URL_PLACEHOLDER)) {
670670
$url = str_replace(self::BASE_URL_PLACEHOLDER, $this->_request->getDistroBaseUrl(), $url);
671671
}
672672

673+
$url = is_string($url) ? rtrim($url, '/') : '';
673674
$this->_baseUrlCache[$cacheKey] = $this->getUrlModifier()->execute(
674-
rtrim($url, '/') . '/',
675+
$url . '/',
675676
\Magento\Framework\Url\ModifierInterface::MODE_BASE
676677
);
677678
}

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,10 @@ protected function _getXmlQuotes()
492492
}
493493
$package->addChild('ZipOrigination', $r->getOrigPostal());
494494
//only 5 chars available
495-
$package->addChild('ZipDestination', substr($r->getDestPostal(), 0, 5));
495+
$package->addChild(
496+
'ZipDestination',
497+
is_string($r->getDestPostal()) ? substr($r->getDestPostal(), 0, 5) : ''
498+
);
496499
$package->addChild('Pounds', $r->getWeightPounds());
497500
$package->addChild('Ounces', $r->getWeightOunces());
498501
// Because some methods don't accept VARIABLE and (NON)RECTANGULAR containers

lib/internal/Magento/Framework/App/Response/Http.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ public function sendVary()
131131
*/
132132
public function setPublicHeaders($ttl)
133133
{
134-
if ($ttl < 0 || !preg_match('/^[0-9]+$/', $ttl)) {
134+
if ($ttl === null || $ttl < 0 || !preg_match('/^[0-9]+$/', $ttl)) {
135135
throw new \InvalidArgumentException('Time to live is a mandatory parameter for set public headers');
136136
}
137137
$this->setHeader('pragma', 'cache', true);

lib/internal/Magento/Framework/Data/Test/Unit/Form/Element/EditablemultiselectTest.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
use Magento\Framework\Data\Form\Element\Editablemultiselect;
1111
use Magento\Framework\DataObject;
12+
use Magento\Framework\Escaper;
1213
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
1314
use PHPUnit\Framework\TestCase;
1415
use Magento\Framework\Math\Random;
@@ -21,6 +22,9 @@ class EditablemultiselectTest extends TestCase
2122
*/
2223
protected $_model;
2324

25+
/**
26+
* @inheritdoc
27+
*/
2428
protected function setUp(): void
2529
{
2630
$testHelper = new ObjectManager($this);
@@ -41,11 +45,14 @@ function (string $tag, array $attrs, ?string $content): string {
4145
return "<$tag {$attrs->serialize()}>$content</$tag>";
4246
}
4347
);
48+
$escaper = $this->createMock(Escaper::class);
49+
$escaper->method('escapeHtml')->willReturn('test-name');
4450
$this->_model = $testHelper->getObject(
4551
Editablemultiselect::class,
4652
[
4753
'random' => $randomMock,
48-
'secureRenderer' => $secureRendererMock
54+
'secureRenderer' => $secureRendererMock,
55+
'escaper' => $escaper
4956
]
5057
);
5158
$values = [

lib/internal/Magento/Framework/DataObject.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ public function getData($key = '', $index = null)
128128
}
129129

130130
/* process a/b/c key as ['a']['b']['c'] */
131-
if (strpos($key, '/') !== false) {
131+
if (is_string($key) && strpos($key, '/') !== false) {
132132
$data = $this->getDataByPath($key);
133133
} else {
134134
$data = $this->_getData($key);

0 commit comments

Comments
 (0)