100 lines
4.0 KiB
PHP
100 lines
4.0 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Malio\EdnotifBundle\Tests\Unit\Bovin\Mapper;
|
|
|
|
use DateTimeImmutable;
|
|
use Malio\EdnotifBundle\Bovin\Dto\InventoryDto;
|
|
use Malio\EdnotifBundle\Bovin\Mapper\AnimalSummaryMapper;
|
|
use Malio\EdnotifBundle\Bovin\Mapper\InventoryMapper;
|
|
use PHPUnit\Framework\Attributes\CoversClass;
|
|
use PHPUnit\Framework\TestCase;
|
|
use stdClass;
|
|
|
|
/**
|
|
* @internal
|
|
*/
|
|
#[CoversClass(InventoryMapper::class)]
|
|
final class InventoryMapperTest extends TestCase
|
|
{
|
|
public function testMapFullInventory(): void
|
|
{
|
|
$mapper = new InventoryMapper(new AnimalSummaryMapper());
|
|
|
|
$inventory = $mapper->map($this->makeSoapResponse(), $this->makeUnzippedMessage());
|
|
|
|
self::assertInstanceOf(InventoryDto::class, $inventory);
|
|
self::assertTrue($inventory->standardResponse->result);
|
|
self::assertSame(2, $inventory->nbBovins);
|
|
self::assertEquals(new DateTimeImmutable('2026-01-01'), $inventory->startDate);
|
|
self::assertEquals(new DateTimeImmutable('2026-01-31'), $inventory->endDate);
|
|
self::assertTrue($inventory->includesEarTagStock);
|
|
self::assertCount(2, $inventory->animals);
|
|
self::assertCount(1, $inventory->earTagSeries);
|
|
self::assertSame('FR123', $inventory->animals[0]->identification?->bovin?->nationalNumber);
|
|
}
|
|
|
|
public function testMapInventoryWithoutMessageZipReturnsEmptyLists(): void
|
|
{
|
|
$mapper = new InventoryMapper(new AnimalSummaryMapper());
|
|
|
|
$soapResponse = new stdClass();
|
|
$soapResponse->ReponseStandard = new stdClass();
|
|
$soapResponse->ReponseStandard->Resultat = true;
|
|
$soapResponse->ReponseSpecifique = new stdClass();
|
|
$soapResponse->ReponseSpecifique->NbBovins = 0;
|
|
|
|
$inventory = $mapper->map($soapResponse, null);
|
|
|
|
self::assertSame(0, $inventory->nbBovins);
|
|
self::assertSame([], $inventory->animals);
|
|
self::assertSame([], $inventory->earTagSeries);
|
|
self::assertNull($inventory->startDate);
|
|
}
|
|
|
|
private function makeSoapResponse(): object
|
|
{
|
|
$response = new stdClass();
|
|
$response->ReponseStandard = new stdClass();
|
|
$response->ReponseStandard->Resultat = true;
|
|
$response->ReponseSpecifique = new stdClass();
|
|
$response->ReponseSpecifique->NbBovins = 2;
|
|
|
|
return $response;
|
|
}
|
|
|
|
private function makeUnzippedMessage(): object
|
|
{
|
|
$message = new stdClass();
|
|
$message->InformationsMessage = new stdClass();
|
|
$message->InformationsMessage->DateDebut = '2026-01-01';
|
|
$message->InformationsMessage->DateFin = '2026-01-31';
|
|
$message->InformationsMessage->StockBoucles = '1';
|
|
$message->Bovins = new stdClass();
|
|
$message->Bovins->Bovin = [
|
|
$this->makeAnimalNode('FR123'),
|
|
$this->makeAnimalNode('FR456'),
|
|
];
|
|
$message->Boucles = new stdClass();
|
|
$message->Boucles->SerieBoucles = new stdClass();
|
|
$message->Boucles->SerieBoucles->NumeroSerieDebut = 'A0001';
|
|
|
|
return $message;
|
|
}
|
|
|
|
private function makeAnimalNode(string $nationalNumber): object
|
|
{
|
|
$node = new stdClass();
|
|
$node->IdentiteBovin = new stdClass();
|
|
$node->IdentiteBovin->Bovin = new stdClass();
|
|
$node->IdentiteBovin->Bovin->NumeroNational = $nationalNumber;
|
|
$node->PeriodesPresences = new stdClass();
|
|
$node->PeriodesPresences->PeriodePresence = new stdClass();
|
|
$node->PeriodesPresences->PeriodePresence->Entree = new stdClass();
|
|
$node->PeriodesPresences->PeriodePresence->Entree->DateEntree = '2025-05-01';
|
|
|
|
return $node;
|
|
}
|
|
}
|