feat(mcp) : add CRUD tools for Pieces, Composants, Machines
- 5 tools each: list, get, create, update, delete - Piece: includes typePiece, constructeurs, prix (string) - Composant: includes typeComposant, constructeurs, prix (string) - Machine: includes site (required), constructeurs - 40 MCP tests pass total Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
107
tests/Mcp/Tool/Machine/MachinesCrudToolTest.php
Normal file
107
tests/Mcp/Tool/Machine/MachinesCrudToolTest.php
Normal file
@@ -0,0 +1,107 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Tests\Mcp\Tool\Machine;
|
||||
|
||||
use App\Tests\AbstractApiTestCase;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
class MachinesCrudToolTest extends AbstractApiTestCase
|
||||
{
|
||||
public function testListMachines(): void
|
||||
{
|
||||
$site = $this->createSite(name: 'Site Usine');
|
||||
$this->createMachine(name: 'Machine Alpha', site: $site);
|
||||
$this->createMachine(name: 'Machine Beta', site: $site);
|
||||
$session = $this->createMcpClient('ROLE_VIEWER');
|
||||
|
||||
$data = $this->callMcpTool($session, 'list_machines');
|
||||
|
||||
$this->assertArrayHasKey('_parsed', $data);
|
||||
$this->assertGreaterThanOrEqual(2, $data['_parsed']['total']);
|
||||
}
|
||||
|
||||
public function testGetMachine(): void
|
||||
{
|
||||
$site = $this->createSite(name: 'Site Principal');
|
||||
$constructeur = $this->createConstructeur(name: 'Fournisseur M');
|
||||
$machine = $this->createMachine(name: 'Machine Gamma', site: $site, reference: 'REF-M001');
|
||||
|
||||
// Add constructeur to machine
|
||||
$machine->addConstructeur($constructeur);
|
||||
$this->getEntityManager()->flush();
|
||||
|
||||
$session = $this->createMcpClient('ROLE_VIEWER');
|
||||
|
||||
$data = $this->callMcpTool($session, 'get_machine', ['machineId' => $machine->getId()]);
|
||||
|
||||
$this->assertArrayHasKey('_parsed', $data);
|
||||
$this->assertSame('Machine Gamma', $data['_parsed']['name']);
|
||||
$this->assertSame('REF-M001', $data['_parsed']['reference']);
|
||||
$this->assertNotNull($data['_parsed']['site']);
|
||||
$this->assertSame('Site Principal', $data['_parsed']['site']['name']);
|
||||
$this->assertCount(1, $data['_parsed']['constructeurs']);
|
||||
$this->assertSame('Fournisseur M', $data['_parsed']['constructeurs'][0]['name']);
|
||||
}
|
||||
|
||||
public function testCreateMachine(): void
|
||||
{
|
||||
$site = $this->createSite(name: 'Site Création');
|
||||
$session = $this->createMcpClient('ROLE_GESTIONNAIRE');
|
||||
|
||||
$data = $this->callMcpTool($session, 'create_machine', [
|
||||
'name' => 'Machine Nouvelle',
|
||||
'siteId' => $site->getId(),
|
||||
'reference' => 'REF-NEW',
|
||||
'prix' => '42.99',
|
||||
]);
|
||||
|
||||
$this->assertArrayHasKey('_parsed', $data);
|
||||
$this->assertSame('Machine Nouvelle', $data['_parsed']['name']);
|
||||
$this->assertNotEmpty($data['_parsed']['id']);
|
||||
}
|
||||
|
||||
public function testCreateMachineRequiresGestionnaire(): void
|
||||
{
|
||||
$site = $this->createSite(name: 'Site Forbidden');
|
||||
$session = $this->createMcpClient('ROLE_VIEWER');
|
||||
|
||||
$data = $this->callMcpTool($session, 'create_machine', [
|
||||
'name' => 'Forbidden',
|
||||
'siteId' => $site->getId(),
|
||||
]);
|
||||
|
||||
$this->assertArrayHasKey('error', $data, 'Should fail with VIEWER role');
|
||||
}
|
||||
|
||||
public function testUpdateMachine(): void
|
||||
{
|
||||
$site = $this->createSite(name: 'Site Update');
|
||||
$machine = $this->createMachine(name: 'Old Machine', site: $site);
|
||||
$session = $this->createMcpClient('ROLE_GESTIONNAIRE');
|
||||
|
||||
$data = $this->callMcpTool($session, 'update_machine', [
|
||||
'machineId' => $machine->getId(),
|
||||
'name' => 'Updated Machine',
|
||||
'prix' => '99.00',
|
||||
]);
|
||||
|
||||
$this->assertArrayHasKey('_parsed', $data);
|
||||
$this->assertSame('Updated Machine', $data['_parsed']['name']);
|
||||
}
|
||||
|
||||
public function testDeleteMachine(): void
|
||||
{
|
||||
$site = $this->createSite(name: 'Site Delete');
|
||||
$machine = $this->createMachine(name: 'To Delete', site: $site);
|
||||
$session = $this->createMcpClient('ROLE_GESTIONNAIRE');
|
||||
|
||||
$data = $this->callMcpTool($session, 'delete_machine', ['machineId' => $machine->getId()]);
|
||||
|
||||
$this->assertArrayHasKey('_parsed', $data);
|
||||
$this->assertTrue($data['_parsed']['deleted']);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user