feat : DTO et mapper pour IpBGetRetourDossiers
This commit is contained in:
22
src/Bovin/Dto/ReturnedDossiersDto.php
Normal file
22
src/Bovin/Dto/ReturnedDossiersDto.php
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Malio\EdnotifBundle\Bovin\Dto;
|
||||||
|
|
||||||
|
use DateTimeImmutable;
|
||||||
|
use Malio\EdnotifBundle\Shared\Dto\StandardResponseDto;
|
||||||
|
|
||||||
|
final readonly class ReturnedDossiersDto
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @param list<AnimalSummaryDto> $animals
|
||||||
|
*/
|
||||||
|
public function __construct(
|
||||||
|
public StandardResponseDto $standardResponse,
|
||||||
|
public int $nbBovins,
|
||||||
|
public ?DateTimeImmutable $startDate,
|
||||||
|
public array $animals,
|
||||||
|
public ?object $rawSoapResponse,
|
||||||
|
) {}
|
||||||
|
}
|
||||||
50
src/Bovin/Mapper/ReturnedDossiersMapper.php
Normal file
50
src/Bovin/Mapper/ReturnedDossiersMapper.php
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Malio\EdnotifBundle\Bovin\Mapper;
|
||||||
|
|
||||||
|
use Malio\EdnotifBundle\Bovin\Dto\ReturnedDossiersDto;
|
||||||
|
use Malio\EdnotifBundle\Shared\Mapper\StandardResponseMapper;
|
||||||
|
|
||||||
|
final class ReturnedDossiersMapper
|
||||||
|
{
|
||||||
|
use BovinNodeMappingTrait;
|
||||||
|
|
||||||
|
public function __construct(
|
||||||
|
private readonly AnimalSummaryMapper $animalSummaryMapper,
|
||||||
|
private readonly StandardResponseMapper $standardResponseMapper,
|
||||||
|
) {}
|
||||||
|
|
||||||
|
public function map(object $soapResponse, ?object $unzippedMessage): ReturnedDossiersDto
|
||||||
|
{
|
||||||
|
$standardResponse = $this->standardResponseMapper->map($soapResponse->ReponseStandard ?? null);
|
||||||
|
$nbBovins = $this->toNullableInt($soapResponse->ReponseSpecifique->NbBovins ?? null) ?? 0;
|
||||||
|
|
||||||
|
$startDate = null;
|
||||||
|
$animals = [];
|
||||||
|
|
||||||
|
if (is_object($unzippedMessage)) {
|
||||||
|
$infoNode = $unzippedMessage->InformationsMessage ?? null;
|
||||||
|
if (is_object($infoNode)) {
|
||||||
|
$startDate = $this->toNullableDate($infoNode->DateDebut ?? null);
|
||||||
|
}
|
||||||
|
|
||||||
|
$bovinsNode = $unzippedMessage->Bovins->Bovin ?? null;
|
||||||
|
foreach ($this->normalizeToList($bovinsNode) as $bovinNode) {
|
||||||
|
if (!is_object($bovinNode)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$animals[] = $this->animalSummaryMapper->map($bovinNode);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return new ReturnedDossiersDto(
|
||||||
|
standardResponse: $standardResponse,
|
||||||
|
nbBovins: $nbBovins,
|
||||||
|
startDate: $startDate,
|
||||||
|
animals: $animals,
|
||||||
|
rawSoapResponse: $soapResponse,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
67
tests/Unit/Bovin/Mapper/ReturnedDossiersMapperTest.php
Normal file
67
tests/Unit/Bovin/Mapper/ReturnedDossiersMapperTest.php
Normal file
@@ -0,0 +1,67 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Malio\EdnotifBundle\Tests\Unit\Bovin\Mapper;
|
||||||
|
|
||||||
|
use DateTimeImmutable;
|
||||||
|
use Malio\EdnotifBundle\Bovin\Dto\ReturnedDossiersDto;
|
||||||
|
use Malio\EdnotifBundle\Bovin\Mapper\AnimalSummaryMapper;
|
||||||
|
use Malio\EdnotifBundle\Bovin\Mapper\ReturnedDossiersMapper;
|
||||||
|
use Malio\EdnotifBundle\Shared\Mapper\StandardResponseMapper;
|
||||||
|
use PHPUnit\Framework\Attributes\CoversClass;
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
use stdClass;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @internal
|
||||||
|
*/
|
||||||
|
#[CoversClass(ReturnedDossiersMapper::class)]
|
||||||
|
final class ReturnedDossiersMapperTest extends TestCase
|
||||||
|
{
|
||||||
|
public function testMapReturnsAnimalsAndStartDate(): void
|
||||||
|
{
|
||||||
|
$mapper = new ReturnedDossiersMapper(new AnimalSummaryMapper(), new StandardResponseMapper());
|
||||||
|
|
||||||
|
$soapResponse = new stdClass();
|
||||||
|
$soapResponse->ReponseStandard = new stdClass();
|
||||||
|
$soapResponse->ReponseStandard->Resultat = true;
|
||||||
|
$soapResponse->ReponseSpecifique = new stdClass();
|
||||||
|
$soapResponse->ReponseSpecifique->NbBovins = 1;
|
||||||
|
|
||||||
|
$message = new stdClass();
|
||||||
|
$message->InformationsMessage = new stdClass();
|
||||||
|
$message->InformationsMessage->DateDebut = '2026-03-01';
|
||||||
|
$message->Bovins = new stdClass();
|
||||||
|
$message->Bovins->Bovin = new stdClass();
|
||||||
|
$message->Bovins->Bovin->IdentiteBovin = new stdClass();
|
||||||
|
$message->Bovins->Bovin->IdentiteBovin->Bovin = new stdClass();
|
||||||
|
$message->Bovins->Bovin->IdentiteBovin->Bovin->NumeroNational = 'FR789';
|
||||||
|
$message->Bovins->Bovin->PeriodesPresences = new stdClass();
|
||||||
|
$message->Bovins->Bovin->PeriodesPresences->PeriodePresence = new stdClass();
|
||||||
|
|
||||||
|
$dto = $mapper->map($soapResponse, $message);
|
||||||
|
|
||||||
|
self::assertInstanceOf(ReturnedDossiersDto::class, $dto);
|
||||||
|
self::assertEquals(new DateTimeImmutable('2026-03-01'), $dto->startDate);
|
||||||
|
self::assertSame(1, $dto->nbBovins);
|
||||||
|
self::assertCount(1, $dto->animals);
|
||||||
|
self::assertSame('FR789', $dto->animals[0]->identification?->bovin?->nationalNumber);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testMapWithoutMessageReturnsEmptyAnimals(): void
|
||||||
|
{
|
||||||
|
$mapper = new ReturnedDossiersMapper(new AnimalSummaryMapper(), new StandardResponseMapper());
|
||||||
|
|
||||||
|
$soapResponse = new stdClass();
|
||||||
|
$soapResponse->ReponseStandard = new stdClass();
|
||||||
|
$soapResponse->ReponseStandard->Resultat = true;
|
||||||
|
$soapResponse->ReponseSpecifique = new stdClass();
|
||||||
|
$soapResponse->ReponseSpecifique->NbBovins = 0;
|
||||||
|
|
||||||
|
$dto = $mapper->map($soapResponse, null);
|
||||||
|
|
||||||
|
self::assertSame(0, $dto->nbBovins);
|
||||||
|
self::assertSame([], $dto->animals);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user