Files
ednotif-bundle/tests/Unit/Bovin/Mapper/AnimalSummaryMapperTest.php
tristan f757822f36
All checks were successful
Auto Tag Develop / tag (push) Successful in 6s
Build Release Artefact / build (push) Successful in 39s
[#ED-1] Ajout des API de lecture bovin (#2)
| Numéro du ticket | Titre du ticket |
|------------------|-----------------|
|                  |                 |

## Description de la PR

## Modification du .env

## Check list

- [ ] Pas de régression
- [x] TU/TI/TF rédigée
- [x] TU/TI/TF OK
- [ ] CHANGELOG modifié

Reviewed-on: #2
Co-authored-by: tristan <tristan@yuno.malio.fr>
Co-committed-by: tristan <tristan@yuno.malio.fr>
2026-04-21 08:14:37 +00:00

71 lines
2.3 KiB
PHP

<?php
declare(strict_types=1);
namespace Malio\EdnotifBundle\Tests\Unit\Bovin\Mapper;
use Malio\EdnotifBundle\Bovin\Dto\AnimalSummaryDto;
use Malio\EdnotifBundle\Bovin\Mapper\AnimalSummaryMapper;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\TestCase;
use stdClass;
/**
* @internal
*/
#[CoversClass(AnimalSummaryMapper::class)]
final class AnimalSummaryMapperTest extends TestCase
{
public function testMapReturnsIdentificationAndPresencePeriods(): void
{
$node = $this->makeBovinNode();
$summary = new AnimalSummaryMapper()->map($node);
self::assertInstanceOf(AnimalSummaryDto::class, $summary);
self::assertNotNull($summary->identification);
self::assertSame('FR1234567890', $summary->identification->bovin?->nationalNumber);
self::assertSame('F', $summary->identification->sex);
self::assertCount(2, $summary->presencePeriods);
}
public function testMapHandlesMissingOptionalNodes(): void
{
$summary = new AnimalSummaryMapper()->map(new stdClass());
self::assertNull($summary->identification);
self::assertSame([], $summary->presencePeriods);
}
private function makeBovinNode(): object
{
$node = new stdClass();
$node->IdentiteBovin = new stdClass();
$node->IdentiteBovin->Sexe = 'F';
$node->IdentiteBovin->Bovin = new stdClass();
$node->IdentiteBovin->Bovin->CodePays = 'FR';
$node->IdentiteBovin->Bovin->NumeroNational = 'FR1234567890';
$node->PeriodesPresences = new stdClass();
$node->PeriodesPresences->PeriodePresence = [
$this->makePresencePeriod('2024-01-10', '2024-06-01'),
$this->makePresencePeriod('2024-06-02', null),
];
return $node;
}
private function makePresencePeriod(string $entryDate, ?string $exitDate): object
{
$period = new stdClass();
$period->Entree = new stdClass();
$period->Entree->DateEntree = $entryDate;
if (null !== $exitDate) {
$period->Sortie = new stdClass();
$period->Sortie->DateSortie = $exitDate;
}
return $period;
}
}