Skip to content

Commit 244a81e

Browse files
committed
Unify tests
1 parent 4a29253 commit 244a81e

File tree

2 files changed

+54
-96
lines changed

2 files changed

+54
-96
lines changed

tests/Capability/Registry/RegistryTest.php

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313

1414
use Mcp\Capability\Prompt\Completion\EnumCompletionProvider;
1515
use Mcp\Capability\Registry;
16+
use Mcp\Schema\Notification\PromptListChangedNotification;
17+
use Mcp\Schema\Notification\ResourceListChangedNotification;
18+
use Mcp\Schema\Notification\ToolListChangedNotification;
1619
use Mcp\Schema\Prompt;
1720
use Mcp\Schema\Resource;
1821
use Mcp\Schema\ResourceTemplate;
@@ -305,6 +308,57 @@ public function testMultipleRegistrationsOfSameElementWithSameType(): void
305308
$this->assertEquals('second', ($toolRef->handler)());
306309
}
307310

311+
public function testToolRegistrationTriggersNotification(): void
312+
{
313+
$tool = $this->createValidTool('the-best-tool-name-ever');
314+
315+
$expected = [$tool->name => $tool];
316+
317+
$notificationPublisher = $this->createMock(NotificationPublisher::class);
318+
$notificationPublisher->expects($this->once())
319+
->method('enqueue')
320+
->with(new ToolListChangedNotification());
321+
322+
$registry = new Registry($notificationPublisher);
323+
$registry->registerTool($tool, fn () => null);
324+
325+
$this->assertSame($expected, $registry->getTools());
326+
}
327+
328+
public function testResourceRegistrationTriggersNotification(): void
329+
{
330+
$resource = $this->createValidResource('config://the-best-resource-uri-ever');
331+
332+
$expected = [$resource->uri => $resource];
333+
334+
$notificationPublisher = $this->createMock(NotificationPublisher::class);
335+
$notificationPublisher->expects($this->once())
336+
->method('enqueue')
337+
->with(new ResourceListChangedNotification());
338+
339+
$registry = new Registry($notificationPublisher);
340+
$registry->registerResource($resource, fn () => null);
341+
342+
$this->assertSame($expected, $registry->getResources());
343+
}
344+
345+
public function testPromptRegistrationTriggersNotification(): void
346+
{
347+
$prompt = $this->createValidPrompt('the-best-prompt-ever');
348+
349+
$expected = [$prompt->name => $prompt];
350+
351+
$notificationPublisher = $this->createMock(NotificationPublisher::class);
352+
$notificationPublisher->expects($this->once())
353+
->method('enqueue')
354+
->with(new PromptListChangedNotification());
355+
356+
$registry = new Registry($notificationPublisher);
357+
$registry->registerPrompt($prompt, fn () => null);
358+
359+
$this->assertSame($expected, $registry->getPrompts());
360+
}
361+
308362
private function createValidTool(string $name): Tool
309363
{
310364
return new Tool(

tests/Capability/RegistryTest.php

Lines changed: 0 additions & 96 deletions
This file was deleted.

0 commit comments

Comments
 (0)