- 5 tools each: list, get, create, update, delete - McpToolHelper extracted to AbstractApiTestCase for reuse - DashboardStatsToolTest simplified to use base helpers - 22 MCP tests pass Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
86 lines
2.8 KiB
PHP
86 lines
2.8 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Tests\Mcp\Tool\Constructeur;
|
|
|
|
use App\Tests\AbstractApiTestCase;
|
|
|
|
/**
|
|
* @internal
|
|
*/
|
|
class ConstructeursCrudToolTest extends AbstractApiTestCase
|
|
{
|
|
public function testListConstructeurs(): void
|
|
{
|
|
$this->createConstructeur(name: 'Constructeur Alpha');
|
|
$this->createConstructeur(name: 'Constructeur Beta');
|
|
$session = $this->createMcpClient('ROLE_VIEWER');
|
|
|
|
$data = $this->callMcpTool($session, 'list_constructeurs');
|
|
|
|
$this->assertArrayHasKey('_parsed', $data, 'MCP response: '.json_encode($data));
|
|
$this->assertGreaterThanOrEqual(2, $data['_parsed']['total']);
|
|
}
|
|
|
|
public function testGetConstructeur(): void
|
|
{
|
|
$constructeur = $this->createConstructeur(name: 'Constructeur Gamma');
|
|
$session = $this->createMcpClient('ROLE_VIEWER');
|
|
|
|
$data = $this->callMcpTool($session, 'get_constructeur', ['constructeurId' => $constructeur->getId()]);
|
|
|
|
$this->assertArrayHasKey('_parsed', $data);
|
|
$this->assertSame('Constructeur Gamma', $data['_parsed']['name']);
|
|
}
|
|
|
|
public function testCreateConstructeur(): void
|
|
{
|
|
$session = $this->createMcpClient('ROLE_GESTIONNAIRE');
|
|
|
|
$data = $this->callMcpTool($session, 'create_constructeur', [
|
|
'name' => 'Constructeur Nouveau',
|
|
'email' => 'contact@nouveau.com',
|
|
'phone' => '+33123456789',
|
|
]);
|
|
|
|
$this->assertArrayHasKey('_parsed', $data);
|
|
$this->assertSame('Constructeur Nouveau', $data['_parsed']['name']);
|
|
$this->assertNotEmpty($data['_parsed']['id']);
|
|
}
|
|
|
|
public function testCreateConstructeurRequiresGestionnaire(): void
|
|
{
|
|
$session = $this->createMcpClient('ROLE_VIEWER');
|
|
|
|
$data = $this->callMcpTool($session, 'create_constructeur', ['name' => 'Forbidden']);
|
|
|
|
$this->assertArrayHasKey('error', $data, 'Should fail with VIEWER role');
|
|
}
|
|
|
|
public function testUpdateConstructeur(): void
|
|
{
|
|
$constructeur = $this->createConstructeur(name: 'Old Name');
|
|
$session = $this->createMcpClient('ROLE_GESTIONNAIRE');
|
|
|
|
$data = $this->callMcpTool($session, 'update_constructeur', [
|
|
'constructeurId' => $constructeur->getId(),
|
|
'name' => 'New Name',
|
|
]);
|
|
|
|
$this->assertArrayHasKey('_parsed', $data);
|
|
$this->assertSame('New Name', $data['_parsed']['name']);
|
|
}
|
|
|
|
public function testDeleteConstructeur(): void
|
|
{
|
|
$constructeur = $this->createConstructeur(name: 'To Delete');
|
|
$session = $this->createMcpClient('ROLE_GESTIONNAIRE');
|
|
|
|
$data = $this->callMcpTool($session, 'delete_constructeur', ['constructeurId' => $constructeur->getId()]);
|
|
|
|
$this->assertArrayHasKey('_parsed', $data);
|
|
$this->assertTrue($data['_parsed']['deleted']);
|
|
}
|
|
}
|