422 (Assert\NotBlank) sur `numero` ; * - relation nulle (site / storageType) -> 422 (Assert\NotNull, via le chemin de * denormalisation `collectDenormalizationErrors`) portant le bon propertyPath, et * NON un 400 qui court-circuiterait le mapping inline front (useFormErrors, * ERP-101). * * Pendant ces RG, le contrat de violation 422 (propertyPath aligne sur le champ * front) est ce que le front consomme : on l'asserte explicitement. * * @internal */ final class StorageWriteValidationTest extends AbstractStorageApiTestCase { public function testNumeroIsTrimmedServerSide(): void { $client = $this->createAdminClient(); // RG-7.06 : numero saisi avec des espaces autour -> stocke trimme. $created = $client->request('POST', '/api/storages', [ 'headers' => ['Content-Type' => self::LD], 'json' => $this->validStoragePayload(['numero' => ' A1 ']), ])->toArray(); self::assertResponseStatusCodeSame(201); self::assertSame('A1', $created['numero'], 'Le numero doit etre trimme cote serveur (RG-7.06).'); // Relecture : la normalisation est bien persistee, pas seulement reflechie. $detail = $client->request('GET', '/api/storages/'.$created['id'], [ 'headers' => ['Accept' => self::LD], ])->toArray(); self::assertSame('A1', $detail['numero']); } public function testBlankNumeroIsRejected(): void { $client = $this->createAdminClient(); $response = $client->request('POST', '/api/storages', [ 'headers' => ['Content-Type' => self::LD], 'json' => $this->validStoragePayload(['numero' => ' ']), ]); self::assertResponseStatusCodeSame(422); self::assertContains('numero', $this->violationPaths($response)); } public function testNullSiteReturns422WithPropertyPath(): void { $client = $this->createAdminClient(); // Relation obligatoire a null : doit ressortir en 422 (NotNull) avec un // propertyPath `site`, pas en 400 (collectDenormalizationErrors). $response = $client->request('POST', '/api/storages', [ 'headers' => ['Content-Type' => self::LD], 'json' => $this->validStoragePayload(['site' => null]), ]); self::assertResponseStatusCodeSame(422); self::assertContains('site', $this->violationPaths($response)); } public function testNullStorageTypeReturns422WithPropertyPath(): void { $client = $this->createAdminClient(); $response = $client->request('POST', '/api/storages', [ 'headers' => ['Content-Type' => self::LD], 'json' => $this->validStoragePayload(['storageType' => null]), ]); self::assertResponseStatusCodeSame(422); self::assertContains('storageType', $this->violationPaths($response)); } }