Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit460fd35

Browse files
committed
minor#42782 [VarExporter] Suppress deprecations for legacy fixtures (derrabus)
This PR was merged into the 4.4 branch.Discussion----------[VarExporter] Suppress deprecations for legacy fixtures| Q | A| ------------- | ---| Branch? | 4.4| Bug fix? | yes| New feature? | no| Deprecations? | no| Tickets | Part of#41552| License | MIT| Doc PR | N/ATwo test fixtures currently trigger a deprecation on PHP 8.1 because they implement `Serializable` without implementing `__serialize()` and `__unserialize()`. However, I believe that we want to test the behavior of the component with this kind of implementation. This why I decided to suppress the deprecation instead of upgrading the fixtures.Commits-------2db2c00 [VarExporter] Suppress deprecations for legacy fixtures
2 parents11fc285 +2db2c00 commit460fd35

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+
namespaceSymfony\Component\VarExporter\Tests\Fixtures;
13+
14+
class FooSerializableimplements \Serializable
15+
{
16+
private$foo;
17+
18+
publicfunction__construct(string$foo)
19+
{
20+
$this->foo =$foo;
21+
}
22+
23+
publicfunctiongetFoo():string
24+
{
25+
return$this->foo;
26+
}
27+
28+
publicfunctionserialize():string
29+
{
30+
returnserialize([$this->getFoo()]);
31+
}
32+
33+
publicfunctionunserialize($str)
34+
{
35+
[$this->foo] =unserialize($str);
36+
}
37+
}
Lines changed: 25 additions & 0 deletions
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+
namespaceSymfony\Component\VarExporter\Tests\Fixtures;
13+
14+
class MySerializableimplements \Serializable
15+
{
16+
publicfunctionserialize():string
17+
{
18+
return'123';
19+
}
20+
21+
publicfunctionunserialize($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
[],

‎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
useSymfony\Component\VarExporter\Exception\ClassNotFoundException;
1717
useSymfony\Component\VarExporter\Exception\NotInstantiableTypeException;
1818
useSymfony\Component\VarExporter\Internal\Registry;
19+
useSymfony\Component\VarExporter\Tests\Fixtures\FooSerializable;
1920
useSymfony\Component\VarExporter\Tests\Fixtures\FooUnitEnum;
21+
useSymfony\Component\VarExporter\Tests\Fixtures\MySerializable;
2022
useSymfony\Component\VarExporter\VarExporter;
2123

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

140-
$value =newMySerializable();
142+
$errorHandler =set_error_handler(staticfunction (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+
returntrue;
148+
}
149+
150+
return$errorHandler ?$errorHandler(...\func_get_args()) :false;
151+
});
141152

142-
yield ['serializable', [$value,$value]];
153+
try {
154+
$mySerializable =newMySerializable();
155+
$fooSerializable =newFooSerializable('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 =newMyWakeup();
145166
$value->sub =newMyWakeup();
@@ -211,8 +232,6 @@ public function provideExport()
211232

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

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

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

226-
class MySerializableimplements \Serializable
227-
{
228-
publicfunctionserialize():string
229-
{
230-
return'123';
231-
}
232-
233-
publicfunctionunserialize($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 FooSerializableimplements \Serializable
388-
{
389-
private$foo;
390-
391-
publicfunction__construct(string$foo)
392-
{
393-
$this->foo =$foo;
394-
}
395-
396-
publicfunctiongetFoo():string
397-
{
398-
return$this->foo;
399-
}
400-
401-
publicfunctionserialize():string
402-
{
403-
returnserialize([$this->getFoo()]);
404-
}
405-
406-
publicfunctionunserialize($str)
407-
{
408-
[$this->foo] =unserialize($str);
409-
}
410-
}
411-
412393
class Php74Serializableimplements \Serializable
413394
{
414395
publicfunction__serialize():array

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp