Files
WP-LIT-MCP/tests/Unit/Server/ServerRegistrarTest.php
T

81 lines
2.8 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
declare(strict_types=1);
namespace LIT\MCP\Tests\Unit\Server;
use Brain\Monkey\Functions;
use LIT\MCP\Abilities\Ability;
use LIT\MCP\Guides\InstructionsBuilder;
use LIT\MCP\Integrations\Integration;
use LIT\MCP\Integrations\IntegrationRegistry;
use LIT\MCP\Server\ServerRegistrar;
use LIT\MCP\Tests\Unit\TestCase;
use Mockery;
final class ServerRegistrarTest extends TestCase
{
private function registry(): IntegrationRegistry
{
$direct = Mockery::mock(Ability::class);
$direct->allows('name')->andReturn('lit/guide');
$direct->allows('isDirect')->andReturn(true);
$indirect = Mockery::mock(Ability::class);
$indirect->allows('name')->andReturn('lit/rare-tool');
$indirect->allows('isDirect')->andReturn(false);
$core = Mockery::mock(Integration::class);
$core->allows('id')->andReturn('core');
$core->allows('isAvailable')->andReturn(true);
$core->allows('abilities')->andReturn([$direct, $indirect]);
return new IntegrationRegistry($core);
}
private function instructions(): InstructionsBuilder
{
// InstructionsBuilder is final (not mockable) and pure – use the real one.
return new InstructionsBuilder($this->registry());
}
public function testServerUsesOauthRouteDirectToolsPlusMetaToolsAndInstructions(): void
{
$args = (new ServerRegistrar($this->registry(), $this->instructions(), static fn () => true))->serverArguments();
self::assertSame('mcp-oauth-server', $args['id']);
self::assertSame('mcp', $args['namespace']);
self::assertSame('mcp-oauth-server', $args['route']);
self::assertStringContainsString('Aktive Integrationen: core', $args['description']);
self::assertSame(
['lit/guide', 'mcp-adapter/discover-abilities', 'mcp-adapter/get-ability-info', 'mcp-adapter/execute-ability'],
$args['tools']
);
self::assertNotContains('lit/rare-tool', $args['tools']);
}
public function testNoServerWhenOauthIsDisabled(): void
{
$registrar = new ServerRegistrar($this->registry(), $this->instructions(), static fn () => false);
self::assertNull($registrar->serverArguments());
}
public function testCreateServerOutsideAdapterInitDoesNothing(): void
{
Functions\when('doing_action')->justReturn(false);
$oauthChecked = false;
$registrar = new ServerRegistrar(
$this->registry(),
$this->instructions(),
static function () use (&$oauthChecked): bool {
$oauthChecked = true;
return true;
}
);
$registrar->createServer();
self::assertFalse($oauthChecked, 'createServer must bail out before touching the adapter');
}
}