winzik/skeleton-plugin/tests/TodoPluginTest.php
David Nurdin d64b0ac193 JumPHP IDE 0.1.26: plugins give Claude tools (the IDE's MCP server)
- Api::mcpTool($name, $description, fn (array $args), $properties, $required): offered on jumphp-ide beside the
  IDE's own tools as plugin_<id>_<name> (mcp__jumphp-ide__plugin_<id>_<name>), run in PHP (not in the interface),
  a string / array / MCP result / Deferred; an exception is the tool's error; gone when the plugin is disabled
- McpServer: its tools may come from a closure (asked at each tools/list); IdeAgent::setExtraTools()
- PluginTestCase: mcp(), mcpTools(); hello-plugin / skeleton-plugin: list_todos and its test
- the Plugins window lists each plugin's tools for Claude; Claude's instructions name them
- docs/ide-plugins.md (Tools for Claude), docs/ide.md, docs/ide.fr.md, AGENTS.md §19

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01X3cUrpEPheHAT512jkSvAK
2026-11-03 00:01:37 +01:00

76 lines
3.2 KiB
PHP

<?php
namespace JumphpPlugins\SkeletonPlugin\Tests;
use JumPHP\Ide\Testing\PluginTestCase;
final class TodoPluginTest extends PluginTestCase
{
public function testTheToolWindowListsTheTodosOfTheProject(): void
{
$this->project([
'src/Hero.php' => "<?php\n// TODO: jump higher\nclass Hero {}\n",
'README.md' => "# Game\n<!-- FIXME: the title -->\n",
]);
$text = $this->toolText('todos');
self::assertStringContainsString('TODO: jump higher', $text);
self::assertStringContainsString('FIXME: the title', $text);
self::assertStringContainsString('2 of 2', $text);
}
public function testAClickOpensTheLine(): void
{
$this->project(['src/Hero.php' => "<?php\n\n// TODO: jump higher\n"]);
$this->click('todos', 'jump higher');
self::assertSame(['path' => 'src/Hero.php', 'line' => 3], $this->opened());
}
public function testTheFilterAndTheFixmeOnlyBox(): void
{
$this->project(['a.php' => "<?php\n// TODO: sound\n// FIXME: crash\n// TODO: music\n"]);
self::assertStringContainsString('1 of 3', implode(' ', array_column($this->submit('todos', 'Filter', 'music')['children'], 'text')));
$this->submit('todos', 'Filter', '');
$this->click('todos', 'FIXME only');
$text = $this->toolText('todos');
self::assertStringContainsString('FIXME: crash', $text);
self::assertStringNotContainsString('sound', $text);
}
public function testASavedFileUpdatesTheList(): void
{
$this->project(['a.php' => "<?php\n"]);
self::assertStringContainsString('No TODO in the project', $this->toolText('todos'));
$this->save('a.php', "<?php\n// TODO: new one\n");
self::assertStringContainsString('new one', $this->toolText('todos'));
}
public function testTheActionCountsTheTodosOfTheFile(): void
{
$this->project(['a.php' => "<?php\n// TODO: one\n// FIXME: two\n"]);
$this->action('count', 'a.php');
self::assertSame(['2 TODO / FIXME in a.php.'], $this->notifications());
}
public function testAFixmeIsAWarningWhileOneTypes(): void
{
$problems = $this->problems('a.php', "<?php\n\n // FIXME: leaks\n");
self::assertCount(1, $problems);
self::assertSame(3, $problems[0]['startLine']);
self::assertSame('FIXME: leaks', $problems[0]['message']);
}
public function testTodoIsCompletedInAComment(): void
{
self::assertSame(['@todo'], $this->complete('a.php', "<?php\n// @to|"));
self::assertSame([], $this->complete('a.php', "<?php\n\$x = |"));
}
public function testClaudeListsTheTodosThroughTheIdesMcpServer(): void
{
$this->project(['src/A.php' => "<?php\n// TODO: sound\n// FIXME: crash\n", 'docs/b.md' => "<!-- TODO: write -->\n"]);
self::assertContains('plugin_' . str_replace('-', '_', basename($this->pluginDir())) . '_list_todos', $this->mcpTools());
self::assertCount(3, $this->mcp('list_todos'));
self::assertSame([['path' => 'src/A.php', 'line' => 3, 'tag' => 'FIXME', 'text' => 'crash']], $this->mcp('list_todos', ['fixme_only' => true]));
self::assertSame(['write'], array_column($this->mcp('list_todos', ['path' => 'docs']), 'text'));
}
}