forked from modelcontextprotocol/php-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReferenceHandlerTest.php
More file actions
78 lines (61 loc) · 2.14 KB
/
ReferenceHandlerTest.php
File metadata and controls
78 lines (61 loc) · 2.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<?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\Unit\Capability\Registry;
use Mcp\Capability\Registry\ElementReference;
use Mcp\Capability\Registry\ReferenceHandler;
use Mcp\Schema\Metadata;
use Mcp\Server\Session\SessionInterface;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
final class ReferenceHandlerTest extends TestCase
{
private ReferenceHandler $handler;
private SessionInterface&MockObject $session;
protected function setUp(): void
{
$this->handler = new ReferenceHandler();
$this->session = $this->createMock(SessionInterface::class);
}
public function testInjectsMetadataIntoTypedParameter(): void
{
$fn = function (Metadata $meta): string {
return (string) $meta->get('securitySchema');
};
$ref = new ElementReference($fn);
$result = $this->handler->handle($ref, [
'_session' => $this->session,
'_meta' => ['securitySchema' => 'secure-123'],
]);
$this->assertSame('secure-123', $result);
}
public function testNullableMetadataReceivesNullWhenNotProvided(): void
{
$fn = function (?Metadata $meta): string {
return null === $meta ? 'no-meta' : 'has-meta';
};
$ref = new ElementReference($fn);
$result = $this->handler->handle($ref, [
'_session' => $this->session,
]);
$this->assertSame('no-meta', $result);
}
public function testRequiredMetadataThrowsInternalErrorWhenNotProvided(): void
{
$fn = function (Metadata $meta): array {
return $meta->all();
};
$ref = new ElementReference($fn);
$this->expectException(\Mcp\Exception\RegistryException::class);
$this->expectExceptionMessage('Missing required request metadata');
$this->handler->handle($ref, [
'_session' => $this->session,
]);
}
}