valide du ticket de pesee (ERP-193, spec-back ยง 2.14). * * Couvre : * - une pesee peut etre enregistree SANS contrepartie ni immatriculation : le POST * cree un BROUILLON (status DRAFT, pas de numero) ; * - la validation (PATCH /validate) exige les 3 champs du haut (type + champ * contrepartie + immatriculation) ET les 2 pesees (groupe `finalize`) ; * - une validation complete attribue le numero {siteCode}-TP-{NNNN} et passe le * ticket en VALIDATED. * * @internal */ final class WeighingTicketLifecycleTest extends AbstractWeighingTicketApiTestCase { public function testWeighingOnlyCreatesDraftWithoutNumber(): void { $http = $this->authManageOnSite($this->siteByCode('86')); // Pesee a vide seule : ni contrepartie, ni immatriculation. $body = $this->postTicket($http, [ 'emptyDate' => '2026-06-17T09:00:00+02:00', 'emptyWeight' => 7150, 'emptyMode' => 'AUTO', ])->toArray(); self::assertResponseStatusCodeSame(201); self::assertSame('DRAFT', $body['status']); self::assertArrayNotHasKey('number', $body, 'Un brouillon n\'a pas encore de numero (skip_null_values).'); self::assertSame(7150, $body['emptyWeight']); } public function testValidateRequiresCounterparty(): void { $http = $this->authManageOnSite($this->siteByCode('86')); // Brouillon complet cote pesees + immatriculation, mais SANS contrepartie. $id = (int) $this->postTicket($http, [ 'immatriculation' => 'AB-123-CD', 'emptyDate' => '2026-06-17T09:00:00+02:00', 'emptyWeight' => 7150, 'emptyMode' => 'AUTO', 'fullDate' => '2026-06-17T09:12:00+02:00', 'fullWeight' => 14300, 'fullMode' => 'AUTO', ])->toArray()['id']; $response = $this->validateTicket($http, $id); self::assertResponseStatusCodeSame(422); self::assertViolationOnPath($response, 'counterpartyType'); } public function testValidateRequiresBothWeighings(): void { $http = $this->authManageOnSite($this->siteByCode('86')); $client = $this->seedTestClient('Lifecycle'); // Brouillon avec contrepartie + immat + UNE seule pesee (a vide). $id = (int) $this->postTicket($http, [ 'counterpartyType' => 'CLIENT', 'client' => $this->clientIri($client), 'immatriculation' => 'AB-123-CD', 'emptyDate' => '2026-06-17T09:00:00+02:00', 'emptyWeight' => 7150, 'emptyMode' => 'AUTO', ])->toArray()['id']; $response = $this->validateTicket($http, $id); self::assertResponseStatusCodeSame(422); self::assertViolationOnPath($response, 'fullWeight'); } public function testValidateAssignsNumberAndStatus(): void { $http = $this->authManageOnSite($this->siteByCode('86')); $client = $this->seedTestClient('LifecycleOk'); $validated = $this->createValidatedTicket($http, $this->validClientTicketPayload($client)); self::assertSame('VALIDATED', $validated['status']); self::assertMatchesRegularExpression('/^86-TP-\d{4}$/', (string) $validated['number']); self::assertSame(7150, $validated['netWeight']); } }