Skip to content

Commit 0eab7fb

Browse files
committed
Test new message factory method
1 parent 8317429 commit 0eab7fb

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

tests/JsonRpc/MessageFactoryTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,12 @@
1111

1212
namespace Mcp\Tests\JsonRpc;
1313

14+
use Mcp\Exception\InvalidArgumentException;
1415
use Mcp\Exception\InvalidInputMessageException;
1516
use Mcp\JsonRpc\MessageFactory;
1617
use Mcp\Schema\Notification\CancelledNotification;
1718
use Mcp\Schema\Notification\InitializedNotification;
19+
use Mcp\Schema\Notification\ResourceListChangedNotification;
1820
use Mcp\Schema\Request\GetPromptRequest;
1921
use PHPUnit\Framework\TestCase;
2022

@@ -81,6 +83,22 @@ public function testBatchMissingMethod()
8183
$this->assertInstanceOf(InitializedNotification::class, $result);
8284
}
8385

86+
public function testCreateByType(): void
87+
{
88+
$result = $this->factory->createByType(InitializedNotification::class, []);
89+
$this->assertInstanceOf(InitializedNotification::class, $result);
90+
}
91+
92+
public function testCreateByTypeWithMissingData(): void
93+
{
94+
$this->expectException(InvalidArgumentException::class);
95+
$this->expectExceptionMessage(
96+
'Invalid or missing "requestId" parameter for "notifications/cancelled" notification.'
97+
);
98+
99+
$this->factory->createByType(CancelledNotification::class, []);
100+
}
101+
84102
/**
85103
* @param iterable<mixed> $items
86104
*/

0 commit comments

Comments
 (0)