* style: apply php-cs-fixer to test files Addresses drift flagged by the default PHP-CS-Fixer config — mostly adds missing `: void` return types on pre-existing test methods. No behavioural changes. * fix: resolve phpstan errors surfaced by qa - Drop the obsolete `Method ::test*() has no return type specified` ignore rule — every test method now declares a return type, so the pattern never matches and phpstan reports it as unmatched. - Remove `?? []` from two reads of `CallToolRequest::$arguments`; the property is typed `array` (non-nullable), so the coalesce is a no-op that phpstan flags. --------- Co-authored-by: DDEV User <nobody@example.com>
92 lines
3.1 KiB
PHP
92 lines
3.1 KiB
PHP
<?php
|
|
|
|
/*
|
|
* This file is part of the official PHP MCP SDK.
|
|
*
|
|
* A collaboration between Symfony and the PHP Foundation.
|
|
*
|
|
* For the full copyright and license information, please view the LICENSE
|
|
* file that was distributed with this source code.
|
|
*/
|
|
|
|
namespace Mcp\Tests\Unit\Capability\Logger;
|
|
|
|
use Mcp\Capability\Logger\ClientLogger;
|
|
use Mcp\Schema\Enum\LoggingLevel;
|
|
use Mcp\Server\ClientGateway;
|
|
use Mcp\Server\Session\Session;
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
/**
|
|
* Test for simplified ClientLogger PSR-3 compliance.
|
|
*/
|
|
final class ClientLoggerTest extends TestCase
|
|
{
|
|
public function testLog(): void
|
|
{
|
|
$session = $this->getMockBuilder(Session::class)
|
|
->disableOriginalConstructor()
|
|
->onlyMethods(['get'])
|
|
->getMock();
|
|
$session->expects($this->once())->method('get')->willReturn('info');
|
|
$clientGateway = $this->getMockBuilder(ClientGateway::class)
|
|
->disableOriginalConstructor()
|
|
->onlyMethods(['log'])
|
|
->getMock();
|
|
$clientGateway->expects($this->once())->method('log')->with(LoggingLevel::Notice, 'test');
|
|
|
|
$logger = new ClientLogger($clientGateway, $session);
|
|
$logger->notice('test');
|
|
}
|
|
|
|
public function testLogFilter(): void
|
|
{
|
|
$session = $this->getMockBuilder(Session::class)
|
|
->disableOriginalConstructor()
|
|
->onlyMethods(['get'])
|
|
->getMock();
|
|
$session->expects($this->once())->method('get')->willReturn('info');
|
|
$clientGateway = $this->getMockBuilder(ClientGateway::class)
|
|
->disableOriginalConstructor()
|
|
->onlyMethods(['log'])
|
|
->getMock();
|
|
$clientGateway->expects($this->never())->method('log');
|
|
|
|
$logger = new ClientLogger($clientGateway, $session);
|
|
$logger->debug('test');
|
|
}
|
|
|
|
public function testLogFilterSameLevel(): void
|
|
{
|
|
$session = $this->getMockBuilder(Session::class)
|
|
->disableOriginalConstructor()
|
|
->onlyMethods(['get'])
|
|
->getMock();
|
|
$session->expects($this->once())->method('get')->willReturn('info');
|
|
$clientGateway = $this->getMockBuilder(ClientGateway::class)
|
|
->disableOriginalConstructor()
|
|
->onlyMethods(['log'])
|
|
->getMock();
|
|
$clientGateway->expects($this->once())->method('log');
|
|
|
|
$logger = new ClientLogger($clientGateway, $session);
|
|
$logger->info('test');
|
|
}
|
|
|
|
public function testLogWithInvalidLevel(): void
|
|
{
|
|
$session = $this->getMockBuilder(Session::class)
|
|
->disableOriginalConstructor()
|
|
->onlyMethods(['get'])
|
|
->getMock();
|
|
$session->expects($this->any())->method('get')->willReturn('info');
|
|
$clientGateway = $this->getMockBuilder(ClientGateway::class)
|
|
->disableOriginalConstructor()
|
|
->onlyMethods(['log'])
|
|
->getMock();
|
|
$clientGateway->expects($this->never())->method('log');
|
|
|
|
$logger = new ClientLogger($clientGateway, $session);
|
|
$logger->log('foo', 'test');
|
|
}
|
|
}
|