Skip to content

Commit 9383fe1

Browse files
committed
Static properties serialization fix.
1 parent 946c6ba commit 9383fe1

File tree

3 files changed

+56
-2
lines changed

3 files changed

+56
-2
lines changed

dev/tests/integration/etc/di/preferences/ce.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
\Magento\Framework\App\Response\Http::class => \Magento\TestFramework\Response::class,
1717
\Magento\Framework\Interception\PluginListInterface::class =>
1818
\Magento\TestFramework\Interception\PluginList::class,
19+
\Magento\Framework\Serialize\SerializerInterface::class =>
20+
\Magento\TestFramework\Serialize\Serializer::class,
1921
\Magento\Framework\Interception\ObjectManager\ConfigInterface::class =>
2022
\Magento\TestFramework\ObjectManager\Config::class,
2123
\Magento\Framework\Interception\ObjectManager\Config\Developer::class =>
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
declare(strict_types=1);
8+
9+
namespace Magento\TestFramework\Serialize;
10+
11+
use Magento\Framework\Serialize\SerializerInterface;
12+
13+
/**
14+
* Insecure SerializerInterface implementation for test use only.
15+
*/
16+
class Serializer implements SerializerInterface
17+
{
18+
/**
19+
* @inheritDoc
20+
*/
21+
public function serialize($data)
22+
{
23+
if (is_resource($data)) {
24+
throw new \InvalidArgumentException('Unable to serialize value.');
25+
}
26+
27+
// phpcs:ignore Magento2.Security.InsecureFunction
28+
return serialize($data);
29+
}
30+
31+
/**
32+
* @inheritDoc
33+
*/
34+
public function unserialize($string)
35+
{
36+
if (false === $string || null === $string || '' === $string) {
37+
throw new \InvalidArgumentException('Unable to unserialize value.');
38+
}
39+
set_error_handler(
40+
function () {
41+
restore_error_handler();
42+
throw new \InvalidArgumentException('Unable to unserialize value, string is corrupted.');
43+
},
44+
E_NOTICE
45+
);
46+
// phpcs:ignore Magento2.Security.InsecureFunction
47+
$result = unserialize($string);
48+
restore_error_handler();
49+
50+
return $result;
51+
}
52+
}

dev/tests/integration/framework/Magento/TestFramework/Workaround/Cleanup/StaticProperties.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,8 +186,8 @@ public static function backupStaticVariables()
186186
),
187187
function ($classFile) {
188188
return StaticProperties::_isClassInCleanableFolders($classFile)
189-
// phpcs:ignore Magento2.Functions.DiscouragedFunction
190-
&& strpos(file_get_contents($classFile), ' static ') > 0;
189+
// phpcs:ignore Magento2.Functions.DiscouragedFunction
190+
&& strpos(file_get_contents($classFile), ' static ') > 0;
191191
}
192192
);
193193
$namespacePattern = '/namespace [a-zA-Z0-9\\\\]+;/';

0 commit comments

Comments
 (0)