Add happy cases for functional tests of example 1 (#91)

This commit is contained in:
Christopher Hertel 2025-10-12 14:52:58 +02:00 • committed by GitHub
commit 9ff6516e5b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -19,20 +19,42 @@ abstract class InspectorSnapshotTestCase extends TestCase
{
private const INSPECTOR_VERSION = '0.16.8';
/**
* @param array<string, mixed> $toolArgs
*/
#[DataProvider('provideMethods')]
public function testResourcesListOutputMatchesSnapshot(string $method): void
{
$process = (new Process([
'npx',
\sprintf('@modelcontextprotocol/inspector@%s', self::INSPECTOR_VERSION),
'--cli',
'php',
$this->getServerScript(),
'--method',
$method,
]))->mustRun();
public function testMethodOutputMatchesSnapshot(
string $method,
?string $toolName = null,
array $toolArgs = [],
?string $uri = null,
): void {
$inspector = \sprintf('@modelcontextprotocol/inspector@%s', self::INSPECTOR_VERSION);
$args = [
'npx', $inspector, '--cli', 'php', $this->getServerScript(), '--method', $method,
];
// 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);
if (!file_exists($snapshotFile)) {