From 971e16012089628577c645477f0fcda6477a0aae Mon Sep 17 00:00:00 2001 From: tristan Date: Wed, 22 Apr 2026 14:53:27 +0200 Subject: [PATCH] =?UTF-8?q?feat=20:=20DTO=20et=20mapper=20de=20r=C3=A9pons?= =?UTF-8?q?e=20pour=20IpBCreateEntree?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 4.7 (1M context) --- src/Bovin/Dto/CreateEntreeResponseDto.php | 26 +++++++ .../Mapper/CreateEntreeResponseMapper.php | 56 +++++++++++++++ .../Mapper/CreateEntreeResponseMapperTest.php | 68 +++++++++++++++++++ 3 files changed, 150 insertions(+) create mode 100644 src/Bovin/Dto/CreateEntreeResponseDto.php create mode 100644 src/Bovin/Mapper/CreateEntreeResponseMapper.php create mode 100644 tests/Unit/Bovin/Mapper/CreateEntreeResponseMapperTest.php diff --git a/src/Bovin/Dto/CreateEntreeResponseDto.php b/src/Bovin/Dto/CreateEntreeResponseDto.php new file mode 100644 index 0000000..3817e2b --- /dev/null +++ b/src/Bovin/Dto/CreateEntreeResponseDto.php @@ -0,0 +1,26 @@ +standardResponseMapper->map($soapResponse->ReponseStandard ?? null); + + $specific = $soapResponse->ReponseSpecifique ?? null; + + $pending = false; + $identification = null; + $entryMovement = null; + + if (is_object($specific)) { + $pendingFlag = $specific->AttenteValidationBDNi ?? null; + if (null !== $pendingFlag) { + $pending = (bool) $this->toNullableBool($pendingFlag); + } + + $validee = $specific->EntreeValidee ?? null; + if (is_object($validee)) { + $identityNode = $validee->IdentiteBovin ?? null; + if (is_object($identityNode)) { + $identification = $this->mapIdentification($identityNode); + } + + $movementNode = $validee->MouvementEntreeBovin ?? null; + if (is_object($movementNode)) { + $entryMovement = $this->mapMovement($movementNode, 'entry'); + } + } + } + + return new CreateEntreeResponseDto( + standardResponse: $standardResponse, + pendingBdniValidation: $pending, + identification: $identification, + entryMovement: $entryMovement, + rawSoapResponse: $soapResponse, + ); + } +} diff --git a/tests/Unit/Bovin/Mapper/CreateEntreeResponseMapperTest.php b/tests/Unit/Bovin/Mapper/CreateEntreeResponseMapperTest.php new file mode 100644 index 0000000..f24fa04 --- /dev/null +++ b/tests/Unit/Bovin/Mapper/CreateEntreeResponseMapperTest.php @@ -0,0 +1,68 @@ +ReponseStandard = new stdClass(); + $soapResponse->ReponseStandard->Resultat = true; + $soapResponse->ReponseSpecifique = new stdClass(); + $soapResponse->ReponseSpecifique->AttenteValidationBDNi = true; + + $dto = new CreateEntreeResponseMapper(new StandardResponseMapper())->map($soapResponse); + + self::assertInstanceOf(CreateEntreeResponseDto::class, $dto); + self::assertTrue($dto->standardResponse->result); + self::assertTrue($dto->pendingBdniValidation); + self::assertNull($dto->identification); + self::assertNull($dto->entryMovement); + } + + public function testMapValidatedEntry(): void + { + $soapResponse = new stdClass(); + $soapResponse->ReponseStandard = new stdClass(); + $soapResponse->ReponseStandard->Resultat = true; + $soapResponse->ReponseSpecifique = new stdClass(); + + $validee = new stdClass(); + $validee->IdentiteBovin = new stdClass(); + $validee->IdentiteBovin->Sexe = 'F'; + $validee->IdentiteBovin->Bovin = new stdClass(); + $validee->IdentiteBovin->Bovin->CodePays = 'FR'; + $validee->IdentiteBovin->Bovin->NumeroNational = 'FR1234567890'; + + $validee->MouvementEntreeBovin = new stdClass(); + $validee->MouvementEntreeBovin->DateEntree = '2026-04-22'; + $validee->MouvementEntreeBovin->CauseEntree = 'A'; + + $soapResponse->ReponseSpecifique->EntreeValidee = $validee; + + $dto = new CreateEntreeResponseMapper(new StandardResponseMapper())->map($soapResponse); + + self::assertFalse($dto->pendingBdniValidation); + self::assertNotNull($dto->identification); + self::assertSame('F', $dto->identification->sex); + self::assertSame('FR1234567890', $dto->identification->bovin?->nationalNumber); + self::assertNotNull($dto->entryMovement); + self::assertEquals(new DateTimeImmutable('2026-04-22'), $dto->entryMovement->date); + self::assertSame('A', $dto->entryMovement->cause); + } +}