feat : DTO et mapper de réponse pour IpBCreateEntree

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-04-22 14:53:27 +02:00
parent 7c028f79c7
commit 971e160120
3 changed files with 150 additions and 0 deletions

View File

@@ -0,0 +1,26 @@
<?php
declare(strict_types=1);
namespace Malio\EdnotifBundle\Bovin\Dto;
use Malio\EdnotifBundle\Shared\Dto\StandardResponseDto;
/**
* Réponse de `IpBCreateEntree`.
*
* Si `$pendingBdniValidation === true`, EDNOTIF a accepté la requête mais
* attend la validation asynchrone de la BDNi — `identification` et
* `entryMovement` sont `null`. Sinon, les deux sont populés avec les données
* validées du bovin et du mouvement d'entrée.
*/
final readonly class CreateEntreeResponseDto
{
public function __construct(
public StandardResponseDto $standardResponse,
public bool $pendingBdniValidation,
public ?BovinIdentificationDto $identification,
public ?MovementDto $entryMovement,
public ?object $rawSoapResponse,
) {}
}

View File

@@ -0,0 +1,56 @@
<?php
declare(strict_types=1);
namespace Malio\EdnotifBundle\Bovin\Mapper;
use Malio\EdnotifBundle\Bovin\Dto\CreateEntreeResponseDto;
use Malio\EdnotifBundle\Shared\Mapper\StandardResponseMapper;
final class CreateEntreeResponseMapper
{
use BovinNodeMappingTrait;
public function __construct(
private readonly StandardResponseMapper $standardResponseMapper,
) {}
public function map(object $soapResponse): CreateEntreeResponseDto
{
$standardResponse = $this->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,
);
}
}

View File

@@ -0,0 +1,68 @@
<?php
declare(strict_types=1);
namespace Malio\EdnotifBundle\Tests\Unit\Bovin\Mapper;
use DateTimeImmutable;
use Malio\EdnotifBundle\Bovin\Dto\CreateEntreeResponseDto;
use Malio\EdnotifBundle\Bovin\Mapper\CreateEntreeResponseMapper;
use Malio\EdnotifBundle\Shared\Mapper\StandardResponseMapper;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\TestCase;
use stdClass;
/**
* @internal
*/
#[CoversClass(CreateEntreeResponseMapper::class)]
final class CreateEntreeResponseMapperTest extends TestCase
{
public function testMapPendingBdniValidation(): void
{
$soapResponse = new stdClass();
$soapResponse->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);
}
}