Skip to content

Commit 276d09d

Browse files
committed
Add happy cases for functional tests of example 1
1 parent 41486bf commit 276d09d

File tree

4 files changed

+62
-6
lines changed

4 files changed

+62
-6
lines changed

tests/Inspector/InspectorSnapshotTestCase.php

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,41 @@
1717

1818
abstract class InspectorSnapshotTestCase extends TestCase
1919
{
20+
/**
21+
* @param array<string, mixed> $toolArgs
22+
*/
2023
#[DataProvider('provideMethods')]
21-
public function testResourcesListOutputMatchesSnapshot(string $method): void
22-
{
23-
$process = Process::fromShellCommandline(
24-
\sprintf('npx @modelcontextprotocol/inspector --cli php %s --method %s', $this->getServerScript(), $method)
25-
)->mustRun();
24+
public function testResourcesListOutputMatchesSnapshot(
25+
string $method,
26+
?string $toolName = null,
27+
array $toolArgs = [],
28+
?string $uri = null,
29+
): void {
30+
$args = [
31+
'npx', '@modelcontextprotocol/inspector', '--cli', 'php', $this->getServerScript(), '--method', $method,
32+
];
33+
34+
// Options for tools/call
35+
if (null !== $toolName) {
36+
$args[] = '--tool-name';
37+
$args[] = $toolName;
38+
39+
foreach ($toolArgs as $key => $value) {
40+
$args[] = '--tool-arg';
41+
$args[] = \sprintf('%s=%s', $key, $value);
42+
}
43+
}
44+
45+
// Options for resources/read
46+
if (null !== $uri) {
47+
$args[] = '--uri';
48+
$args[] = $uri;
49+
}
50+
51+
$output = (new Process($args))
52+
->mustRun()
53+
->getOutput();
2654

27-
$output = $process->getOutput();
2855
$snapshotFile = $this->getSnapshotFilePath($method);
2956

3057
if (!file_exists($snapshotFile)) {

tests/Inspector/StdioCalculatorExampleTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,17 @@ public static function provideMethods(): array
1717
{
1818
return [
1919
...parent::provideListMethods(),
20+
'Calculate Sum' => [
21+
'method' => 'tools/call',
22+
'toolName' => 'calculate',
23+
'toolArgs' => ['a' => 12.5, 'b' => 7.3, 'operation' => 'add'],
24+
],
25+
'Read Config' => [
26+
'method' => 'resources/read',
27+
'toolName' => null, // can be removed with newer PHPUnit versions
28+
'toolArgs' => [], // can be removed with newer PHPUnit versions
29+
'uri' => 'config://calculator/settings',
30+
],
2031
];
2132
}
2233

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"contents": [
3+
{
4+
"uri": "config://calculator/settings",
5+
"mimeType": "application/json",
6+
"text": "{\n \"precision\": 2,\n \"allow_negative\": true\n}"
7+
}
8+
]
9+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"content": [
3+
{
4+
"type": "text",
5+
"text": "19.8"
6+
}
7+
],
8+
"isError": false
9+
}

0 commit comments

Comments
 (0)