|
21 | 21 | use Symfony\Component\VarExporter\Tests\Fixtures\FooReadonly; |
22 | 22 | use Symfony\Component\VarExporter\Tests\Fixtures\FooSerializable; |
23 | 23 | use Symfony\Component\VarExporter\Tests\Fixtures\FooUnitEnum; |
| 24 | +use Symfony\Component\VarExporter\Tests\Fixtures\GoodNight; |
24 | 25 | use Symfony\Component\VarExporter\Tests\Fixtures\MySerializable; |
| 26 | +use Symfony\Component\VarExporter\Tests\Fixtures\MyWakeup; |
| 27 | +use Symfony\Component\VarExporter\Tests\Fixtures\Php74Serializable; |
25 | 28 | use Symfony\Component\VarExporter\Tests\Fixtures\PrivateFCC; |
26 | 29 | use Symfony\Component\VarExporter\VarExporter; |
27 | 30 |
|
| 31 | +$errorHandler = set_error_handler(static function (int $errno, string $errstr) use (&$errorHandler) { |
| 32 | + if (\E_DEPRECATED === $errno && str_contains($errstr, 'serialize()')) { |
| 33 | + // We're testing if the component handles deprecated Serializable and __sleep/wakeup implementations well. |
| 34 | + // This kind of implementation triggers a deprecation warning that we explicitly want to ignore here. |
| 35 | + return true; |
| 36 | + } |
| 37 | + |
| 38 | + return $errorHandler ? $errorHandler(...\func_get_args()) : false; |
| 39 | +}); |
| 40 | + |
| 41 | +try { |
| 42 | + foreach ([ |
| 43 | + MySerializable::class, |
| 44 | + FooSerializable::class, |
| 45 | + GoodNight::class, |
| 46 | + Php74Serializable::class, |
| 47 | + MyWakeup::class, |
| 48 | + ] as $class) { |
| 49 | + class_exists($class); |
| 50 | + } |
| 51 | +} finally { |
| 52 | + restore_error_handler(); |
| 53 | +} |
| 54 | + |
28 | 55 | class VarExporterTest extends TestCase |
29 | 56 | { |
30 | 57 | use VarDumperTestTrait; |
@@ -136,23 +163,8 @@ public static function provideExport() |
136 | 163 | yield ['array-iterator', new \ArrayIterator([123], 1)]; |
137 | 164 | yield ['array-object-custom', new MyArrayObject([234])]; |
138 | 165 |
|
139 | | - $errorHandler = set_error_handler(static function (int $errno, string $errstr) use (&$errorHandler) { |
140 | | - if (\E_DEPRECATED === $errno && str_contains($errstr, 'implements the Serializable interface, which is deprecated. Implement __serialize() and __unserialize() instead')) { |
141 | | - // We're testing if the component handles deprecated Serializable implementations well. |
142 | | - // This kind of implementation triggers a deprecation warning since PHP 8.1 that we explicitly want to |
143 | | - // ignore here. We probably need to reevaluate this piece of code for PHP 9. |
144 | | - return true; |
145 | | - } |
146 | | - |
147 | | - return $errorHandler ? $errorHandler(...\func_get_args()) : false; |
148 | | - }); |
149 | | - |
150 | | - try { |
151 | | - $mySerializable = new MySerializable(); |
152 | | - $fooSerializable = new FooSerializable('bar'); |
153 | | - } finally { |
154 | | - restore_error_handler(); |
155 | | - } |
| 166 | + $mySerializable = new MySerializable(); |
| 167 | + $fooSerializable = new FooSerializable('bar'); |
156 | 168 |
|
157 | 169 | yield ['serializable', [$mySerializable, $mySerializable]]; |
158 | 170 | yield ['foo-serializable', $fooSerializable]; |
@@ -253,27 +265,6 @@ public function testUnicodeDirectionality() |
253 | 265 | } |
254 | 266 | } |
255 | 267 |
|
256 | | -class MyWakeup |
257 | | -{ |
258 | | - public $sub; |
259 | | - public $bis; |
260 | | - public $baz; |
261 | | - public $def = 234; |
262 | | - |
263 | | - public function __sleep(): array |
264 | | - { |
265 | | - return ['sub', 'baz']; |
266 | | - } |
267 | | - |
268 | | - public function __wakeup(): void |
269 | | - { |
270 | | - if (123 === $this->sub) { |
271 | | - $this->bis = 123; |
272 | | - $this->baz = 123; |
273 | | - } |
274 | | - } |
275 | | -} |
276 | | - |
277 | 268 | class MyCloneable |
278 | 269 | { |
279 | 270 | public function __clone() |
@@ -349,27 +340,6 @@ public function setFlags($flags): void |
349 | 340 | } |
350 | 341 | } |
351 | 342 |
|
352 | | -class GoodNight |
353 | | -{ |
354 | | - public $good; |
355 | | - protected $foo; |
356 | | - private $bar; |
357 | | - |
358 | | - public function __construct() |
359 | | - { |
360 | | - unset($this->good); |
361 | | - $this->foo = 'afternoon'; |
362 | | - $this->bar = 'morning'; |
363 | | - } |
364 | | - |
365 | | - public function __sleep(): array |
366 | | - { |
367 | | - $this->good = 'night'; |
368 | | - |
369 | | - return ['good', 'foo', "\0*\0foo", "\0".__CLASS__."\0bar"]; |
370 | | - } |
371 | | -} |
372 | | - |
373 | 343 | final class FinalError extends \Error |
374 | 344 | { |
375 | 345 | public function __construct(bool $throw = true) |
@@ -425,41 +395,6 @@ public function __construct() |
425 | 395 | } |
426 | 396 | } |
427 | 397 |
|
428 | | -class Php74Serializable implements \Serializable |
429 | | -{ |
430 | | - public $foo; |
431 | | - |
432 | | - public function __serialize(): array |
433 | | - { |
434 | | - return [$this->foo = new \stdClass()]; |
435 | | - } |
436 | | - |
437 | | - public function __unserialize(array $data): void |
438 | | - { |
439 | | - [$this->foo] = $data; |
440 | | - } |
441 | | - |
442 | | - public function __sleep(): array |
443 | | - { |
444 | | - throw new \BadMethodCallException(); |
445 | | - } |
446 | | - |
447 | | - public function __wakeup(): void |
448 | | - { |
449 | | - throw new \BadMethodCallException(); |
450 | | - } |
451 | | - |
452 | | - public function serialize(): string |
453 | | - { |
454 | | - throw new \BadMethodCallException(); |
455 | | - } |
456 | | - |
457 | | - public function unserialize($ser) |
458 | | - { |
459 | | - throw new \BadMethodCallException(); |
460 | | - } |
461 | | -} |
462 | | - |
463 | 398 | #[\AllowDynamicProperties] |
464 | 399 | class ArrayObject extends \ArrayObject |
465 | 400 | { |
|
0 commit comments