16
16
use Symfony \Component \VarExporter \Exception \ClassNotFoundException ;
17
17
use Symfony \Component \VarExporter \Exception \NotInstantiableTypeException ;
18
18
use Symfony \Component \VarExporter \Internal \Registry ;
19
+ use Symfony \Component \VarExporter \Tests \Fixtures \FooSerializable ;
19
20
use Symfony \Component \VarExporter \Tests \Fixtures \FooUnitEnum ;
21
+ use Symfony \Component \VarExporter \Tests \Fixtures \MySerializable ;
20
22
use Symfony \Component \VarExporter \VarExporter ;
21
23
22
24
class VarExporterTest extends TestCase
@@ -137,9 +139,26 @@ public function provideExport()
137
139
yield ['array-iterator ' , new \ArrayIterator ([123 ], 1 )];
138
140
yield ['array-object-custom ' , new MyArrayObject ([234 ])];
139
141
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
+ // Skip the expected error.
145
+ return true ;
146
+ }
147
+
148
+ return $ errorHandler ? $ errorHandler (...\func_get_args ()) : false ;
149
+ });
141
150
142
- yield ['serializable ' , [$ value , $ value ]];
151
+ try {
152
+ $ mySerializable = new MySerializable ();
153
+ $ fooSerializable = new FooSerializable ('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 );
143
162
144
163
$ value = new MyWakeup ();
145
164
$ value ->sub = new MyWakeup ();
@@ -211,8 +230,6 @@ public function provideExport()
211
230
212
231
yield ['abstract-parent ' , new ConcreteClass ()];
213
232
214
- yield ['foo-serializable ' , new FooSerializable ('bar ' )];
215
-
216
233
yield ['private-constructor ' , PrivateConstructor::create ('bar ' )];
217
234
218
235
yield ['php74-serializable ' , new Php74Serializable ()];
@@ -223,19 +240,6 @@ public function provideExport()
223
240
}
224
241
}
225
242
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
-
239
243
class MyWakeup
240
244
{
241
245
public $ sub ;
@@ -384,31 +388,6 @@ public function __construct()
384
388
}
385
389
}
386
390
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
-
412
391
class Php74Serializable implements \Serializable
413
392
{
414
393
public function __serialize (): array
0 commit comments