Add happy cases for functional tests of example 1 (#91)
This commit is contained in:
parent
4486776e7d
commit
9ff6516e5b
4 changed files with 64 additions and 13 deletions
|
|
@ -19,20 +19,42 @@ abstract class InspectorSnapshotTestCase extends TestCase
|
||||||
{
|
{
|
||||||
private const INSPECTOR_VERSION = '0.16.8';
|
private const INSPECTOR_VERSION = '0.16.8';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array<string, mixed> $toolArgs
|
||||||
|
*/
|
||||||
#[DataProvider('provideMethods')]
|
#[DataProvider('provideMethods')]
|
||||||
public function testResourcesListOutputMatchesSnapshot(string $method): void
|
public function testMethodOutputMatchesSnapshot(
|
||||||
{
|
string $method,
|
||||||
$process = (new Process([
|
?string $toolName = null,
|
||||||
'npx',
|
array $toolArgs = [],
|
||||||
\sprintf('@modelcontextprotocol/inspector@%s', self::INSPECTOR_VERSION),
|
?string $uri = null,
|
||||||
'--cli',
|
): void {
|
||||||
'php',
|
$inspector = \sprintf('@modelcontextprotocol/inspector@%s', self::INSPECTOR_VERSION);
|
||||||
$this->getServerScript(),
|
$args = [
|
||||||
'--method',
|
'npx', $inspector, '--cli', 'php', $this->getServerScript(), '--method', $method,
|
||||||
$method,
|
];
|
||||||
]))->mustRun();
|
|
||||||
|
// Options for tools/call
|
||||||
|
if (null !== $toolName) {
|
||||||
|
$args[] = '--tool-name';
|
||||||
|
$args[] = $toolName;
|
||||||
|
|
||||||
|
foreach ($toolArgs as $key => $value) {
|
||||||
|
$args[] = '--tool-arg';
|
||||||
|
$args[] = \sprintf('%s=%s', $key, $value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Options for resources/read
|
||||||
|
if (null !== $uri) {
|
||||||
|
$args[] = '--uri';
|
||||||
|
$args[] = $uri;
|
||||||
|
}
|
||||||
|
|
||||||
|
$output = (new Process($args))
|
||||||
|
->mustRun()
|
||||||
|
->getOutput();
|
||||||
|
|
||||||
$output = $process->getOutput();
|
|
||||||
$snapshotFile = $this->getSnapshotFilePath($method);
|
$snapshotFile = $this->getSnapshotFilePath($method);
|
||||||
|
|
||||||
if (!file_exists($snapshotFile)) {
|
if (!file_exists($snapshotFile)) {
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,17 @@ final class StdioCalculatorExampleTest extends InspectorSnapshotTestCase
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
...parent::provideListMethods(),
|
...parent::provideListMethods(),
|
||||||
|
'Calculate Sum' => [
|
||||||
|
'method' => 'tools/call',
|
||||||
|
'toolName' => 'calculate',
|
||||||
|
'toolArgs' => ['a' => 12.5, 'b' => 7.3, 'operation' => 'add'],
|
||||||
|
],
|
||||||
|
'Read Config' => [
|
||||||
|
'method' => 'resources/read',
|
||||||
|
'toolName' => null, // can be removed with newer PHPUnit versions
|
||||||
|
'toolArgs' => [], // can be removed with newer PHPUnit versions
|
||||||
|
'uri' => 'config://calculator/settings',
|
||||||
|
],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,9 @@
|
||||||
|
{
|
||||||
|
"contents": [
|
||||||
|
{
|
||||||
|
"uri": "config://calculator/settings",
|
||||||
|
"mimeType": "application/json",
|
||||||
|
"text": "{\n \"precision\": 2,\n \"allow_negative\": true\n}"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,9 @@
|
||||||
|
{
|
||||||
|
"content": [
|
||||||
|
{
|
||||||
|
"type": "text",
|
||||||
|
"text": "19.8"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"isError": false
|
||||||
|
}
|
||||||
Loading…
Reference in a new issue