Skip to content

Commit 1a7fb0c

Browse files
author
silinmykola
committed
fix php8.1 compatibility for unit tests part 2
1 parent d44a639 commit 1a7fb0c

File tree

10 files changed

+37
-31
lines changed

10 files changed

+37
-31
lines changed

lib/internal/Magento/Framework/App/Test/Unit/Response/HttpTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ public function testSetPublicHeadersWithoutTtl(): void
245245
{
246246
$this->expectException('InvalidArgumentException');
247247
$this->expectExceptionMessage('Time to live is a mandatory parameter for set public headers');
248-
$this->model->setPublicHeaders(null);
248+
$this->model->setPublicHeaders('');
249249
}
250250

251251
/**

lib/internal/Magento/Framework/App/Test/Unit/StaticResourceTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,9 @@ public function testLaunchWrongPathProductionMode()
328328
$this->responseMock->expects($this->once())
329329
->method('setHttpResponseCode')
330330
->with(404);
331+
$this->driverMock->expects($this->once())
332+
->method('getRealPathSafety')
333+
->willReturnArgument(0);
331334
$this->object->launch();
332335
}
333336

lib/internal/Magento/Framework/App/Test/Unit/ViewTest.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,9 @@ public function testLoadLayoutWithDefaultSetup(): void
166166
$this->_layoutProcessor
167167
->method('addHandle')
168168
->withConsecutive(['default']);
169-
$this->_requestMock->expects($this->any())->method('getFullActionName')->willReturn('action_name');
169+
$this->_requestMock->expects($this->any())
170+
->method('getFullActionName')
171+
->willReturn('action_name');
170172
$this->_view->loadLayout();
171173
}
172174

@@ -175,6 +177,9 @@ public function testLoadLayoutWithDefaultSetup(): void
175177
*/
176178
public function testLoadLayoutWhenBlocksNotGenerated(): void
177179
{
180+
$this->_requestMock->expects($this->any())
181+
->method('getFullActionName')
182+
->willReturn('action_name');
178183
$this->_view->loadLayout('', false, true);
179184
}
180185

@@ -183,6 +188,9 @@ public function testLoadLayoutWhenBlocksNotGenerated(): void
183188
*/
184189
public function testLoadLayoutWhenXmlNotGenerated(): void
185190
{
191+
$this->_requestMock->expects($this->any())
192+
->method('getFullActionName')
193+
->willReturn('action_name');
186194
$this->_view->loadLayout('', true, false);
187195
}
188196

lib/internal/Magento/Framework/Code/Generator/EntityAbstract.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ public function getSourceClassNameWithoutNamespace()
157157
*/
158158
protected function _getFullyQualifiedClassName($className)
159159
{
160-
$className = ltrim($className, '\\');
160+
$className = $className ? ltrim($className, '\\') : '';
161161
return $className ? '\\' . $className : '';
162162
}
163163

lib/internal/Magento/Framework/HTTP/PhpEnvironment/RemoteAddress.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ function (string $ip) {
9999
return !in_array(trim($ip), $this->trustedProxies, true);
100100
}
101101
);
102-
$remoteAddress = trim(array_pop($ipList));
102+
$remoteAddress = empty($ipList) ? '' : trim(array_pop($ipList));
103103
} else {
104104
$remoteAddress = trim(reset($ipList));
105105
}

lib/internal/Magento/Framework/Mview/Test/Unit/View/ChangelogTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ public function testGetNameWithException()
111111
{
112112
$this->expectException('DomainException');
113113
$this->expectExceptionMessage('View\'s identifier is not set');
114+
$this->model->setViewId('');
114115
$this->model->getName();
115116
}
116117

lib/internal/Magento/Framework/ObjectManager/Config/Config.php

Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@
55
*/
66
namespace Magento\Framework\ObjectManager\Config;
77

8-
use Magento\Framework\Serialize\SerializerInterface;
8+
use Magento\Framework\App\ObjectManager;
99
use Magento\Framework\ObjectManager\ConfigCacheInterface;
1010
use Magento\Framework\ObjectManager\DefinitionInterface;
1111
use Magento\Framework\ObjectManager\RelationsInterface;
12+
use Magento\Framework\Serialize\SerializerInterface;
1213

