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

Commit01dcc62

Browse files
committed
[VarExporter] Suppress deprecations for legacy fixtures
Signed-off-by: Alexander M. Turek <me@derrabus.de>
1 parent1a59dc5 commit01dcc62

File tree

5 files changed

+85
-44
lines changed

5 files changed

+85
-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: 21 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,26 @@ 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+
// Skip the expected error.
145+
returntrue;
146+
}
147+
148+
return$errorHandler ?$errorHandler(...\func_get_args()) :false;
149+
});
141150

142-
yield ['serializable', [$value,$value]];
151+
try {
152+
$mySerializable =newMySerializable();
153+
$fooSerializable =newFooSerializable('bar');
154+
}finally {
155+
restore_error_handler();
156+
}
157+
158+
yield ['serializable', [$mySerializable,$mySerializable]];
159+
yield ['foo-serializable',$fooSerializable];
160+
161+
unset($mySerializable,$fooSerializable,$errorHandler);
143162

144163
$value =newMyWakeup();
145164
$value->sub =newMyWakeup();
@@ -211,8 +230,6 @@ public function provideExport()
211230

212231
yield ['abstract-parent',newConcreteClass()];
213232

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

218235
yield ['php74-serializable',newPhp74Serializable()];
@@ -223,19 +240,6 @@ public function provideExport()
223240
}
224241
}
225242

226-
class MySerializableimplements \Serializable
227-
{
228-
publicfunctionserialize():string
229-
{
230-
return'123';
231-
}
232-
233-
publicfunctionunserialize($data)
234-
{
235-
// no-op
236-
}
237-
}
238-
239243
class MyWakeup
240244
{
241245
public$sub;
@@ -384,31 +388,6 @@ public function __construct()
384388
}
385389
}
386390

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-
412391
class Php74Serializableimplements \Serializable
413392
{
414393
publicfunction__serialize():array

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp