. */ namespace App\Tests\Validator\Constraints; use App\Entity\Parts\Part; use App\Entity\Parts\PartLot; use App\Entity\Parts\StorageLocation; use App\Validator\Constraints\ValidPartLot; use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; use Symfony\Component\Validator\Validator\ValidatorInterface; final class ValidPartLotValidatorTest extends WebTestCase { private static ValidatorInterface $validator; public static function setUpBeforeClass(): void { self::bootKernel(); self::$validator = self::getContainer()->get('validator'); } public function testPartLotWithoutStorageLocationIsValid(): void { $lot = new PartLot(); $lot->setPart(new Part()); // No storage location set → validation should pass without any location checks $violations = self::$validator->validate($lot, new ValidPartLot()); $this->assertCount(0, $violations); } public function testPartLotWithNonFullNonRestrictedStorageLocationIsValid(): void { $lot = new PartLot(); $lot->setPart(new Part()); $location = new StorageLocation(); // Default: not full, not limited — should be valid $lot->setStorageLocation($location); $violations = self::$validator->validate($lot, new ValidPartLot()); $this->assertCount(0, $violations); } public function testPartLotWithFullLocationAndNewLotRaisesViolation(): void { $lot = new PartLot(); $lot->setPart(new Part()); $location = new StorageLocation(); $location->setIsFull(true); $lot->setStorageLocation($location); // The lot has no ID (new entity), so "parts" is empty, and a full location will reject it $violations = self::$validator->validate($lot, new ValidPartLot()); // Should raise a violation because the location is full and the part is not in the existing parts list $this->assertGreaterThan(0, count($violations)); } public function testNonPartLotValueThrowsException(): void { $this->expectException(\Symfony\Component\Form\Exception\UnexpectedTypeException::class); self::$validator->validate('not a part lot', new ValidPartLot()); } }