|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +/** |
| 6 | + * This file is part of the Nexus MCP SDK package. |
| 7 | + * |
| 8 | + * (c) 2025 John Paul E. Balandan, CPA <[email protected]> |
| 9 | + * |
| 10 | + * For the full copyright and license information, please view |
| 11 | + * the LICENSE file that was distributed with this source code. |
| 12 | + */ |
| 13 | + |
| 14 | +namespace Nexus\Mcp\Tests\Message; |
| 15 | + |
| 16 | +use Nexus\Mcp\Message\Message; |
| 17 | +use PHPUnit\Framework\Attributes\CoversClass; |
| 18 | +use PHPUnit\Framework\TestCase; |
| 19 | + |
| 20 | +/** |
| 21 | + * @internal |
| 22 | + */ |
| 23 | +#[CoversClass(Message::class)] |
| 24 | +final class MessageTest extends TestCase |
| 25 | +{ |
| 26 | + public function testMessageDoesNotAcceptInvalidJsonRpcVersion(): void |
| 27 | + { |
| 28 | + $this->expectException(\InvalidArgumentException::class); |
| 29 | + $this->expectExceptionMessage('Invalid JSON-RPC version.'); |
| 30 | + $this->getMockBuilder(Message::class)->setConstructorArgs(['1.1'])->getMock(); |
| 31 | + } |
| 32 | + |
| 33 | + public function testMessageDoesNotAcceptEmptyJsonRpcVersion(): void |
| 34 | + { |
| 35 | + $this->expectException(\InvalidArgumentException::class); |
| 36 | + $this->expectExceptionMessage('JSON-RPC version cannot be empty.'); |
| 37 | + $this->getMockBuilder(Message::class)->setConstructorArgs([''])->getMock(); |
| 38 | + } |
| 39 | + |
| 40 | + public function testMessageCanBeJsonSerialized(): void |
| 41 | + { |
| 42 | + $message = $this->getMockBuilder(Message::class) |
| 43 | + ->setConstructorArgs([Message::JSON_RPC_VERSION]) |
| 44 | + ->onlyMethods(['toArray']) |
| 45 | + ->getMock() |
| 46 | + ; |
| 47 | + $message->method('toArray')->willReturn(['jsonrpc' => Message::JSON_RPC_VERSION]); |
| 48 | + |
| 49 | + self::assertSame('{"jsonrpc":"2.0"}', json_encode($message)); |
| 50 | + } |
| 51 | +} |
0 commit comments