Kick off the SDK based on Symfony's MCP SDK
This commit is contained in:
parent
0044ffb365
commit
ee0dffe369
1 changed files with 3924 additions and 0 deletions
50
tests/ServerTest.php
Normal file
50
tests/ServerTest.php
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
<?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;
|
||||
|
||||
use Mcp\Server;
|
||||
use Mcp\Server\JsonRpcHandler;
|
||||
use Mcp\Tests\Fixtures\InMemoryTransport;
|
||||
use PHPUnit\Framework\Attributes\CoversClass;
|
||||
use PHPUnit\Framework\Attributes\Small;
|
||||
use PHPUnit\Framework\MockObject\Stub\Exception;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Psr\Log\NullLogger;
|
||||
|
||||
#[Small]
|
||||
#[CoversClass(Server::class)]
|
||||
class ServerTest extends TestCase
|
||||
{
|
||||
public function testJsonExceptions(): void
|
||||
{
|
||||
$logger = $this->getMockBuilder(NullLogger::class)
|
||||
->disableOriginalConstructor()
|
||||
->onlyMethods(['error'])
|
||||
->getMock();
|
||||
$logger->expects($this->once())->method('error');
|
||||
|
||||
$handler = $this->getMockBuilder(JsonRpcHandler::class)
|
||||
->disableOriginalConstructor()
|
||||
->onlyMethods(['process'])
|
||||
->getMock();
|
||||
$handler->expects($this->exactly(2))->method('process')->willReturnOnConsecutiveCalls(new Exception(new \JsonException('foobar')), ['success']);
|
||||
|
||||
$transport = $this->getMockBuilder(InMemoryTransport::class)
|
||||
->setConstructorArgs([['foo', 'bar']])
|
||||
->onlyMethods(['send'])
|
||||
->getMock();
|
||||
$transport->expects($this->once())->method('send')->with('success');
|
||||
|
||||
$server = new Server($handler, $logger);
|
||||
$server->connect($transport);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue