Skip to content

Commit

Permalink
fix(symfony)!: context stamp not serializable because of request obje…
Browse files Browse the repository at this point in the history
…ct (#6323)

BREAKING CHANGE: unset request object from context array passed to the context stamp
  • Loading branch information
MariusJam committed Apr 18, 2024
1 parent 61bc8b6 commit af61482
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 8 deletions.
3 changes: 2 additions & 1 deletion src/Symfony/Messenger/ContextStamp.php
Expand Up @@ -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']);
}

Expand Down
10 changes: 3 additions & 7 deletions tests/Symfony/Messenger/ContextStampTest.php
Expand Up @@ -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());
}
}

0 comments on commit af61482

Please sign in to comment.