1314
class Config implements \Magento\Framework\ObjectManager\ConfigInterface
1415
{
@@ -76,18 +77,23 @@ class Config implements \Magento\Framework\ObjectManager\ConfigInterface
7677
protected $_mergedArguments;
7778

7879
/**
79-
* @var \Magento\Framework\Serialize\SerializerInterface
80+
* @var SerializerInterface
8081
*/
8182
private $serializer;
8283

8384
/**
84-
* @param RelationsInterface $relations
85-
* @param DefinitionInterface $definitions
85+
* @param RelationsInterface|null $relations
86+
* @param DefinitionInterface|null $definitions
87+
* @param SerializerInterface|null $serializer
8688
*/
87-
public function __construct(RelationsInterface $relations = null, DefinitionInterface $definitions = null)
88-
{
89+
public function __construct(
90+
RelationsInterface $relations = null,
91+
DefinitionInterface $definitions = null,
92+
SerializerInterface $serializer = null
93+
) {
8994
$this->_relations = $relations ?: new \Magento\Framework\ObjectManager\Relations\Runtime();
9095
$this->_definitions = $definitions ?: new \Magento\Framework\ObjectManager\Definition\Runtime();
96+
$this->serializer = $serializer ?: ObjectManager::getInstance()->get(SerializerInterface::class);
9197
}
9298

9399
/**
@@ -275,14 +281,14 @@ public function extend(array $configuration)
275281
// md5() here is not for cryptographic use.
276282
// phpcs:ignore Magento2.Security.InsecureFunction
277283
$this->_currentCacheKey = md5(
278-
$this->getSerializer()->serialize(
284+
$this->serializer->serialize(
279285
[$this->_arguments, $this->_nonShared, $this->_preferences, $this->_virtualTypes]
280286
)
281287
);
282288
}
283289
// md5() here is not for cryptographic use.
284290
// phpcs:ignore Magento2.Security.InsecureFunction
285-
$key = md5($this->_currentCacheKey . $this->getSerializer()->serialize($configuration));
291+
$key = md5($this->_currentCacheKey . $this->serializer->serialize($configuration));
286292
$cached = $this->_cache->get($key);
287293
if ($cached) {
288294
list(
@@ -335,19 +341,4 @@ public function getPreferences()
335341
{
336342
return $this->_preferences;
337343
}
338-
339-
/**
340-
* Get serializer
341-
*
342-
* @return \Magento\Framework\Serialize\SerializerInterface
343-
* @deprecated 101.0.0
344-
*/
345-
private function getSerializer()
346-
{
347-
if ($this->serializer === null) {
348-
$this->serializer = \Magento\Framework\App\ObjectManager::getInstance()
349-
->get(SerializerInterface::class);
350-
}
351-
return $this->serializer;
352-
}
353344
}

lib/internal/Magento/Framework/ObjectManager/Test/Unit/Config/ConfigTest.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,14 @@ public function testExtendWithCacheMock()
5353
$definitions = $this->getMockForAbstractClass(DefinitionInterface::class);
5454
$definitions->expects($this->once())->method('getClasses')->willReturn(['FooType']);
5555

56+
$serializer = $this->getMockForAbstractClass(SerializerInterface::class);
57+
$serializer->expects($this->any())
58+
->method('serialize')
59+
->willReturn('["custom_value"]');
5660
$cache = $this->getMockForAbstractClass(ConfigCacheInterface::class);
5761
$cache->expects($this->once())->method('get')->willReturn(false);
5862

59-
$config = new Config(null, $definitions);
63+
$config = new Config(null, $definitions, $serializer);
6064
$serializerMock = $this->getMockForAbstractClass(SerializerInterface::class);
6165
$serializerMock->expects($this->exactly(2))
6266
->method('serialize');

lib/internal/Magento/Framework/Serialize/Test/Unit/Serializer/JsonHexTagTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,6 @@ public function unserializeExceptionDataProvider(): array
115115
return [
116116
[''],
117117
[false],
118-
[null],
119118
['{']
120119
];
121120
}

setup/src/Magento/Setup/Fixtures/CartPriceRulesFixture.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ public function generateAdvancedCondition($ruleId, $categoriesArray)
264264
'type' => \Magento\SalesRule\Model\Rule\Condition\Product::class,
265265
'attribute' => 'category_ids',
266266
'operator' => '==',
267-
'value' => $categoriesArray[($ruleId / 4) % count($categoriesArray)][0],
267+
'value' => $categoriesArray[intdiv($ruleId, 4) % count($categoriesArray)][0],
268268
];
269269

270270
$subtotal = [0, 5, 10, 15];
@@ -316,7 +316,7 @@ public function generateAdvancedCondition($ruleId, $categoriesArray)
316316
'type' => \Magento\SalesRule\Model\Rule\Condition\Address::class,
317317
'attribute' => 'region',
318318
'operator' => '==',
319-
'value' => $regions[($ruleId / 4) % 50],
319+
'value' => $regions[intdiv($ruleId, 4) % 50],
320320
];
321321

322322
$subtotals = [0, 5, 10, 15];

0 commit comments

Comments
 (0)