Skip to content

Commit 605450f

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

File tree

4 files changed

+59
-6
lines changed

4 files changed

+59
-6
lines changed

tests/Inspector/InspectorSnapshotTestCase.php

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,37 @@
1818
abstract class InspectorSnapshotTestCase extends TestCase
1919
{
2020
#[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();
21+
public function testResourcesListOutputMatchesSnapshot(
22+
string $method,
23+
?string $toolName = null,
24+
array $toolArgs = [],
25+
?string $uri = null,
26+
): void {
27+
$args = [
28+
'npx', '@modelcontextprotocol/inspector', '--cli', 'php', $this->getServerScript(), '--method', $method,
29+
];
30+
31+
// Options for tools/call
32+
if (null !== $toolName) {
33+
$args[] = '--tool-name';
34+
$args[] = $toolName;
35+
36+
foreach ($toolArgs as $key => $value) {
37+
$args[] = '--tool-arg';
38+
$args[] = \sprintf('%s=%s', $key, $value);
39+
}
40+
}
41+
42+
// Options for resources/read
43+
if (null !== $uri) {
44+
$args[] = '--uri';
45+
$args[] = $uri;
46+
}
47+
48+
$output = (new Process($args))
49+
->mustRun()
50+
->getOutput();
2651

27-
$output = $process->getOutput();
2852
$snapshotFile = $this->getSnapshotFilePath($method);
2953

3054
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)