From 1626a0480ece022821550aaf51bb841ab84b8e2f Mon Sep 17 00:00:00 2001 From: Marius J Date: Wed, 17 Apr 2024 15:21:41 +0200 Subject: [PATCH] fix(symfony)!: context stamp not serializable because of request object BREAKING CHANGE: unset request object from context array passed to the context stamp --- src/Symfony/Messenger/ContextStamp.php | 3 ++- tests/Symfony/Messenger/ContextStampTest.php | 10 +++------- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/src/Symfony/Messenger/ContextStamp.php b/src/Symfony/Messenger/ContextStamp.php index 6723b17c47f..5a8ffb42aba 100644 --- a/src/Symfony/Messenger/ContextStamp.php +++ b/src/Symfony/Messenger/ContextStamp.php @@ -27,7 +27,8 @@ final class ContextStamp implements StampInterface public function __construct(array $context = []) { - if (($request = ($context['request'] ?? null)) && $request instanceof Request && $request->hasSession()) { + /** Symfony does not guarantee that the Request object is serializable */ + if (($request = ($context['request'] ?? null)) && $request instanceof Request) { unset($context['request']); } diff --git a/tests/Symfony/Messenger/ContextStampTest.php b/tests/Symfony/Messenger/ContextStampTest.php index db185821785..208ac195765 100644 --- a/tests/Symfony/Messenger/ContextStampTest.php +++ b/tests/Symfony/Messenger/ContextStampTest.php @@ -34,15 +34,11 @@ public function testGetContext(): void $this->assertIsArray($contextStamp->getContext()); } - /** - * @doesNotPerformAssertions - */ - public function testSerializable(): void + public function testRequestIsUnset(): void { $request = new Request(); - $request->setSessionFactory(function (): void {}); // @phpstan-ignore-line - $stamp = new ContextStamp(['request' => $request]); - serialize($stamp); + + self::assertArrayNotHasKey('request', $stamp->getContext()); } }