From 34b0d9225c462e2b464c17b392ec18fde97ae306 Mon Sep 17 00:00:00 2001 From: Matthieu Date: Tue, 31 Mar 2026 14:30:46 +0200 Subject: [PATCH] test(constructeur) : update test helpers and MCP tests for ConstructeurLinks Co-Authored-By: Claude Opus 4.6 (1M context) --- tests/AbstractApiTestCase.php | 52 +++++++++++++++++++ .../Tool/Composant/ComposantsCrudToolTest.php | 4 +- .../Mcp/Tool/Machine/MachinesCrudToolTest.php | 4 +- tests/Mcp/Tool/Piece/PiecesCrudToolTest.php | 4 +- .../Mcp/Tool/Product/ProductsCrudToolTest.php | 4 +- 5 files changed, 56 insertions(+), 12 deletions(-) diff --git a/tests/AbstractApiTestCase.php b/tests/AbstractApiTestCase.php index 567290e..517ab94 100644 --- a/tests/AbstractApiTestCase.php +++ b/tests/AbstractApiTestCase.php @@ -10,17 +10,21 @@ use App\Entity\Composant; use App\Entity\ComposantPieceSlot; use App\Entity\ComposantProductSlot; use App\Entity\ComposantSubcomponentSlot; +use App\Entity\ComposantConstructeurLink; use App\Entity\Constructeur; use App\Entity\CustomField; use App\Entity\CustomFieldValue; use App\Entity\Machine; use App\Entity\MachineComponentLink; +use App\Entity\MachineConstructeurLink; use App\Entity\MachinePieceLink; use App\Entity\MachineProductLink; use App\Entity\ModelType; use App\Entity\Piece; +use App\Entity\PieceConstructeurLink; use App\Entity\PieceProductSlot; use App\Entity\Product; +use App\Entity\ProductConstructeurLink; use App\Entity\Profile; use App\Entity\Site; use App\Enum\ModelCategory; @@ -255,6 +259,54 @@ abstract class AbstractApiTestCase extends ApiTestCase return $c; } + protected function createMachineConstructeurLink(Machine $machine, Constructeur $constructeur, ?string $supplierReference = null): MachineConstructeurLink + { + $link = new MachineConstructeurLink(); + $link->setMachine($machine); + $link->setConstructeur($constructeur); + $link->setSupplierReference($supplierReference); + $this->getEntityManager()->persist($link); + $this->getEntityManager()->flush(); + + return $link; + } + + protected function createPieceConstructeurLink(Piece $piece, Constructeur $constructeur, ?string $supplierReference = null): PieceConstructeurLink + { + $link = new PieceConstructeurLink(); + $link->setPiece($piece); + $link->setConstructeur($constructeur); + $link->setSupplierReference($supplierReference); + $this->getEntityManager()->persist($link); + $this->getEntityManager()->flush(); + + return $link; + } + + protected function createComposantConstructeurLink(Composant $composant, Constructeur $constructeur, ?string $supplierReference = null): ComposantConstructeurLink + { + $link = new ComposantConstructeurLink(); + $link->setComposant($composant); + $link->setConstructeur($constructeur); + $link->setSupplierReference($supplierReference); + $this->getEntityManager()->persist($link); + $this->getEntityManager()->flush(); + + return $link; + } + + protected function createProductConstructeurLink(Product $product, Constructeur $constructeur, ?string $supplierReference = null): ProductConstructeurLink + { + $link = new ProductConstructeurLink(); + $link->setProduct($product); + $link->setConstructeur($constructeur); + $link->setSupplierReference($supplierReference); + $this->getEntityManager()->persist($link); + $this->getEntityManager()->flush(); + + return $link; + } + protected function createModelType( string $name = 'ModelType Test', string $code = 'MT-001', diff --git a/tests/Mcp/Tool/Composant/ComposantsCrudToolTest.php b/tests/Mcp/Tool/Composant/ComposantsCrudToolTest.php index 8effc57..7579a20 100644 --- a/tests/Mcp/Tool/Composant/ComposantsCrudToolTest.php +++ b/tests/Mcp/Tool/Composant/ComposantsCrudToolTest.php @@ -30,9 +30,7 @@ class ComposantsCrudToolTest extends AbstractApiTestCase $modelType = $this->createModelType(name: 'Type Composant', code: 'TC-001', category: ModelCategory::COMPONENT); $composant = $this->createComposant(name: 'Composant Gamma', type: $modelType); - // Add constructeur to composant - $composant->addConstructeur($constructeur); - $this->getEntityManager()->flush(); + $this->createComposantConstructeurLink($composant, $constructeur); $session = $this->createMcpClient('ROLE_VIEWER'); diff --git a/tests/Mcp/Tool/Machine/MachinesCrudToolTest.php b/tests/Mcp/Tool/Machine/MachinesCrudToolTest.php index 84fa134..eff9565 100644 --- a/tests/Mcp/Tool/Machine/MachinesCrudToolTest.php +++ b/tests/Mcp/Tool/Machine/MachinesCrudToolTest.php @@ -30,9 +30,7 @@ class MachinesCrudToolTest extends AbstractApiTestCase $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(); + $this->createMachineConstructeurLink($machine, $constructeur); $session = $this->createMcpClient('ROLE_VIEWER'); diff --git a/tests/Mcp/Tool/Piece/PiecesCrudToolTest.php b/tests/Mcp/Tool/Piece/PiecesCrudToolTest.php index 8483c3b..129a20f 100644 --- a/tests/Mcp/Tool/Piece/PiecesCrudToolTest.php +++ b/tests/Mcp/Tool/Piece/PiecesCrudToolTest.php @@ -30,9 +30,7 @@ class PiecesCrudToolTest extends AbstractApiTestCase $modelType = $this->createModelType(name: 'Type Piece', code: 'TP-001', category: ModelCategory::PIECE); $piece = $this->createPiece(name: 'Piece Gamma', reference: 'REF-001', type: $modelType); - // Add constructeur to piece - $piece->addConstructeur($constructeur); - $this->getEntityManager()->flush(); + $this->createPieceConstructeurLink($piece, $constructeur); $session = $this->createMcpClient('ROLE_VIEWER'); diff --git a/tests/Mcp/Tool/Product/ProductsCrudToolTest.php b/tests/Mcp/Tool/Product/ProductsCrudToolTest.php index a0593db..d61b2f6 100644 --- a/tests/Mcp/Tool/Product/ProductsCrudToolTest.php +++ b/tests/Mcp/Tool/Product/ProductsCrudToolTest.php @@ -30,9 +30,7 @@ class ProductsCrudToolTest extends AbstractApiTestCase $modelType = $this->createModelType(name: 'Type Produit', code: 'TP-001', category: ModelCategory::PRODUCT); $product = $this->createProduct(name: 'Product Gamma', reference: 'REF-001', type: $modelType); - // Add constructeur to product - $product->addConstructeur($constructeur); - $this->getEntityManager()->flush(); + $this->createProductConstructeurLink($product, $constructeur); $session = $this->createMcpClient('ROLE_VIEWER');