|
| 1 | +<?php |
| 2 | + |
| 3 | +/* |
| 4 | + * This file is part of the official PHP MCP SDK. |
| 5 | + * |
| 6 | + * A collaboration between Symfony and the PHP Foundation. |
| 7 | + * |
| 8 | + * For the full copyright and license information, please view the LICENSE |
| 9 | + * file that was distributed with this source code. |
| 10 | + */ |
| 11 | + |
| 12 | +namespace Mcp\Tests\Integration; |
| 13 | + |
| 14 | +use Mcp\Schema\PromptReference; |
| 15 | +use PHPUnit\Framework\Attributes\TestDox; |
| 16 | + |
| 17 | +/** |
| 18 | + * Argument completion driven by a `#[CompletionProvider(provider: …)]` class-string. |
| 19 | + * |
| 20 | + * The fixture's provider only exists in the container, so completions coming |
| 21 | + * back at all is what proves the attribute reached the registry and the |
| 22 | + * container was asked to build it. |
| 23 | + * |
| 24 | + * @see Fixture/completion.php for the server under test |
| 25 | + */ |
| 26 | +final class CompletionTest extends IntegrationTestCase |
| 27 | +{ |
| 28 | + #[TestDox('a class-string provider completes from the container-built instance')] |
| 29 | + public function testClassStringProviderCompletesFromTheContainer(): void |
| 30 | + { |
| 31 | + $client = $this->connect('completion'); |
| 32 | + |
| 33 | + $result = $client->complete(new PromptReference('book_seat'), ['name' => 'seat', 'value' => '12']); |
| 34 | + |
| 35 | + $this->assertSame(['12A', '12B'], $result->values); |
| 36 | + } |
| 37 | + |
| 38 | + #[TestDox('an empty value offers every completion the provider knows')] |
| 39 | + public function testEmptyValueOffersEveryCompletion(): void |
| 40 | + { |
| 41 | + $client = $this->connect('completion'); |
| 42 | + |
| 43 | + $result = $client->complete(new PromptReference('book_seat'), ['name' => 'seat', 'value' => '']); |
| 44 | + |
| 45 | + $this->assertSame(['12A', '12B', '14C'], $result->values); |
| 46 | + } |
| 47 | + |
| 48 | + #[TestDox('an argument the prompt does not declare completes to nothing')] |
| 49 | + public function testUnknownArgumentCompletesToNothing(): void |
| 50 | + { |
| 51 | + $client = $this->connect('completion'); |
| 52 | + |
| 53 | + $result = $client->complete(new PromptReference('book_seat'), ['name' => 'unknown', 'value' => '1']); |
| 54 | + |
| 55 | + $this->assertSame([], $result->values); |
| 56 | + } |
| 57 | +} |
0 commit comments