test(normalization) : add tests for skeleton requirements, composant slots, piece-product relation

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Matthieu
2026-03-13 08:25:00 +01:00
parent a6139d7090
commit 55bed90ac7
5 changed files with 502 additions and 0 deletions

View File

@@ -4,6 +4,7 @@ declare(strict_types=1);
namespace App\Tests\Api\Entity;
use App\Entity\Composant;
use App\Enum\ModelCategory;
use App\Tests\AbstractApiTestCase;
@@ -135,4 +136,82 @@ class ComposantTest extends AbstractApiTestCase
$this->assertResponseIsSuccessful();
$this->assertJsonContains(['totalItems' => 1]);
}
public function testComposantPieceSlotsPersistedAndReadable(): void
{
$pieceType = $this->createModelType('Joint', 'JOINT-CSLOT', ModelCategory::PIECE);
$piece = $this->createPiece('Joint slot', 'REF-CSLOT', $pieceType);
$composant = $this->createComposant('Composant slots pièces');
$this->createComposantPieceSlot($composant, $pieceType, $piece, 3, 0);
$em = $this->getEntityManager();
$em->clear();
$refetched = $em->find(Composant::class, $composant->getId());
$this->assertNotNull($refetched);
$this->assertCount(1, $refetched->getPieceSlots());
$slot = $refetched->getPieceSlots()->first();
$this->assertSame($pieceType->getId(), $slot->getTypePiece()->getId());
$this->assertSame($piece->getId(), $slot->getSelectedPiece()->getId());
$this->assertSame(3, $slot->getQuantity());
$this->assertSame(0, $slot->getPosition());
}
public function testComposantSubcomponentSlotsPersistedAndReadable(): void
{
$subType = $this->createModelType('Sous-pompe', 'SP-001', ModelCategory::COMPONENT);
$subComposant = $this->createComposant('Sous-composant');
$composant = $this->createComposant('Composant parent');
$this->createComposantSubcomponentSlot($composant, 'Sous-pompe A', 'SP-FAM', $subType, $subComposant, 0);
$em = $this->getEntityManager();
$em->clear();
$refetched = $em->find(Composant::class, $composant->getId());
$this->assertNotNull($refetched);
$this->assertCount(1, $refetched->getSubcomponentSlots());
$slot = $refetched->getSubcomponentSlots()->first();
$this->assertSame('Sous-pompe A', $slot->getAlias());
$this->assertSame('SP-FAM', $slot->getFamilyCode());
$this->assertSame($subType->getId(), $slot->getTypeComposant()->getId());
$this->assertSame($subComposant->getId(), $slot->getSelectedComposant()->getId());
}
public function testComposantProductSlotsPersistedAndReadable(): void
{
$productType = $this->createModelType('Huile', 'HUILE-CSLOT', ModelCategory::PRODUCT);
$product = $this->createProduct('Huile slot', 'REF-HSLOT', $productType);
$composant = $this->createComposant('Composant slots produits');
$this->createComposantProductSlot($composant, $productType, $product, 'LUB', 0);
$em = $this->getEntityManager();
$em->clear();
$refetched = $em->find(Composant::class, $composant->getId());
$this->assertNotNull($refetched);
$this->assertCount(1, $refetched->getProductSlots());
$slot = $refetched->getProductSlots()->first();
$this->assertSame($productType->getId(), $slot->getTypeProduct()->getId());
$this->assertSame($product->getId(), $slot->getSelectedProduct()->getId());
$this->assertSame('LUB', $slot->getFamilyCode());
}
public function testComposantDeleteCascadesSlots(): void
{
$composant = $this->createComposant('Composant cascade');
$this->createComposantPieceSlot($composant);
$this->createComposantProductSlot($composant);
$this->createComposantSubcomponentSlot($composant, 'Sub', 'FAM');
$client = $this->createGestionnaireClient();
$client->request('DELETE', self::iri('composants', $composant->getId()));
$this->assertResponseStatusCodeSame(204);
}
}