Add PSR-3 compliant exception context when logging exceptions (#300)
* Add PSR-3 exception context to caught error logs * Apply review feedback
This commit is contained in:
parent
bfc4728792
commit
73414d65f6
1 changed files with 88 additions and 27 deletions
|
|
@ -26,6 +26,7 @@ use Mcp\Server\Session\SessionInterface;
|
|||
use PHPUnit\Framework\Attributes\TestDox;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
class ResourceSubscribeTest extends TestCase
|
||||
{
|
||||
|
|
@ -33,13 +34,15 @@ class ResourceSubscribeTest extends TestCase
|
|||
private RegistryInterface&MockObject $registry;
|
||||
private SessionInterface&MockObject $session;
|
||||
private SubscriptionManagerInterface&MockObject $subscriptionManager;
|
||||
private LoggerInterface&MockObject $logger;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->registry = $this->createMock(RegistryInterface::class);
|
||||
$this->subscriptionManager = $this->createMock(SubscriptionManagerInterface::class);
|
||||
$this->session = $this->createMock(SessionInterface::class);
|
||||
$this->handler = new ResourceSubscribeHandler($this->registry, $this->subscriptionManager);
|
||||
$this->logger = $this->createMock(LoggerInterface::class);
|
||||
$this->handler = new ResourceSubscribeHandler($this->registry, $this->subscriptionManager, $this->logger);
|
||||
}
|
||||
|
||||
#[TestDox('Client can successfully subscribe to a resource')]
|
||||
|
|
@ -121,6 +124,11 @@ class ResourceSubscribeTest extends TestCase
|
|||
->with($uri)
|
||||
->willThrowException($exception);
|
||||
|
||||
$this->logger
|
||||
->expects($this->once())
|
||||
->method('error')
|
||||
->with('Resource not found', ['uri' => $uri, 'exception' => $exception]);
|
||||
|
||||
$response = $this->handler->handle($request, $this->session);
|
||||
|
||||
$this->assertInstanceOf(Error::class, $response);
|
||||
|
|
|
|||
Loading…
Reference in a new issue