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\Piece;
use App\Enum\ModelCategory;
use App\Tests\AbstractApiTestCase;
@@ -142,4 +143,48 @@ class PieceTest extends AbstractApiTestCase
$this->assertResponseStatusCodeSame(422);
}
public function testGetItemReturnsProductIds(): void
{
$product1 = $this->createProduct('Huile A', 'HUILE-A');
$product2 = $this->createProduct('Graisse B', 'GRAISSE-B');
$piece = $this->createPiece('Joint avec produits', 'REF-JP');
$piece->addProduct($product1);
$piece->addProduct($product2);
$em = $this->getEntityManager();
$em->persist($piece);
$em->flush();
$client = $this->createViewerClient();
$client->request('GET', self::iri('pieces', $piece->getId()));
$this->assertResponseIsSuccessful();
$data = $client->getResponse()->toArray();
$this->assertArrayHasKey('productIds', $data);
$this->assertCount(2, $data['productIds']);
$this->assertContains($product1->getId(), $data['productIds']);
$this->assertContains($product2->getId(), $data['productIds']);
}
public function testPieceProductRelationSurvivesRefetch(): void
{
$product = $this->createProduct('Huile', 'HUILE-REL');
$piece = $this->createPiece('Joint relation', 'REF-REL');
$piece->addProduct($product);
$em = $this->getEntityManager();
$em->persist($piece);
$em->flush();
$em->clear();
// Re-fetch the piece to verify relation persisted
$refetched = $em->find(Piece::class, $piece->getId());
$this->assertNotNull($refetched);
$this->assertCount(1, $refetched->getProducts());
$this->assertSame($product->getId(), $refetched->getProducts()->first()->getId());
$this->assertSame([$product->getId()], $refetched->getProductIds());
}
}