php-sdk/tests/Schema/JsonRpc/RequestTest.php
Igor Markin 20e789d402
Fix return type in abstract methods from self to static (#53)
* Change return type of abstract request methods

* Change return type of `fromParams` method to `static` in request classes

(cherry picked from commit 94799ab66ff60d4b2305aadb6b73aaa4c805221e)

* Make request classes final and update `getParams` return types for improved type safety

(cherry picked from commit d6be496f89cc0e6d30f519792d0dc902685c4178)
2025-09-09 18:22:29 +02:00

58 lines
1.4 KiB
PHP

<?php
/*
* This file is part of the official PHP MCP SDK.
*
* A collaboration between Symfony and the PHP Foundation.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Mcp\Tests\Schema\JsonRpc;
use Mcp\Schema\JsonRpc\Request;
use PHPUnit\Framework\TestCase;
final class RequestTest extends TestCase
{
public function testMetaAndIdAreLoopedThrough()
{
$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 null;
}
};
$notification = $requestImplementation::fromArray([
'jsonrpc' => '2.0',
'id' => '12345',
'method' => 'foo/bar',
'params' => [
'_meta' => ['key' => 'value'],
],
]);
$expectedMeta = [
'jsonrpc' => '2.0',
'id' => '12345',
'method' => 'foo/bar',
'params' => [
'_meta' => ['key' => 'value'],
],
];
$this->assertSame($expectedMeta, $notification->jsonSerialize());
}
}