8000 [VarExporter] Suppress deprecations for legacy fixtures · symfony/symfony@2db2c00 · GitHub
[go: up one dir, main page]

Skip to content

Commit 2db2c00

Browse files
committed
[VarExporter] Suppress deprecations for legacy fixtures
Signed-off-by: Alexander M. Turek <me@derrabus.de>
1 parent 11fc285 commit 2db2c00

File tree

5 files changed

+87
-44
lines changed

5 files changed

+87
-44
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\VarExporter\Tests\Fixtures;
13+
14+
class FooSerializable implements \Serializable
15+
{
16+
private $foo;
17+
18+
public function __construct(string $foo)
19+
{
20+
$this->foo = $foo;
21+
}
22+
23+
public function getFoo(): string
24+
{
25+
return $this->foo;
26+
}
27+
28+
public function serialize(): string
29+
{
30+
return serialize([$this->getFoo()]);
31+
}
32+
33+
public function unserialize($str)
34+
{
35+
[$this->foo] = unserialize($str);
36+
}
37+
}
Lines changed: 25 additions & 0 deletions
E864
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\VarExporter\Tests\Fixtures;
13+
14+
class MySerializable implements \Serializable
15+
{
16+
public function serialize(): string
17+
{
18+
return '123';
19+
}
20+
21+
public function unserialize($data): void
22+
{
23+
// no-op
24+
}
25+
}

src/Symfony/Component/VarExporter/Tests/Fixtures/foo-serializable.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
return \Symfony\Component\VarExporter\Internal\Hydrator::hydrate(
44
$o = \Symfony\Component\VarExporter\Internal\Registry::unserialize([], [
5-
'C:51:"Symfony\\Component\\VarExporter\\Tests\\FooSerializable":20:{a:1:{i:0;s:3:"bar";}}',
5+
'C:60:"Symfony\\Component\\VarExporter\\Tests\\Fixtures\\FooSerializable":20:{a:1:{i:0;s:3:"bar";}}',
66
]),
77
null,
88
[],

src/Symfony/Component/VarExporter/Tests/Fixtures/serializable.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
return \Symfony\Component\VarExporter\Internal\Hydrator::hydrate(
44
$o = \Symfony\Component\VarExporter\Internal\Registry::unserialize([], [
5-
'C:50:"Symfony\\Component\\VarExporter\\Tests\\MySerializable":3:{123}',
5+
'C:59:"Symfony\\Component\\VarExporter\\Tests\\Fixtures\\MySerializable":3:{123}',
66
]),
77
null,
88
[],
< 2364 div aria-hidden="true" class="position-absolute top-0 d-flex user-select-none DiffLineTableCellParts-module__comment-indicator--eI0hb">

src/Symfony/Component/VarExporter/Tests/VarExporterTest.php

Lines changed: 23 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@
1616
use Symfony\Component\VarExporter\Exception\ClassNotFoundException;
1717
use Symfony\Component\VarExporter\Exception\NotInstantiableTypeException;
1818
use Symfony\Component\VarExporter\Internal\Registry;
19+
use Symfony\Component\VarExporter\Tests\Fixtures\FooSerializable;
1920
use Symfony\Component\VarExporter\Tests\Fixtures\FooUnitEnum;
21+
use Symfony\Component\VarExporter\Tests\Fixtures\MySerializable;
2022
use Symfony\Component\VarExporter\VarExporter;
2123

2224
class VarExporterTest extends TestCase
@@ -137,9 +139,28 @@ public function provideExport()
137139
yield ['array-iterator', new \ArrayIterator([123], 1)];
138140
yield ['array-object-custom', new MyArrayObject([234])];
139141

140-
$value = new MySerializable();
142+
$errorHandler = set_error_handler(static function (int $errno, string $errstr) use (&$errorHandler) {
143+
if (\E_DEPRECATED === $errno && str_contains($errstr, 'implements the Serializable interface, which is deprecated. Implement __serialize() and __unserialize() instead')) {
144+
// We're testing if the component handles deprecated Serializable implementations well.
145+
// This kind of implementation triggers a deprecation warning since PHP 8.1 that we explicitly want to
146+
// ignore here. We probably need to reevaluate this piece of code for PHP 9.
147+
return true;
148+
}
149+
150+
return $errorHandler ? $errorHandler(...\func_get_args()) : false;
151+
});
141152

142-
yield ['serializable', [$value, $value]];
153+
try {
154+
$mySerializable = new MySerializable();
155+
$fooSerializable = new FooSerializable('bar');
156+
} finally {
157+
restore_error_handler();
158+
}
159+
160+
yield ['serializable', [$mySerializable, $mySerializable]];
161+
yield ['foo-serializable', $fooSerializable];
162+
163+
unset($mySerializable, $fooSerializable, $errorHandler);
143164

144165
$value = new MyWakeup();
145166
$value->sub = new MyWakeup();
@@ -211,8 +232,6 @@ public function provideExport()
211232

212233
yield ['abstract-parent', new ConcreteClass()];
213234

214-
yield ['foo-serializable', new FooSerializable('bar')];
215-
216235
yield ['private-constructor', PrivateConstructor::create('bar')];
217236

218237
yield ['php74-serializable', new Php74Serializable()];
@@ -223,19 +242,6 @@ public function provideExport()
223242
}
224243
}
225244

226-
class MySerializable implements \Serializable
227-
{
228-
public function serialize(): string
229-
{
230-
return '123';
231-
}
232-
233-
public function unserialize($data)
234-
{
235-
// no-op
236-
}
237-
}
238-
239245
class MyWakeup
240246
{
241247
public $sub;
@@ -384,31 +390,6 @@ public function __construct()
384390
}
385391
}
386392

387-
class FooSerializable implements \Serializable
388-
{
389-
private $foo;
390-
391-
public function __construct(string $foo)
392-
{
393-
$this->foo = $foo;
394-
}
395-
396-
public function getFoo(): string
397-
{
398-
return $this->foo;
399-
}
400-
401-
public function serialize(): string
402-
{
403-
return serialize([$this->getFoo()]);
404-
}
405-
406-
public function unserialize($str)
407-
{
408-
[$this->foo] = unserialize($str);
409-
}
410-
}
411-
412393
class Php74Serializable implements \Serializable
413394
{
414395
public function __serialize(): array

0 commit comments

Comments
 (0)
0