Skip to content

Commit b39fa5d

Browse files
committed
Test the new notification publisher
1 parent c0a483b commit b39fa5d

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

src/Server/NotificationPublisher.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public static function make(EventDispatcher $eventDispatcher): self
4343
return $instance;
4444
}
4545

46-
public function onEvent(object $event): void
46+
public function onEvent(Event $event): void
4747
{
4848
$eventClass = $event::class;
4949
if (!isset(self::EVENTS_TO_NOTIFICATIONS[$eventClass])) {
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Mcp\Tests\Server;
6+
7+
use Mcp\JsonRpc\MessageFactory;
8+
use Mcp\Server\NotificationPublisher;
9+
use PHPUnit\Framework\TestCase;
10+
use Symfony\Contracts\EventDispatcher\Event;
11+
12+
class NotificationPublisherTest extends TestCase
13+
{
14+
public function testOnEventCreatesNotification(): void
15+
{
16+
$expectedNotifications = [];
17+
$notificationPublisher = new NotificationPublisher(MessageFactory::make());
18+
19+
foreach (NotificationPublisher::EVENTS_TO_NOTIFICATIONS as $eventClass => $notificationClass) {
20+
/** @var Event $event */
21+
$event = new $eventClass();
22+
$notificationPublisher->onEvent($event);
23+
$expectedNotifications[] = $notificationClass;
24+
}
25+
26+
$flushedNotifications = $notificationPublisher->flush();
27+
28+
$this->assertCount(count($expectedNotifications), $flushedNotifications);
29+
30+
foreach ($flushedNotifications as $index => $notification) {
31+
$this->assertInstanceOf($expectedNotifications[$index], $notification);
32+
}
33+
34+
$this->assertEmpty($notificationPublisher->flush());
35+
}
36+
}

0 commit comments

Comments
 (0)