Introduce Capability Registry & Discovery
This commit is contained in:
parent
09707b4798
commit
da0d5a87a0
2 changed files with 7063 additions and 8 deletions
|
|
@ -0,0 +1,85 @@
|
|||
<?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\Capability\Prompt\Completion;
|
||||
|
||||
use Mcp\Capability\Prompt\Completion\EnumCompletionProvider;
|
||||
use Mcp\Exception\InvalidArgumentException;
|
||||
use Mcp\Tests\Fixtures\Enum\PriorityEnum;
|
||||
use Mcp\Tests\Fixtures\Enum\StatusEnum;
|
||||
use Mcp\Tests\Fixtures\Enum\UnitEnum;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class EnumCompletionProviderTest extends TestCase
|
||||
{
|
||||
public function testCreatesProviderFromStringBackedEnum()
|
||||
{
|
||||
$provider = new EnumCompletionProvider(StatusEnum::class);
|
||||
$result = $provider->getCompletions('');
|
||||
$this->assertSame(['draft', 'published', 'archived'], $result);
|
||||
}
|
||||
|
||||
public function testCreatesProviderFromIntBackedEnumUsingNames()
|
||||
{
|
||||
$provider = new EnumCompletionProvider(PriorityEnum::class);
|
||||
$result = $provider->getCompletions('');
|
||||
|
||||
$this->assertSame(['LOW', 'MEDIUM', 'HIGH'], $result);
|
||||
}
|
||||
|
||||
public function testCreatesProviderFromUnitEnumUsingNames()
|
||||
{
|
||||
$provider = new EnumCompletionProvider(UnitEnum::class);
|
||||
$result = $provider->getCompletions('');
|
||||
|
||||
$this->assertSame(['Yes', 'No'], $result);
|
||||
}
|
||||
|
||||
public function testFiltersStringEnumValuesByPrefix()
|
||||
{
|
||||
$provider = new EnumCompletionProvider(StatusEnum::class);
|
||||
$result = $provider->getCompletions('ar');
|
||||
|
||||
$this->assertEquals(['archived'], $result);
|
||||
}
|
||||
|
||||
public function testFiltersUnitEnumValuesByPrefix()
|
||||
{
|
||||
$provider = new EnumCompletionProvider(UnitEnum::class);
|
||||
$result = $provider->getCompletions('Y');
|
||||
|
||||
$this->assertSame(['Yes'], $result);
|
||||
}
|
||||
|
||||
public function testReturnsEmptyArrayWhenNoValuesMatchPrefix()
|
||||
{
|
||||
$provider = new EnumCompletionProvider(StatusEnum::class);
|
||||
$result = $provider->getCompletions('xyz');
|
||||
|
||||
$this->assertSame([], $result);
|
||||
}
|
||||
|
||||
public function testThrowsExceptionForNonEnumClass()
|
||||
{
|
||||
$this->expectException(InvalidArgumentException::class);
|
||||
$this->expectExceptionMessage('Class "stdClass" is not an enum.');
|
||||
|
||||
new EnumCompletionProvider(\stdClass::class);
|
||||
}
|
||||
|
||||
public function testThrowsExceptionForNonExistentClass()
|
||||
{
|
||||
$this->expectException(InvalidArgumentException::class);
|
||||
$this->expectExceptionMessage('Class "NonExistentClass" is not an enum.');
|
||||
|
||||
new EnumCompletionProvider('NonExistentClass'); /* @phpstan-ignore argument.type */
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,80 @@
|
|||
<?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\Capability\Prompt\Completion;
|
||||
|
||||
use Mcp\Capability\Prompt\Completion\ListCompletionProvider;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class ListCompletionProviderTest extends TestCase
|
||||
{
|
||||
public function testReturnsAllValuesWhenCurrentValueIsEmpty()
|
||||
{
|
||||
$values = ['apple', 'banana', 'cherry'];
|
||||
$provider = new ListCompletionProvider($values);
|
||||
$result = $provider->getCompletions('');
|
||||
|
||||
$this->assertSame($values, $result);
|
||||
}
|
||||
|
||||
public function testFiltersValuesBasedOnCurrentValuePrefix()
|
||||
{
|
||||
$values = ['apple', 'apricot', 'banana', 'cherry'];
|
||||
$provider = new ListCompletionProvider($values);
|
||||
$result = $provider->getCompletions('ap');
|
||||
|
||||
$this->assertSame(['apple', 'apricot'], $result);
|
||||
}
|
||||
|
||||
public function testReturnsEmptyArrayWhenNoValuesMatch()
|
||||
{
|
||||
$values = ['apple', 'banana', 'cherry'];
|
||||
$provider = new ListCompletionProvider($values);
|
||||
$result = $provider->getCompletions('xyz');
|
||||
|
||||
$this->assertSame([], $result);
|
||||
}
|
||||
|
||||
public function testWorksWithSingleCharacterPrefix()
|
||||
{
|
||||
$values = ['apple', 'banana', 'cherry'];
|
||||
$provider = new ListCompletionProvider($values);
|
||||
$result = $provider->getCompletions('a');
|
||||
|
||||
$this->assertSame(['apple'], $result);
|
||||
}
|
||||
|
||||
public function testIsCaseSensitiveByDefault()
|
||||
{
|
||||
$values = ['Apple', 'apple', 'APPLE'];
|
||||
$provider = new ListCompletionProvider($values);
|
||||
$result = $provider->getCompletions('A');
|
||||
|
||||
$this->assertEquals(['Apple', 'APPLE'], $result);
|
||||
}
|
||||
|
||||
public function testHandlesEmptyValuesArray()
|
||||
{
|
||||
$provider = new ListCompletionProvider([]);
|
||||
$result = $provider->getCompletions('test');
|
||||
|
||||
$this->assertSame([], $result);
|
||||
}
|
||||
|
||||
public function testPreservesArrayOrder()
|
||||
{
|
||||
$values = ['zebra', 'apple', 'banana'];
|
||||
$provider = new ListCompletionProvider($values);
|
||||
$result = $provider->getCompletions('');
|
||||
|
||||
$this->assertSame(['zebra', 'apple', 'banana'], $result);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue