[Schema] Fix _meta guard key in Request and Notification jsonSerialize() (#485)

This commit is contained in:
Christopher Hertel 2026-09-05 01:18:54 +02:00 • committed by GitHub
commit 1bd7895b5f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -55,4 +55,41 @@ final class RequestTest extends TestCase
$this->assertSame($expectedMeta, $notification->jsonSerialize());
}
public function testMetaDoesNotOverrideMetaFromParams(): void
{
$requestImplementation = new class extends Request {
public static function getMethod(): string
{
return 'foo/bar';
}
public static function fromParams(?array $params): static
{
return new self();
}
protected function getParams(): array
{
return [
'_meta' => ['key' => 'from-params'],
];
}
};
$request = $requestImplementation::fromParams(null)
->withId('12345')
->withMeta(['key' => 'from-meta']);
$expected = [
'jsonrpc' => '2.0',
'id' => '12345',
'method' => 'foo/bar',
'params' => [
'_meta' => ['key' => 'from-params'],
],
];
$this->assertSame($expected, $request->jsonSerialize());
}
}