Update codestyle based on updated Symfony rules (#229)
This commit is contained in:
parent
e485fde727
commit
c081b90d74
11 changed files with 165 additions and 168 deletions
|
|
@ -38,23 +38,23 @@ $server = Server::builder()
|
|||
->setSession(new FileSessionStore(__DIR__.'/sessions'))
|
||||
->setLogger($logger)
|
||||
// Tools
|
||||
->addTool(fn () => 'This is a simple text response for testing.', 'test_simple_text', 'Tests simple text content response')
|
||||
->addTool(fn () => new ImageContent(Elements::TEST_IMAGE_BASE64, 'image/png'), 'test_image_content', 'Tests image content response')
|
||||
->addTool(fn () => new AudioContent(Elements::TEST_AUDIO_BASE64, 'audio/wav'), 'test_audio_content', 'Tests audio content response')
|
||||
->addTool(fn () => EmbeddedResource::fromText('test://embedded-resource', 'This is an embedded resource content.'), 'test_embedded_resource', 'Tests embedded resource content response')
|
||||
->addTool(static fn () => 'This is a simple text response for testing.', 'test_simple_text', 'Tests simple text content response')
|
||||
->addTool(static fn () => new ImageContent(Elements::TEST_IMAGE_BASE64, 'image/png'), 'test_image_content', 'Tests image content response')
|
||||
->addTool(static fn () => new AudioContent(Elements::TEST_AUDIO_BASE64, 'audio/wav'), 'test_audio_content', 'Tests audio content response')
|
||||
->addTool(static fn () => EmbeddedResource::fromText('test://embedded-resource', 'This is an embedded resource content.'), 'test_embedded_resource', 'Tests embedded resource content response')
|
||||
->addTool([Elements::class, 'toolMultipleTypes'], 'test_multiple_content_types', 'Tests response with multiple content types')
|
||||
->addTool([Elements::class, 'toolWithLogging'], 'test_tool_with_logging', 'Tests tool that emits log messages')
|
||||
->addTool([Elements::class, 'toolWithProgress'], 'test_tool_with_progress', 'Tests tool that reports progress notifications')
|
||||
->addTool([Elements::class, 'toolWithSampling'], 'test_sampling', 'Tests server-initiated sampling')
|
||||
->addTool(fn () => CallToolResult::error([new TextContent('This tool intentionally returns an error for testing')]), 'test_error_handling', 'Tests error response handling')
|
||||
->addTool(static fn () => CallToolResult::error([new TextContent('This tool intentionally returns an error for testing')]), 'test_error_handling', 'Tests error response handling')
|
||||
// Resources
|
||||
->addResource(fn () => 'This is the content of the static text resource.', 'test://static-text', 'static-text', 'A static text resource for testing')
|
||||
->addResource(fn () => fopen('data://image/png;base64,'.Elements::TEST_IMAGE_BASE64, 'r'), 'test://static-binary', 'static-binary', 'A static binary resource (image) for testing')
|
||||
->addResource(static fn () => 'This is the content of the static text resource.', 'test://static-text', 'static-text', 'A static text resource for testing')
|
||||
->addResource(static fn () => fopen('data://image/png;base64,'.Elements::TEST_IMAGE_BASE64, 'r'), 'test://static-binary', 'static-binary', 'A static binary resource (image) for testing')
|
||||
->addResourceTemplate([Elements::class, 'resourceTemplate'], 'test://template/{id}/data', 'template', 'A resource template with parameter substitution', 'application/json')
|
||||
// TODO: Handler for resources/subscribe and resources/unsubscribe
|
||||
->addResource(fn () => 'Watched resource content', 'test://watched-resource', 'watched-resource', 'A resource that can be watched')
|
||||
->addResource(static fn () => 'Watched resource content', 'test://watched-resource', 'watched-resource', 'A resource that can be watched')
|
||||
// Prompts
|
||||
->addPrompt(fn () => [['role' => 'user', 'content' => 'This is a simple prompt for testing.']], 'test_simple_prompt', 'A simple prompt without arguments')
|
||||
->addPrompt(static fn () => [['role' => 'user', 'content' => 'This is a simple prompt for testing.']], 'test_simple_prompt', 'A simple prompt without arguments')
|
||||
->addPrompt([Elements::class, 'promptWithArguments'], 'test_prompt_with_arguments', 'A prompt with required arguments')
|
||||
->addPrompt([Elements::class, 'promptWithEmbeddedResource'], 'test_prompt_with_embedded_resource', 'A prompt that includes an embedded resource')
|
||||
->addPrompt([Elements::class, 'promptWithImage'], 'test_prompt_with_image', 'A prompt that includes image content')
|
||||
|
|
|
|||
|
|
@ -25,6 +25,6 @@ class CompletionProviderFixture implements ProviderInterface
|
|||
{
|
||||
self::$lastCurrentValue = $currentValue;
|
||||
|
||||
return array_filter(self::$completions, fn ($item) => str_starts_with($item, $currentValue));
|
||||
return array_filter(self::$completions, static fn ($item) => str_starts_with($item, $currentValue));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ class HandlerResolverTest extends TestCase
|
|||
{
|
||||
public function testResolvesClosuresToReflectionFunction()
|
||||
{
|
||||
$closure = function (string $input): string {
|
||||
$closure = static function (string $input): string {
|
||||
return "processed: $input";
|
||||
};
|
||||
$resolved = HandlerResolver::resolve($closure);
|
||||
|
|
@ -135,13 +135,13 @@ class HandlerResolverTest extends TestCase
|
|||
|
||||
public function testResolvesClosuresWithDifferentSignatures()
|
||||
{
|
||||
$noParams = function () {
|
||||
$noParams = static function () {
|
||||
return 'test';
|
||||
};
|
||||
$withParams = function (int $a, string $b = 'default') {
|
||||
$withParams = static function (int $a, string $b = 'default') {
|
||||
return $a.$b;
|
||||
};
|
||||
$variadic = function (...$args) {
|
||||
$variadic = static function (...$args) {
|
||||
return $args;
|
||||
};
|
||||
$this->assertInstanceOf(\ReflectionFunction::class, HandlerResolver::resolve($noParams));
|
||||
|
|
@ -154,7 +154,7 @@ class HandlerResolverTest extends TestCase
|
|||
|
||||
public function testDistinguishesBetweenClosuresAndCallableArrays()
|
||||
{
|
||||
$closure = function () {
|
||||
$closure = static function () {
|
||||
return 'closure';
|
||||
};
|
||||
$array = [ValidHandlerClass::class, 'publicMethod'];
|
||||
|
|
|
|||
|
|
@ -50,7 +50,7 @@ class RegistryTest extends TestCase
|
|||
public function testHasToolsReturnsTrueWhenToolIsRegistered(): void
|
||||
{
|
||||
$tool = $this->createValidTool('test_tool');
|
||||
$this->registry->registerTool($tool, fn () => 'result');
|
||||
$this->registry->registerTool($tool, static fn () => 'result');
|
||||
|
||||
$this->assertTrue($this->registry->hasTools());
|
||||
}
|
||||
|
|
@ -60,8 +60,8 @@ class RegistryTest extends TestCase
|
|||
$tool1 = $this->createValidTool('tool1');
|
||||
$tool2 = $this->createValidTool('tool2');
|
||||
|
||||
$this->registry->registerTool($tool1, fn () => 'result1');
|
||||
$this->registry->registerTool($tool2, fn () => 'result2');
|
||||
$this->registry->registerTool($tool1, static fn () => 'result1');
|
||||
$this->registry->registerTool($tool2, static fn () => 'result2');
|
||||
|
||||
$tools = $this->registry->getTools();
|
||||
$this->assertCount(2, $tools);
|
||||
|
|
@ -74,7 +74,7 @@ class RegistryTest extends TestCase
|
|||
public function testGetToolReturnsRegisteredTool(): void
|
||||
{
|
||||
$tool = $this->createValidTool('test_tool');
|
||||
$handler = fn () => 'result';
|
||||
$handler = static fn () => 'result';
|
||||
|
||||
$this->registry->registerTool($tool, $handler);
|
||||
|
||||
|
|
@ -88,7 +88,7 @@ class RegistryTest extends TestCase
|
|||
public function testRegisterToolWithManualFlag(): void
|
||||
{
|
||||
$tool = $this->createValidTool('test_tool');
|
||||
$handler = fn () => 'result';
|
||||
$handler = static fn () => 'result';
|
||||
|
||||
$this->registry->registerTool($tool, $handler, true);
|
||||
|
||||
|
|
@ -101,14 +101,14 @@ class RegistryTest extends TestCase
|
|||
$manualTool = $this->createValidTool('test_tool');
|
||||
$discoveredTool = $this->createValidTool('test_tool');
|
||||
|
||||
$this->registry->registerTool($manualTool, fn () => 'manual', true);
|
||||
$this->registry->registerTool($manualTool, static fn () => 'manual', true);
|
||||
|
||||
$this->logger
|
||||
->expects($this->once())
|
||||
->method('debug')
|
||||
->with('Ignoring discovered tool "test_tool" as it conflicts with a manually registered one.');
|
||||
|
||||
$this->registry->registerTool($discoveredTool, fn () => 'discovered');
|
||||
$this->registry->registerTool($discoveredTool, static fn () => 'discovered');
|
||||
|
||||
$toolRef = $this->registry->getTool('test_tool');
|
||||
$this->assertTrue($toolRef->isManual);
|
||||
|
|
@ -119,8 +119,8 @@ class RegistryTest extends TestCase
|
|||
$discoveredTool = $this->createValidTool('test_tool');
|
||||
$manualTool = $this->createValidTool('test_tool');
|
||||
|
||||
$this->registry->registerTool($discoveredTool, fn () => 'discovered');
|
||||
$this->registry->registerTool($manualTool, fn () => 'manual', true);
|
||||
$this->registry->registerTool($discoveredTool, static fn () => 'discovered');
|
||||
$this->registry->registerTool($manualTool, static fn () => 'manual', true);
|
||||
|
||||
$toolRef = $this->registry->getTool('test_tool');
|
||||
$this->assertTrue($toolRef->isManual);
|
||||
|
|
@ -137,7 +137,7 @@ class RegistryTest extends TestCase
|
|||
public function testHasResourceReturnsTrueWhenResourceIsRegistered(): void
|
||||
{
|
||||
$resource = $this->createValidResource('test://resource');
|
||||
$this->registry->registerResource($resource, fn () => 'content');
|
||||
$this->registry->registerResource($resource, static fn () => 'content');
|
||||
|
||||
$this->assertTrue($this->registry->hasResources());
|
||||
}
|
||||
|
|
@ -147,8 +147,8 @@ class RegistryTest extends TestCase
|
|||
$resource1 = $this->createValidResource('test://resource1');
|
||||
$resource2 = $this->createValidResource('test://resource2');
|
||||
|
||||
$this->registry->registerResource($resource1, fn () => 'content1');
|
||||
$this->registry->registerResource($resource2, fn () => 'content2');
|
||||
$this->registry->registerResource($resource1, static fn () => 'content1');
|
||||
$this->registry->registerResource($resource2, static fn () => 'content2');
|
||||
|
||||
$resources = $this->registry->getResources();
|
||||
$this->assertCount(2, $resources);
|
||||
|
|
@ -161,7 +161,7 @@ class RegistryTest extends TestCase
|
|||
public function testGetResourceReturnsRegisteredResource(): void
|
||||
{
|
||||
$resource = $this->createValidResource('test://resource');
|
||||
$handler = fn () => 'content';
|
||||
$handler = static fn () => 'content';
|
||||
|
||||
$this->registry->registerResource($resource, $handler);
|
||||
|
||||
|
|
@ -175,7 +175,7 @@ class RegistryTest extends TestCase
|
|||
public function testRegisterResourceWithManualFlag(): void
|
||||
{
|
||||
$resource = $this->createValidResource('test://resource');
|
||||
$handler = fn () => 'content';
|
||||
$handler = static fn () => 'content';
|
||||
|
||||
$this->registry->registerResource($resource, $handler, true);
|
||||
|
||||
|
|
@ -188,14 +188,14 @@ class RegistryTest extends TestCase
|
|||
$manualResource = $this->createValidResource('test://resource');
|
||||
$discoveredResource = $this->createValidResource('test://resource');
|
||||
|
||||
$this->registry->registerResource($manualResource, fn () => 'manual', true);
|
||||
$this->registry->registerResource($manualResource, static fn () => 'manual', true);
|
||||
|
||||
$this->logger
|
||||
->expects($this->once())
|
||||
->method('debug')
|
||||
->with('Ignoring discovered resource "test://resource" as it conflicts with a manually registered one.');
|
||||
|
||||
$this->registry->registerResource($discoveredResource, fn () => 'discovered');
|
||||
$this->registry->registerResource($discoveredResource, static fn () => 'discovered');
|
||||
|
||||
$resourceRef = $this->registry->getResource('test://resource');
|
||||
$this->assertTrue($resourceRef->isManual);
|
||||
|
|
@ -212,7 +212,7 @@ class RegistryTest extends TestCase
|
|||
public function testHasResourceTemplatesReturnsTrueWhenResourceTemplateIsRegistered(): void
|
||||
{
|
||||
$template = $this->createValidResourceTemplate('test://{id}');
|
||||
$this->registry->registerResourceTemplate($template, fn () => 'content');
|
||||
$this->registry->registerResourceTemplate($template, static fn () => 'content');
|
||||
|
||||
$this->assertTrue($this->registry->hasResourceTemplates());
|
||||
}
|
||||
|
|
@ -222,8 +222,8 @@ class RegistryTest extends TestCase
|
|||
$template1 = $this->createValidResourceTemplate('test1://{id}');
|
||||
$template2 = $this->createValidResourceTemplate('test2://{category}');
|
||||
|
||||
$this->registry->registerResourceTemplate($template1, fn () => 'content1');
|
||||
$this->registry->registerResourceTemplate($template2, fn () => 'content2');
|
||||
$this->registry->registerResourceTemplate($template1, static fn () => 'content1');
|
||||
$this->registry->registerResourceTemplate($template2, static fn () => 'content2');
|
||||
|
||||
$templates = $this->registry->getResourceTemplates();
|
||||
$this->assertCount(2, $templates);
|
||||
|
|
@ -236,7 +236,7 @@ class RegistryTest extends TestCase
|
|||
public function testGetResourceTemplateReturnsRegisteredTemplate(): void
|
||||
{
|
||||
$template = $this->createValidResourceTemplate('test://{id}');
|
||||
$handler = fn (string $id) => "content for {$id}";
|
||||
$handler = static fn (string $id) => "content for {$id}";
|
||||
|
||||
$this->registry->registerResourceTemplate($template, $handler);
|
||||
|
||||
|
|
@ -250,10 +250,10 @@ class RegistryTest extends TestCase
|
|||
public function testGetResourcePrefersDirectResourceOverTemplate(): void
|
||||
{
|
||||
$resource = $this->createValidResource('test://123');
|
||||
$resourceHandler = fn () => 'direct resource';
|
||||
$resourceHandler = static fn () => 'direct resource';
|
||||
|
||||
$template = $this->createValidResourceTemplate('test://{id}');
|
||||
$templateHandler = fn (string $id) => "template for {$id}";
|
||||
$templateHandler = static fn (string $id) => "template for {$id}";
|
||||
|
||||
$this->registry->registerResource($resource, $resourceHandler);
|
||||
$this->registry->registerResourceTemplate($template, $templateHandler);
|
||||
|
|
@ -266,7 +266,7 @@ class RegistryTest extends TestCase
|
|||
public function testGetResourceMatchesResourceTemplate(): void
|
||||
{
|
||||
$template = $this->createValidResourceTemplate('test://{id}');
|
||||
$handler = fn (string $id) => "content for {$id}";
|
||||
$handler = static fn (string $id) => "content for {$id}";
|
||||
|
||||
$this->registry->registerResourceTemplate($template, $handler);
|
||||
|
||||
|
|
@ -279,7 +279,7 @@ class RegistryTest extends TestCase
|
|||
public function testGetResourceWithIncludeTemplatesFalseThrowsException(): void
|
||||
{
|
||||
$template = $this->createValidResourceTemplate('test://{id}');
|
||||
$handler = fn (string $id) => "content for {$id}";
|
||||
$handler = static fn (string $id) => "content for {$id}";
|
||||
|
||||
$this->registry->registerResourceTemplate($template, $handler);
|
||||
|
||||
|
|
@ -294,7 +294,7 @@ class RegistryTest extends TestCase
|
|||
$template = $this->createValidResourceTemplate('test://{id}');
|
||||
$completionProviders = ['id' => EnumCompletionProvider::class];
|
||||
|
||||
$this->registry->registerResourceTemplate($template, fn () => 'content', $completionProviders);
|
||||
$this->registry->registerResourceTemplate($template, static fn () => 'content', $completionProviders);
|
||||
|
||||
$templateRef = $this->registry->getResourceTemplate('test://{id}');
|
||||
$this->assertEquals($completionProviders, $templateRef->completionProviders);
|
||||
|
|
@ -305,14 +305,14 @@ class RegistryTest extends TestCase
|
|||
$manualTemplate = $this->createValidResourceTemplate('test://{id}');
|
||||
$discoveredTemplate = $this->createValidResourceTemplate('test://{id}');
|
||||
|
||||
$this->registry->registerResourceTemplate($manualTemplate, fn () => 'manual', [], true);
|
||||
$this->registry->registerResourceTemplate($manualTemplate, static fn () => 'manual', [], true);
|
||||
|
||||
$this->logger
|
||||
->expects($this->once())
|
||||
->method('debug')
|
||||
->with('Ignoring discovered template "test://{id}" as it conflicts with a manually registered one.');
|
||||
|
||||
$this->registry->registerResourceTemplate($discoveredTemplate, fn () => 'discovered');
|
||||
$this->registry->registerResourceTemplate($discoveredTemplate, static fn () => 'discovered');
|
||||
|
||||
$templateRef = $this->registry->getResourceTemplate('test://{id}');
|
||||
$this->assertTrue($templateRef->isManual);
|
||||
|
|
@ -323,8 +323,8 @@ class RegistryTest extends TestCase
|
|||
$specificTemplate = $this->createValidResourceTemplate('test://users/{userId}/profile');
|
||||
$genericTemplate = $this->createValidResourceTemplate('test://users/{userId}');
|
||||
|
||||
$this->registry->registerResourceTemplate($genericTemplate, fn () => 'generic');
|
||||
$this->registry->registerResourceTemplate($specificTemplate, fn () => 'specific');
|
||||
$this->registry->registerResourceTemplate($genericTemplate, static fn () => 'generic');
|
||||
$this->registry->registerResourceTemplate($specificTemplate, static fn () => 'specific');
|
||||
|
||||
// Should match the more specific template first
|
||||
$resourceRef = $this->registry->getResource('test://users/123/profile');
|
||||
|
|
@ -343,7 +343,7 @@ class RegistryTest extends TestCase
|
|||
public function testHasPromptsReturnsTrueWhenPromptIsRegistered(): void
|
||||
{
|
||||
$prompt = $this->createValidPrompt('test_prompt');
|
||||
$this->registry->registerPrompt($prompt, fn () => []);
|
||||
$this->registry->registerPrompt($prompt, static fn () => []);
|
||||
|
||||
$this->assertTrue($this->registry->hasPrompts());
|
||||
}
|
||||
|
|
@ -353,8 +353,8 @@ class RegistryTest extends TestCase
|
|||
$prompt1 = $this->createValidPrompt('prompt1');
|
||||
$prompt2 = $this->createValidPrompt('prompt2');
|
||||
|
||||
$this->registry->registerPrompt($prompt1, fn () => []);
|
||||
$this->registry->registerPrompt($prompt2, fn () => []);
|
||||
$this->registry->registerPrompt($prompt1, static fn () => []);
|
||||
$this->registry->registerPrompt($prompt2, static fn () => []);
|
||||
|
||||
$prompts = $this->registry->getPrompts();
|
||||
$this->assertCount(2, $prompts);
|
||||
|
|
@ -367,7 +367,7 @@ class RegistryTest extends TestCase
|
|||
public function testGetPromptReturnsRegisteredPrompt(): void
|
||||
{
|
||||
$prompt = $this->createValidPrompt('test_prompt');
|
||||
$handler = fn () => ['role' => 'user', 'content' => 'test message'];
|
||||
$handler = static fn () => ['role' => 'user', 'content' => 'test message'];
|
||||
|
||||
$this->registry->registerPrompt($prompt, $handler);
|
||||
|
||||
|
|
@ -383,7 +383,7 @@ class RegistryTest extends TestCase
|
|||
$prompt = $this->createValidPrompt('test_prompt');
|
||||
$completionProviders = ['param' => EnumCompletionProvider::class];
|
||||
|
||||
$this->registry->registerPrompt($prompt, fn () => [], $completionProviders);
|
||||
$this->registry->registerPrompt($prompt, static fn () => [], $completionProviders);
|
||||
|
||||
$promptRef = $this->registry->getPrompt('test_prompt');
|
||||
$this->assertEquals($completionProviders, $promptRef->completionProviders);
|
||||
|
|
@ -394,14 +394,14 @@ class RegistryTest extends TestCase
|
|||
$manualPrompt = $this->createValidPrompt('test_prompt');
|
||||
$discoveredPrompt = $this->createValidPrompt('test_prompt');
|
||||
|
||||
$this->registry->registerPrompt($manualPrompt, fn () => 'manual', [], true);
|
||||
$this->registry->registerPrompt($manualPrompt, static fn () => 'manual', [], true);
|
||||
|
||||
$this->logger
|
||||
->expects($this->once())
|
||||
->method('debug')
|
||||
->with('Ignoring discovered prompt "test_prompt" as it conflicts with a manually registered one.');
|
||||
|
||||
$this->registry->registerPrompt($discoveredPrompt, fn () => 'discovered');
|
||||
$this->registry->registerPrompt($discoveredPrompt, static fn () => 'discovered');
|
||||
|
||||
$promptRef = $this->registry->getPrompt('test_prompt');
|
||||
$this->assertTrue($promptRef->isManual);
|
||||
|
|
@ -426,14 +426,14 @@ class RegistryTest extends TestCase
|
|||
$manualTemplate = $this->createValidResourceTemplate('manual://{id}');
|
||||
$discoveredTemplate = $this->createValidResourceTemplate('discovered://{id}');
|
||||
|
||||
$this->registry->registerTool($manualTool, fn () => 'manual', true);
|
||||
$this->registry->registerTool($discoveredTool, fn () => 'discovered');
|
||||
$this->registry->registerResource($manualResource, fn () => 'manual', true);
|
||||
$this->registry->registerResource($discoveredResource, fn () => 'discovered');
|
||||
$this->registry->registerPrompt($manualPrompt, fn () => [], [], true);
|
||||
$this->registry->registerPrompt($discoveredPrompt, fn () => []);
|
||||
$this->registry->registerResourceTemplate($manualTemplate, fn () => 'manual', [], true);
|
||||
$this->registry->registerResourceTemplate($discoveredTemplate, fn () => 'discovered');
|
||||
$this->registry->registerTool($manualTool, static fn () => 'manual', true);
|
||||
$this->registry->registerTool($discoveredTool, static fn () => 'discovered');
|
||||
$this->registry->registerResource($manualResource, static fn () => 'manual', true);
|
||||
$this->registry->registerResource($discoveredResource, static fn () => 'discovered');
|
||||
$this->registry->registerPrompt($manualPrompt, static fn () => [], [], true);
|
||||
$this->registry->registerPrompt($discoveredPrompt, static fn () => []);
|
||||
$this->registry->registerResourceTemplate($manualTemplate, static fn () => 'manual', [], true);
|
||||
$this->registry->registerResourceTemplate($discoveredTemplate, static fn () => 'discovered');
|
||||
|
||||
// Test that all elements exist
|
||||
$this->registry->getTool('manual_tool');
|
||||
|
|
@ -470,7 +470,7 @@ class RegistryTest extends TestCase
|
|||
public function testClearLogsNothingWhenNoDiscoveredElements(): void
|
||||
{
|
||||
$manualTool = $this->createValidTool('manual_tool');
|
||||
$this->registry->registerTool($manualTool, fn () => 'manual', true);
|
||||
$this->registry->registerTool($manualTool, static fn () => 'manual', true);
|
||||
|
||||
$this->logger
|
||||
->expects($this->never())
|
||||
|
|
@ -506,7 +506,7 @@ class RegistryTest extends TestCase
|
|||
public function testRegisterResourceHandlesCallableHandler(): void
|
||||
{
|
||||
$resource = $this->createValidResource('test://resource');
|
||||
$handler = fn () => 'content';
|
||||
$handler = static fn () => 'content';
|
||||
|
||||
$this->registry->registerResource($resource, $handler);
|
||||
|
||||
|
|
@ -519,8 +519,8 @@ class RegistryTest extends TestCase
|
|||
$tool1 = $this->createValidTool('test_tool');
|
||||
$tool2 = $this->createValidTool('test_tool');
|
||||
|
||||
$this->registry->registerTool($tool1, fn () => 'first');
|
||||
$this->registry->registerTool($tool2, fn () => 'second');
|
||||
$this->registry->registerTool($tool1, static fn () => 'first');
|
||||
$this->registry->registerTool($tool2, static fn () => 'second');
|
||||
|
||||
// Second registration should override the first
|
||||
$toolRef = $this->registry->getTool('test_tool');
|
||||
|
|
@ -530,7 +530,7 @@ class RegistryTest extends TestCase
|
|||
public function testExtractStructuredContentReturnsNullWhenOutputSchemaIsNull(): void
|
||||
{
|
||||
$tool = $this->createValidTool('test_tool', null);
|
||||
$this->registry->registerTool($tool, fn () => 'result');
|
||||
$this->registry->registerTool($tool, static fn () => 'result');
|
||||
|
||||
$toolRef = $this->registry->getTool('test_tool');
|
||||
$this->assertNull($toolRef->extractStructuredContent('result'));
|
||||
|
|
@ -545,7 +545,7 @@ class RegistryTest extends TestCase
|
|||
],
|
||||
'required' => ['param'],
|
||||
]);
|
||||
$this->registry->registerTool($tool, fn () => [
|
||||
$this->registry->registerTool($tool, static fn () => [
|
||||
'param' => 'test',
|
||||
]);
|
||||
|
||||
|
|
@ -563,7 +563,7 @@ class RegistryTest extends TestCase
|
|||
'type' => 'object',
|
||||
'additionalProperties' => true,
|
||||
]);
|
||||
$this->registry->registerTool($tool, fn () => ['success' => true, 'message' => 'done']);
|
||||
$this->registry->registerTool($tool, static fn () => ['success' => true, 'message' => 'done']);
|
||||
|
||||
$toolRef = $this->registry->getTool('test_tool');
|
||||
$this->assertEquals(['success' => true, 'message' => 'done'], $toolRef->extractStructuredContent(['success' => true, 'message' => 'done']));
|
||||
|
|
@ -594,7 +594,7 @@ class RegistryTest extends TestCase
|
|||
['foo' => 'bar'],
|
||||
];
|
||||
|
||||
$this->registry->registerTool($tool, fn () => $toolReturnValue);
|
||||
$this->registry->registerTool($tool, static fn () => $toolReturnValue);
|
||||
|
||||
// Act
|
||||
$toolRef = $this->registry->getTool('list_static_data');
|
||||
|
|
|
|||
|
|
@ -60,7 +60,7 @@ class CallToolHandlerTest extends TestCase
|
|||
public function testHandleSuccessfulToolCall(): void
|
||||
{
|
||||
$request = $this->createCallToolRequest('greet_user', ['name' => 'John']);
|
||||
$toolReference = $this->createToolReference('greet_user', function () {
|
||||
$toolReference = $this->createToolReference('greet_user', static function () {
|
||||
return 'Hello, John!';
|
||||
});
|
||||
$expectedResult = new CallToolResult([new TextContent('Hello, John!')]);
|
||||
|
|
@ -95,7 +95,7 @@ class CallToolHandlerTest extends TestCase
|
|||
public function testHandleToolCallWithEmptyArguments(): void
|
||||
{
|
||||
$request = $this->createCallToolRequest('simple_tool', []);
|
||||
$toolReference = $this->createToolReference('greet_user', function () {
|
||||
$toolReference = $this->createToolReference('greet_user', static function () {
|
||||
return 'Hello, John!';
|
||||
});
|
||||
$expectedResult = new CallToolResult([new TextContent('Simple result')]);
|
||||
|
|
@ -134,7 +134,7 @@ class CallToolHandlerTest extends TestCase
|
|||
'null_param' => null,
|
||||
];
|
||||
$request = $this->createCallToolRequest('complex_tool', $arguments);
|
||||
$toolReference = $this->createToolReference('greet_user', function () {
|
||||
$toolReference = $this->createToolReference('greet_user', static function () {
|
||||
return 'Hello, John!';
|
||||
});
|
||||
$expectedResult = new CallToolResult([new TextContent('Complex result')]);
|
||||
|
|
@ -189,7 +189,7 @@ class CallToolHandlerTest extends TestCase
|
|||
$request = $this->createCallToolRequest('failing_tool', ['param' => 'value']);
|
||||
$exception = new ToolCallException('Tool execution failed');
|
||||
|
||||
$toolReference = $this->createToolReference('greet_user', function () {
|
||||
$toolReference = $this->createToolReference('greet_user', static function () {
|
||||
return 'Hello, John!';
|
||||
});
|
||||
$this->registry
|
||||
|
|
@ -226,7 +226,7 @@ class CallToolHandlerTest extends TestCase
|
|||
$request = $this->createCallToolRequest('null_tool', []);
|
||||
$expectedResult = new CallToolResult([]);
|
||||
|
||||
$toolReference = $this->createToolReference('greet_user', function () {
|
||||
$toolReference = $this->createToolReference('greet_user', static function () {
|
||||
return 'Hello, John!';
|
||||
});
|
||||
$this->registry
|
||||
|
|
@ -265,7 +265,7 @@ class CallToolHandlerTest extends TestCase
|
|||
$request = $this->createCallToolRequest('test_tool', ['key1' => 'value1', 'key2' => 42]);
|
||||
$exception = new ToolCallException('Custom error message');
|
||||
|
||||
$toolReference = $this->createToolReference('greet_user', function () {
|
||||
$toolReference = $this->createToolReference('greet_user', static function () {
|
||||
return 'Hello, John!';
|
||||
});
|
||||
$this->registry
|
||||
|
|
@ -310,7 +310,7 @@ class CallToolHandlerTest extends TestCase
|
|||
$request = $this->createCallToolRequest('failing_tool', ['param' => 'value']);
|
||||
$exception = new \RuntimeException('Internal database connection failed');
|
||||
|
||||
$toolReference = $this->createToolReference('greet_user', function () {
|
||||
$toolReference = $this->createToolReference('greet_user', static function () {
|
||||
return 'Hello, John!';
|
||||
});
|
||||
$this->registry
|
||||
|
|
@ -339,7 +339,7 @@ class CallToolHandlerTest extends TestCase
|
|||
$request = $this->createCallToolRequest('tool-with_special.chars', []);
|
||||
$expectedResult = new CallToolResult([new TextContent('Special tool result')]);
|
||||
|
||||
$toolReference = $this->createToolReference('greet_user', function () {
|
||||
$toolReference = $this->createToolReference('greet_user', static function () {
|
||||
return 'Hello, John!';
|
||||
});
|
||||
|
||||
|
|
@ -377,7 +377,7 @@ class CallToolHandlerTest extends TestCase
|
|||
$request = $this->createCallToolRequest('unicode_tool', $arguments);
|
||||
$expectedResult = new CallToolResult([new TextContent('Unicode handled')]);
|
||||
|
||||
$toolReference = $this->createToolReference('greet_user', function () {
|
||||
$toolReference = $this->createToolReference('greet_user', static function () {
|
||||
return 'Hello, John!';
|
||||
});
|
||||
$this->registry
|
||||
|
|
@ -407,7 +407,7 @@ class CallToolHandlerTest extends TestCase
|
|||
public function testHandleReturnsStructuredContentResult(): void
|
||||
{
|
||||
$request = $this->createCallToolRequest('structured_tool', ['query' => 'php']);
|
||||
$toolReference = $this->createToolReference('greet_user', function () {
|
||||
$toolReference = $this->createToolReference('greet_user', static function () {
|
||||
return 'Hello, John!';
|
||||
});
|
||||
$structuredResult = new CallToolResult([new TextContent('Rendered results')], false, ['result' => 'Rendered results']);
|
||||
|
|
@ -438,7 +438,7 @@ class CallToolHandlerTest extends TestCase
|
|||
public function testHandleReturnsCallToolResult(): void
|
||||
{
|
||||
$request = $this->createCallToolRequest('result_tool', ['query' => 'php']);
|
||||
$toolReference = $this->createToolReference('greet_user', function () {
|
||||
$toolReference = $this->createToolReference('greet_user', static function () {
|
||||
return 'Hello, John!';
|
||||
});
|
||||
$callToolResult = new CallToolResult([new TextContent('Error result')], true);
|
||||
|
|
@ -483,7 +483,7 @@ class CallToolHandlerTest extends TestCase
|
|||
|
||||
$request = $this->createCallToolRequest('result_tool', ['query' => 'php']);
|
||||
$toolReference = $this->getMockBuilder(ToolReference::class)
|
||||
->setConstructorArgs([new Tool('simple_tool', $schema, null, null), function () {}])
|
||||
->setConstructorArgs([new Tool('simple_tool', $schema, null, null), static function () {}])
|
||||
->getMock();
|
||||
|
||||
$this->registry
|
||||
|
|
|
|||
|
|
@ -226,7 +226,7 @@ class ListPromptsHandlerTest extends TestCase
|
|||
description: "Test prompt $i"
|
||||
);
|
||||
|
||||
$this->registry->registerPrompt($prompt, fn () => null);
|
||||
$this->registry->registerPrompt($prompt, static fn () => null);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -196,7 +196,7 @@ class ListResourceTemplatesHandlerTest extends TestCase
|
|||
description: "Test resource $i"
|
||||
);
|
||||
// Use a simple callable as handler
|
||||
$this->registry->registerResourceTemplate($resourceTemplate, fn () => null);
|
||||
$this->registry->registerResourceTemplate($resourceTemplate, static fn () => null);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -227,7 +227,7 @@ class ListResourcesHandlerTest extends TestCase
|
|||
description: "Test resource $i"
|
||||
);
|
||||
// Use a simple callable as handler
|
||||
$this->registry->registerResource($resource, fn () => null);
|
||||
$this->registry->registerResource($resource, static fn () => null);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -298,7 +298,7 @@ class ListToolsHandlerTest extends TestCase
|
|||
annotations: null
|
||||
);
|
||||
|
||||
$this->registry->registerTool($tool, fn () => null);
|
||||
$this->registry->registerTool($tool, static fn () => null);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -99,7 +99,7 @@ final class ProtocolTest extends TestCase
|
|||
|
||||
// Configure session mock for queue operations
|
||||
$queue = [];
|
||||
$session->method('get')->willReturnCallback(function ($key, $default = null) use (&$queue) {
|
||||
$session->method('get')->willReturnCallback(static function ($key, $default = null) use (&$queue) {
|
||||
if ('_mcp.outgoing_queue' === $key) {
|
||||
return $queue;
|
||||
}
|
||||
|
|
@ -107,7 +107,7 @@ final class ProtocolTest extends TestCase
|
|||
return $default;
|
||||
});
|
||||
|
||||
$session->method('set')->willReturnCallback(function ($key, $value) use (&$queue) {
|
||||
$session->method('set')->willReturnCallback(static function ($key, $value) use (&$queue) {
|
||||
if ('_mcp.outgoing_queue' === $key) {
|
||||
$queue = $value;
|
||||
}
|
||||
|
|
@ -147,7 +147,7 @@ final class ProtocolTest extends TestCase
|
|||
$this->transport->expects($this->once())
|
||||
->method('send')
|
||||
->with(
|
||||
$this->callback(function ($data) {
|
||||
$this->callback(static function ($data) {
|
||||
$decoded = json_decode($data, true);
|
||||
|
||||
return isset($decoded['error'])
|
||||
|
|
@ -178,7 +178,7 @@ final class ProtocolTest extends TestCase
|
|||
$this->transport->expects($this->once())
|
||||
->method('send')
|
||||
->with(
|
||||
$this->callback(function ($data) {
|
||||
$this->callback(static function ($data) {
|
||||
$decoded = json_decode($data, true);
|
||||
|
||||
return isset($decoded['error'])
|
||||
|
|
@ -208,13 +208,13 @@ final class ProtocolTest extends TestCase
|
|||
$this->transport->expects($this->once())
|
||||
->method('send')
|
||||
->with(
|
||||
$this->callback(function ($data) {
|
||||
$this->callback(static function ($data) {
|
||||
$decoded = json_decode($data, true);
|
||||
|
||||
return isset($decoded['error'])
|
||||
&& str_contains($decoded['error']['message'], 'session id is REQUIRED');
|
||||
}),
|
||||
$this->callback(function ($context) {
|
||||
$this->callback(static function ($context) {
|
||||
return isset($context['status_code']) && 400 === $context['status_code'];
|
||||
})
|
||||
);
|
||||
|
|
@ -242,13 +242,13 @@ final class ProtocolTest extends TestCase
|
|||
$this->transport->expects($this->once())
|
||||
->method('send')
|
||||
->with(
|
||||
$this->callback(function ($data) {
|
||||
$this->callback(static function ($data) {
|
||||
$decoded = json_decode($data, true);
|
||||
|
||||
return isset($decoded['error'])
|
||||
&& str_contains($decoded['error']['message'], 'Session not found or has expired');
|
||||
}),
|
||||
$this->callback(function ($context) {
|
||||
$this->callback(static function ($context) {
|
||||
return isset($context['status_code']) && 404 === $context['status_code'];
|
||||
})
|
||||
);
|
||||
|
|
@ -275,7 +275,7 @@ final class ProtocolTest extends TestCase
|
|||
$this->transport->expects($this->once())
|
||||
->method('send')
|
||||
->with(
|
||||
$this->callback(function ($data) {
|
||||
$this->callback(static function ($data) {
|
||||
$decoded = json_decode($data, true);
|
||||
|
||||
return isset($decoded['error'])
|
||||
|
|
@ -309,7 +309,7 @@ final class ProtocolTest extends TestCase
|
|||
|
||||
// Configure session mock for queue operations
|
||||
$queue = [];
|
||||
$session->method('get')->willReturnCallback(function ($key, $default = null) use (&$queue) {
|
||||
$session->method('get')->willReturnCallback(static function ($key, $default = null) use (&$queue) {
|
||||
if ('_mcp.outgoing_queue' === $key) {
|
||||
return $queue;
|
||||
}
|
||||
|
|
@ -317,7 +317,7 @@ final class ProtocolTest extends TestCase
|
|||
return $default;
|
||||
});
|
||||
|
||||
$session->method('set')->willReturnCallback(function ($key, $value) use (&$queue) {
|
||||
$session->method('set')->willReturnCallback(static function ($key, $value) use (&$queue) {
|
||||
if ('_mcp.outgoing_queue' === $key) {
|
||||
$queue = $value;
|
||||
}
|
||||
|
|
@ -362,7 +362,7 @@ final class ProtocolTest extends TestCase
|
|||
|
||||
// Configure session mock for queue operations
|
||||
$queue = [];
|
||||
$session->method('get')->willReturnCallback(function ($key, $default = null) use (&$queue) {
|
||||
$session->method('get')->willReturnCallback(static function ($key, $default = null) use (&$queue) {
|
||||
if ('_mcp.outgoing_queue' === $key) {
|
||||
return $queue;
|
||||
}
|
||||
|
|
@ -370,7 +370,7 @@ final class ProtocolTest extends TestCase
|
|||
return $default;
|
||||
});
|
||||
|
||||
$session->method('set')->willReturnCallback(function ($key, $value) use (&$queue) {
|
||||
$session->method('set')->willReturnCallback(static function ($key, $value) use (&$queue) {
|
||||
if ('_mcp.outgoing_queue' === $key) {
|
||||
$queue = $value;
|
||||
}
|
||||
|
|
@ -420,7 +420,7 @@ final class ProtocolTest extends TestCase
|
|||
|
||||
// Configure session mock for queue operations
|
||||
$queue = [];
|
||||
$session->method('get')->willReturnCallback(function ($key, $default = null) use (&$queue) {
|
||||
$session->method('get')->willReturnCallback(static function ($key, $default = null) use (&$queue) {
|
||||
if ('_mcp.outgoing_queue' === $key) {
|
||||
return $queue;
|
||||
}
|
||||
|
|
@ -428,7 +428,7 @@ final class ProtocolTest extends TestCase
|
|||
return $default;
|
||||
});
|
||||
|
||||
$session->method('set')->willReturnCallback(function ($key, $value) use (&$queue) {
|
||||
$session->method('set')->willReturnCallback(static function ($key, $value) use (&$queue) {
|
||||
if ('_mcp.outgoing_queue' === $key) {
|
||||
$queue = $value;
|
||||
}
|
||||
|
|
@ -478,7 +478,7 @@ final class ProtocolTest extends TestCase
|
|||
|
||||
// Configure session mock for queue operations
|
||||
$queue = [];
|
||||
$session->method('get')->willReturnCallback(function ($key, $default = null) use (&$queue) {
|
||||
$session->method('get')->willReturnCallback(static function ($key, $default = null) use (&$queue) {
|
||||
if ('_mcp.outgoing_queue' === $key) {
|
||||
return $queue;
|
||||
}
|
||||
|
|
@ -486,7 +486,7 @@ final class ProtocolTest extends TestCase
|
|||
return $default;
|
||||
});
|
||||
|
||||
$session->method('set')->willReturnCallback(function ($key, $value) use (&$queue) {
|
||||
$session->method('set')->willReturnCallback(static function ($key, $value) use (&$queue) {
|
||||
if ('_mcp.outgoing_queue' === $key) {
|
||||
$queue = $value;
|
||||
}
|
||||
|
|
@ -568,7 +568,7 @@ final class ProtocolTest extends TestCase
|
|||
|
||||
// Configure session mock for queue operations
|
||||
$queue = [];
|
||||
$session->method('get')->willReturnCallback(function ($key, $default = null) use (&$queue) {
|
||||
$session->method('get')->willReturnCallback(static function ($key, $default = null) use (&$queue) {
|
||||
if ('_mcp.outgoing_queue' === $key) {
|
||||
return $queue;
|
||||
}
|
||||
|
|
@ -576,7 +576,7 @@ final class ProtocolTest extends TestCase
|
|||
return $default;
|
||||
});
|
||||
|
||||
$session->method('set')->willReturnCallback(function ($key, $value) use (&$queue) {
|
||||
$session->method('set')->willReturnCallback(static function ($key, $value) use (&$queue) {
|
||||
if ('_mcp.outgoing_queue' === $key) {
|
||||
$queue = $value;
|
||||
}
|
||||
|
|
@ -615,7 +615,7 @@ final class ProtocolTest extends TestCase
|
|||
{
|
||||
$handlerA = $this->createMock(RequestHandlerInterface::class);
|
||||
$handlerA->method('supports')->willReturn(true);
|
||||
$handlerA->method('handle')->willReturnCallback(function ($request) {
|
||||
$handlerA->method('handle')->willReturnCallback(static function ($request) {
|
||||
return Response::fromArray([
|
||||
'jsonrpc' => '2.0',
|
||||
'id' => $request->getId(),
|
||||
|
|
@ -628,7 +628,7 @@ final class ProtocolTest extends TestCase
|
|||
|
||||
// Configure session mock for queue operations
|
||||
$queue = [];
|
||||
$session->method('get')->willReturnCallback(function ($key, $default = null) use (&$queue) {
|
||||
$session->method('get')->willReturnCallback(static function ($key, $default = null) use (&$queue) {
|
||||
if ('_mcp.outgoing_queue' === $key) {
|
||||
return $queue;
|
||||
}
|
||||
|
|
@ -636,7 +636,7 @@ final class ProtocolTest extends TestCase
|
|||
return $default;
|
||||
});
|
||||
|
||||
$session->method('set')->willReturnCallback(function ($key, $value) use (&$queue) {
|
||||
$session->method('set')->willReturnCallback(static function ($key, $value) use (&$queue) {
|
||||
if ('_mcp.outgoing_queue' === $key) {
|
||||
$queue = $value;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -48,20 +48,20 @@ final class ServerTest extends TestCase
|
|||
|
||||
$this->transport->expects($this->once())
|
||||
->method('initialize')
|
||||
->willReturnCallback(function () use (&$callOrder) {
|
||||
->willReturnCallback(static function () use (&$callOrder) {
|
||||
$callOrder[] = 'initialize';
|
||||
});
|
||||
|
||||
$this->protocol->expects($this->once())
|
||||
->method('connect')
|
||||
->with($this->transport)
|
||||
->willReturnCallback(function () use (&$callOrder) {
|
||||
->willReturnCallback(static function () use (&$callOrder) {
|
||||
$callOrder[] = 'connect';
|
||||
});
|
||||
|
||||
$this->transport->expects($this->once())
|
||||
->method('listen')
|
||||
->willReturnCallback(function () use (&$callOrder) {
|
||||
->willReturnCallback(static function () use (&$callOrder) {
|
||||
$callOrder[] = 'listen';
|
||||
|
||||
return 0;
|
||||
|
|
@ -69,7 +69,7 @@ final class ServerTest extends TestCase
|
|||
|
||||
$this->transport->expects($this->once())
|
||||
->method('close')
|
||||
->willReturnCallback(function () use (&$callOrder) {
|
||||
->willReturnCallback(static function () use (&$callOrder) {
|
||||
$callOrder[] = 'close';
|
||||
});
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue