|
20 | 20 | use Symfony\Component\VarExporter\Tests\Fixtures\FooReadonly; |
21 | 21 | use Symfony\Component\VarExporter\Tests\Fixtures\FooSerializable; |
22 | 22 | use Symfony\Component\VarExporter\Tests\Fixtures\FooUnitEnum; |
| 23 | +use Symfony\Component\VarExporter\Tests\Fixtures\GoodNight; |
23 | 24 | use Symfony\Component\VarExporter\Tests\Fixtures\MySerializable; |
| 25 | +use Symfony\Component\VarExporter\Tests\Fixtures\MyWakeup; |
| 26 | +use Symfony\Component\VarExporter\Tests\Fixtures\Php74Serializable; |
24 | 27 | use Symfony\Component\VarExporter\VarExporter; |
25 | 28 |
|
| 29 | +$errorHandler = set_error_handler(static function (int $errno, string $errstr) use (&$errorHandler) { |
| 30 | + if (\E_DEPRECATED === $errno && str_contains($errstr, 'serialize()')) { |
| 31 | + // We're testing if the component handles deprecated Serializable and __sleep/wakeup implementations well. |
| 32 | + // This kind of implementation triggers a deprecation warning that we explicitly want to ignore here. |
| 33 | + return true; |
| 34 | + } |
| 35 | + |
| 36 | + return $errorHandler ? $errorHandler(...\func_get_args()) : false; |
| 37 | +}); |
| 38 | + |
| 39 | +try { |
| 40 | + foreach ([ |
| 41 | + MySerializable::class, |
| 42 | + FooSerializable::class, |
| 43 | + GoodNight::class, |
| 44 | + Php74Serializable::class, |
| 45 | + MyWakeup::class, |
| 46 | + ] as $class) { |
| 47 | + class_exists($class); |
| 48 | + } |
| 49 | +} finally { |
| 50 | + restore_error_handler(); |
| 51 | +} |
| 52 | + |
26 | 53 | class VarExporterTest extends TestCase |
27 | 54 | { |
28 | 55 | use VarDumperTestTrait; |
@@ -142,23 +169,8 @@ public static function provideExport() |
142 | 169 | yield ['array-iterator', new \ArrayIterator([123], 1)]; |
143 | 170 | yield ['array-object-custom', new MyArrayObject([234])]; |
144 | 171 |
|
145 | | - $errorHandler = set_error_handler(static function (int $errno, string $errstr) use (&$errorHandler) { |
146 | | - if (\E_DEPRECATED === $errno && str_contains($errstr, 'implements the Serializable interface, which is deprecated. Implement __serialize() and __unserialize() instead')) { |
147 | | - // We're testing if the component handles deprecated Serializable implementations well. |
148 | | - // This kind of implementation triggers a deprecation warning since PHP 8.1 that we explicitly want to |
149 | | - // ignore here. We probably need to reevaluate this piece of code for PHP 9. |
150 | | - return true; |
151 | | - } |
152 | | - |
153 | | - return $errorHandler ? $errorHandler(...\func_get_args()) : false; |
154 | | - }); |
155 | | - |
156 | | - try { |
157 | | - $mySerializable = new MySerializable(); |
158 | | - $fooSerializable = new FooSerializable('bar'); |
159 | | - } finally { |
160 | | - restore_error_handler(); |
161 | | - } |
| 172 | + $mySerializable = new MySerializable(); |
| 173 | + $fooSerializable = new FooSerializable('bar'); |
162 | 174 |
|
163 | 175 | yield ['serializable', [$mySerializable, $mySerializable]]; |
164 | 176 | yield ['foo-serializable', $fooSerializable]; |
@@ -254,27 +266,6 @@ public function testUnicodeDirectionality() |
254 | 266 | } |
255 | 267 | } |
256 | 268 |
|
257 | | -class MyWakeup |
258 | | -{ |
259 | | - public $sub; |
260 | | - public $bis; |
261 | | - public $baz; |
262 | | - public $def = 234; |
263 | | - |
264 | | - public function __sleep(): array |
265 | | - { |
266 | | - return ['sub', 'baz']; |
267 | | - } |
268 | | - |
269 | | - public function __wakeup() |
270 | | - { |
271 | | - if (123 === $this->sub) { |
272 | | - $this->bis = 123; |
273 | | - $this->baz = 123; |
274 | | - } |
275 | | - } |
276 | | -} |
277 | | - |
278 | 269 | class MyCloneable |
279 | 270 | { |
280 | 271 | public function __clone() |
@@ -337,27 +328,6 @@ public function setFlags($flags): void |
337 | 328 | } |
338 | 329 | } |
339 | 330 |
|
340 | | -class GoodNight |
341 | | -{ |
342 | | - public $good; |
343 | | - protected $foo; |
344 | | - private $bar; |
345 | | - |
346 | | - public function __construct() |
347 | | - { |
348 | | - unset($this->good); |
349 | | - $this->foo = 'afternoon'; |
350 | | - $this->bar = 'morning'; |
351 | | - } |
352 | | - |
353 | | - public function __sleep(): array |
354 | | - { |
355 | | - $this->good = 'night'; |
356 | | - |
357 | | - return ['good', 'foo', "\0*\0foo", "\0".__CLASS__."\0bar"]; |
358 | | - } |
359 | | -} |
360 | | - |
361 | 331 | final class FinalError extends \Error |
362 | 332 | { |
363 | 333 | public function __construct(bool $throw = true) |
@@ -413,41 +383,6 @@ public function __construct() |
413 | 383 | } |
414 | 384 | } |
415 | 385 |
|
416 | | -class Php74Serializable implements \Serializable |
417 | | -{ |
418 | | - public $foo; |
419 | | - |
420 | | - public function __serialize(): array |
421 | | - { |
422 | | - return [$this->foo = new \stdClass()]; |
423 | | - } |
424 | | - |
425 | | - public function __unserialize(array $data) |
426 | | - { |
427 | | - [$this->foo] = $data; |
428 | | - } |
429 | | - |
430 | | - public function __sleep(): array |
431 | | - { |
432 | | - throw new \BadMethodCallException(); |
433 | | - } |
434 | | - |
435 | | - public function __wakeup() |
436 | | - { |
437 | | - throw new \BadMethodCallException(); |
438 | | - } |
439 | | - |
440 | | - public function serialize(): string |
441 | | - { |
442 | | - throw new \BadMethodCallException(); |
443 | | - } |
444 | | - |
445 | | - public function unserialize($ser) |
446 | | - { |
447 | | - throw new \BadMethodCallException(); |
448 | | - } |
449 | | -} |
450 | | - |
451 | 386 | #[\AllowDynamicProperties] |
452 | 387 | class ArrayObject extends \ArrayObject |
453 | 388 | { |
|
0 commit comments