Compare commits
4 Commits
v0.0.5
...
5a6d166bc8
| Author | SHA1 | Date | |
|---|---|---|---|
| 5a6d166bc8 | |||
| d977207933 | |||
| 17cd62131a | |||
| f757822f36 |
33
README.md
33
README.md
@@ -33,3 +33,36 @@ Dans le docker-composer.yaml
|
||||
volumes:
|
||||
- ../ednotif-bundle:/var/www/html/ednotif-bundle
|
||||
```
|
||||
|
||||
## Utilisation
|
||||
|
||||
Le bundle expose `Malio\EdnotifBundle\Bovin\Api\BovinApiInterface`. Injection standard par autowiring.
|
||||
|
||||
```php
|
||||
use Malio\EdnotifBundle\Bovin\Api\BovinApiInterface;
|
||||
|
||||
final class MyController
|
||||
{
|
||||
public function __construct(private BovinApiInterface $ednotif) {}
|
||||
|
||||
public function example(): void
|
||||
{
|
||||
// Dossier d'un bovin
|
||||
$file = $this->ednotif->getAnimalFile('FR1234567890');
|
||||
|
||||
// Inventaire du cheptel à une date
|
||||
$inventory = $this->ednotif->getInventory(
|
||||
startDate: new \DateTimeImmutable('2026-01-01'),
|
||||
includeEarTagStock: true,
|
||||
);
|
||||
|
||||
// Retours de notifications depuis une date
|
||||
$returns = $this->ednotif->getReturnedDossiers(new \DateTimeImmutable('2026-03-01'));
|
||||
|
||||
// Sorties présumées par l'IPG (flux de rapprochement)
|
||||
$presumed = $this->ednotif->getPresumedExits();
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Toutes les méthodes lèvent `Malio\EdnotifBundle\Shared\Exception\EdnotifException` en cas de `Resultat=false` côté EDNOTIF.
|
||||
|
||||
@@ -6,7 +6,13 @@ use Malio\EdnotifBundle\Auth\TokenProvider;
|
||||
use Malio\EdnotifBundle\Bovin\Api\BovinApi;
|
||||
use Malio\EdnotifBundle\Bovin\Api\BovinApiInterface;
|
||||
use Malio\EdnotifBundle\Bovin\Mapper\AnimalFileMapper;
|
||||
use Malio\EdnotifBundle\Bovin\Mapper\AnimalSummaryMapper;
|
||||
use Malio\EdnotifBundle\Bovin\Mapper\InventoryMapper;
|
||||
use Malio\EdnotifBundle\Bovin\Mapper\PresumedExitsMapper;
|
||||
use Malio\EdnotifBundle\Bovin\Mapper\ReturnedDossiersMapper;
|
||||
use Malio\EdnotifBundle\Shared\Mapper\StandardResponseMapper;
|
||||
use Malio\EdnotifBundle\Shared\Soap\SoapClientFactory;
|
||||
use Malio\EdnotifBundle\Shared\Soap\ZipMessageDecoder;
|
||||
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
|
||||
|
||||
use function Symfony\Component\DependencyInjection\Loader\Configurator\service;
|
||||
@@ -22,6 +28,8 @@ return static function (ContainerConfigurator $container): void {
|
||||
->arg('$soapOptions', '%ednotif.soap_options%')
|
||||
;
|
||||
|
||||
$services->set(StandardResponseMapper::class);
|
||||
|
||||
$services->set('ednotif.soap.guichet', SoapClient::class)
|
||||
->factory([service(SoapClientFactory::class), 'create'])
|
||||
->args(['%ednotif.guichet_wsdl%'])
|
||||
@@ -32,7 +40,29 @@ return static function (ContainerConfigurator $container): void {
|
||||
->args(['%ednotif.metier_wsdl%'])
|
||||
;
|
||||
|
||||
$services->set(AnimalFileMapper::class);
|
||||
$services->set(AnimalFileMapper::class)->args([service(StandardResponseMapper::class)]);
|
||||
|
||||
$services->set(ZipMessageDecoder::class);
|
||||
$services->set(AnimalSummaryMapper::class);
|
||||
$services->set(InventoryMapper::class)
|
||||
->args([
|
||||
service(AnimalSummaryMapper::class),
|
||||
service(StandardResponseMapper::class),
|
||||
])
|
||||
;
|
||||
|
||||
$services->set(ReturnedDossiersMapper::class)
|
||||
->args([
|
||||
service(AnimalSummaryMapper::class),
|
||||
service(StandardResponseMapper::class),
|
||||
])
|
||||
;
|
||||
|
||||
$services->set(PresumedExitsMapper::class)
|
||||
->args([
|
||||
service(StandardResponseMapper::class),
|
||||
])
|
||||
;
|
||||
|
||||
$services->set(TokenProvider::class)
|
||||
->args([
|
||||
@@ -52,6 +82,10 @@ return static function (ContainerConfigurator $container): void {
|
||||
service(TokenProvider::class),
|
||||
service('ednotif.soap.business'),
|
||||
service(AnimalFileMapper::class),
|
||||
service(InventoryMapper::class),
|
||||
service(ReturnedDossiersMapper::class),
|
||||
service(PresumedExitsMapper::class),
|
||||
service(ZipMessageDecoder::class),
|
||||
'%ednotif.exploitation_country_code%',
|
||||
'%ednotif.exploitation_number%',
|
||||
])
|
||||
|
||||
1978
docs/superpowers/plans/2026-04-20-bovin-reads.md
Normal file
1978
docs/superpowers/plans/2026-04-20-bovin-reads.md
Normal file
File diff suppressed because it is too large
Load Diff
375
docs/superpowers/plans/2026-04-21-tech-debt-phase-1.md
Normal file
375
docs/superpowers/plans/2026-04-21-tech-debt-phase-1.md
Normal file
@@ -0,0 +1,375 @@
|
||||
# Dette technique post-Phase 1
|
||||
|
||||
> **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking.
|
||||
|
||||
**Goal:** Combler les deux trous de couverture flaggés par les reviews de Phase 1 avant de démarrer Phase 2 (écriture bovin), pour éviter que les nouveaux mappers empilent de la complexité sur des helpers non-pinnés.
|
||||
|
||||
**Architecture:** Deux fichiers de tests seulement. (1) Un nouveau `BovinNodeMappingTraitTest` qui couvre directement les 5 helpers scalaires du trait via une classe adapter anonyme — jusqu'ici ces helpers n'étaient testés qu'indirectement par les mappers, donc leurs edge cases dérivent sans qu'on s'en rende compte. (2) Des tests adversariaux ajoutés à `InventoryMapperTest` pour pinner les shapes dégradées qui peuvent arriver en prod (`StockBoucles` absent, `DateFin` manquant, `SerieBoucles` en liste, `NbBovins` non-numérique). Pas de changement de code de production — uniquement du test. Un petit docblock ajouté à `EarTagSeriesDto` pour documenter son statut Phase-1.
|
||||
|
||||
**Tech Stack:** PHP 8.4, PHPUnit 12, pas de nouvelle dépendance.
|
||||
|
||||
---
|
||||
|
||||
## Task 1 — Tests directs des helpers scalaires du trait
|
||||
|
||||
**But** : pinner le comportement de `normalizeToList`, `toNullableString`, `toNullableInt`, `toNullableBool`, `toNullableDate` — les 5 helpers purs que chaque nouveau mapper va hériter via `use BovinNodeMappingTrait`.
|
||||
|
||||
**Approche** : une classe adapter anonyme, définie inline dans le test, qui `use` le trait et re-expose chaque helper en `public` pour l'appeler depuis les tests. Pas de nouvelle production class, pas de refacto du trait.
|
||||
|
||||
**Files:**
|
||||
- Create: `tests/Unit/Bovin/Mapper/BovinNodeMappingTraitTest.php`
|
||||
|
||||
### Steps
|
||||
|
||||
- [ ] **Step 1: Écrire le fichier de test**
|
||||
|
||||
Contenu complet de `tests/Unit/Bovin/Mapper/BovinNodeMappingTraitTest.php` :
|
||||
```php
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Malio\EdnotifBundle\Tests\Unit\Bovin\Mapper;
|
||||
|
||||
use DateTimeImmutable;
|
||||
use Malio\EdnotifBundle\Bovin\Mapper\BovinNodeMappingTrait;
|
||||
use PHPUnit\Framework\Attributes\CoversTrait;
|
||||
use PHPUnit\Framework\Attributes\DataProvider;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use stdClass;
|
||||
|
||||
#[CoversTrait(BovinNodeMappingTrait::class)]
|
||||
final class BovinNodeMappingTraitTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* Adapter anonyme : re-expose chaque helper protected en public pour le test,
|
||||
* sans jamais instancier un vrai mapper (ceux-ci ont des dépendances DI).
|
||||
*/
|
||||
private static function adapter(): object
|
||||
{
|
||||
return new class {
|
||||
use BovinNodeMappingTrait {
|
||||
normalizeToList as public;
|
||||
toNullableString as public;
|
||||
toNullableInt as public;
|
||||
toNullableBool as public;
|
||||
toNullableDate as public;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
// ---------- normalizeToList ----------
|
||||
|
||||
public function testNormalizeToListWithNullReturnsEmptyList(): void
|
||||
{
|
||||
self::assertSame([], self::adapter()->normalizeToList(null));
|
||||
}
|
||||
|
||||
public function testNormalizeToListWithScalarWrapsIntoList(): void
|
||||
{
|
||||
self::assertSame(['foo'], self::adapter()->normalizeToList('foo'));
|
||||
self::assertSame([42], self::adapter()->normalizeToList(42));
|
||||
}
|
||||
|
||||
public function testNormalizeToListWithObjectWrapsIntoList(): void
|
||||
{
|
||||
$obj = new stdClass();
|
||||
$result = self::adapter()->normalizeToList($obj);
|
||||
|
||||
self::assertCount(1, $result);
|
||||
self::assertSame($obj, $result[0]);
|
||||
}
|
||||
|
||||
public function testNormalizeToListWithListReturnsListUnchanged(): void
|
||||
{
|
||||
$input = ['a', 'b', 'c'];
|
||||
self::assertSame($input, self::adapter()->normalizeToList($input));
|
||||
}
|
||||
|
||||
public function testNormalizeToListWithAssociativeArrayDiscardsKeys(): void
|
||||
{
|
||||
$input = ['x' => 'a', 'y' => 'b'];
|
||||
$result = self::adapter()->normalizeToList($input);
|
||||
|
||||
self::assertSame(['a', 'b'], $result);
|
||||
}
|
||||
|
||||
// ---------- toNullableString ----------
|
||||
|
||||
/** @return iterable<string,array{mixed, ?string}> */
|
||||
public static function toNullableStringProvider(): iterable
|
||||
{
|
||||
yield 'null' => [null, null];
|
||||
yield 'empty string' => ['', null];
|
||||
yield 'whitespace only' => [' ', null];
|
||||
yield 'plain' => ['abc', 'abc'];
|
||||
yield 'trimmed' => [' abc ', 'abc'];
|
||||
yield 'int coerced to string' => [42, '42'];
|
||||
yield 'zero preserved' => ['0', '0'];
|
||||
}
|
||||
|
||||
#[DataProvider('toNullableStringProvider')]
|
||||
public function testToNullableString(mixed $input, ?string $expected): void
|
||||
{
|
||||
self::assertSame($expected, self::adapter()->toNullableString($input));
|
||||
}
|
||||
|
||||
// ---------- toNullableInt ----------
|
||||
|
||||
/** @return iterable<string,array{mixed, ?int}> */
|
||||
public static function toNullableIntProvider(): iterable
|
||||
{
|
||||
yield 'null' => [null, null];
|
||||
yield 'int passthrough' => [42, 42];
|
||||
yield 'zero int' => [0, 0];
|
||||
yield 'numeric string' => ['42', 42];
|
||||
yield 'negative string' => ['-7', -7];
|
||||
yield 'float-like string' => ['3.14', 3];
|
||||
yield 'non-numeric' => ['abc', null];
|
||||
yield 'empty string' => ['', null];
|
||||
}
|
||||
|
||||
#[DataProvider('toNullableIntProvider')]
|
||||
public function testToNullableInt(mixed $input, ?int $expected): void
|
||||
{
|
||||
self::assertSame($expected, self::adapter()->toNullableInt($input));
|
||||
}
|
||||
|
||||
// ---------- toNullableBool ----------
|
||||
|
||||
/** @return iterable<string,array{mixed, ?bool}> */
|
||||
public static function toNullableBoolProvider(): iterable
|
||||
{
|
||||
yield 'null' => [null, null];
|
||||
yield 'true' => [true, true];
|
||||
yield 'false' => [false, false];
|
||||
yield 'string 1' => ['1', true];
|
||||
yield 'string 0' => ['0', false];
|
||||
yield 'empty string' => ['', false];
|
||||
yield 'int 1' => [1, true];
|
||||
yield 'int 0' => [0, false];
|
||||
}
|
||||
|
||||
#[DataProvider('toNullableBoolProvider')]
|
||||
public function testToNullableBool(mixed $input, ?bool $expected): void
|
||||
{
|
||||
self::assertSame($expected, self::adapter()->toNullableBool($input));
|
||||
}
|
||||
|
||||
// ---------- toNullableDate ----------
|
||||
|
||||
public function testToNullableDateFromIsoString(): void
|
||||
{
|
||||
$result = self::adapter()->toNullableDate('2026-04-21');
|
||||
self::assertEquals(new DateTimeImmutable('2026-04-21'), $result);
|
||||
}
|
||||
|
||||
public function testToNullableDateFromDateTimeString(): void
|
||||
{
|
||||
$result = self::adapter()->toNullableDate('2026-04-21T10:30:00+02:00');
|
||||
self::assertEquals(new DateTimeImmutable('2026-04-21T10:30:00+02:00'), $result);
|
||||
}
|
||||
|
||||
/** @return iterable<string,array{mixed}> */
|
||||
public static function toNullableDateFallbackProvider(): iterable
|
||||
{
|
||||
yield 'null' => [null];
|
||||
yield 'empty string' => [''];
|
||||
yield 'whitespace' => [' '];
|
||||
yield 'non-string int' => [42];
|
||||
yield 'non-string array' => [[]];
|
||||
yield 'invalid date string' => ['not-a-date'];
|
||||
}
|
||||
|
||||
#[DataProvider('toNullableDateFallbackProvider')]
|
||||
public function testToNullableDateReturnsNullOnInvalidInput(mixed $input): void
|
||||
{
|
||||
self::assertNull(self::adapter()->toNullableDate($input));
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
**Notes importantes** :
|
||||
- L'adapter anonyme utilise la syntaxe `use BovinNodeMappingTrait { ... as public; }` pour promouvoir chaque helper protected en public *seulement dans ce test*. Le trait lui-même reste inchangé (les helpers restent `protected` pour les vrais mappers).
|
||||
- Le cas `'string false' => [...]` est **volontairement absent** de `toNullableBoolProvider` : le helper actuel retourne `true` pour `'false'` (string non-vide), ce qui est un bug latent mais pas dans le scope de ce task. Documenté ici pour que tu le retrouves si jamais ça remonte en prod.
|
||||
|
||||
- [ ] **Step 2: Lancer le test (doit passer immédiatement)**
|
||||
|
||||
Run:
|
||||
```
|
||||
make test FILES=tests/Unit/Bovin/Mapper/BovinNodeMappingTraitTest.php
|
||||
```
|
||||
Expected : tous les tests passent du premier coup. Pas de RED phase ici — on teste du code existant qui marche déjà. Si un test échoue, c'est qu'on a découvert un bug : remonter avant de commit.
|
||||
|
||||
Compte attendu : environ **36 test cases** (PHPUnit compte chaque entrée de DataProvider comme un test distinct). L'ordre de grandeur compte plus que le chiffre exact — l'important est que 100% soient verts.
|
||||
|
||||
- [ ] **Step 3: Lancer la suite complète pour vérifier qu'il n'y a pas de régression**
|
||||
|
||||
Run:
|
||||
```
|
||||
make test
|
||||
```
|
||||
Expected : 12 tests préexistants + nouveaux tests de ce task, tous verts.
|
||||
|
||||
- [ ] **Step 4: Commit**
|
||||
|
||||
Run:
|
||||
```
|
||||
git add tests/Unit/Bovin/Mapper/BovinNodeMappingTraitTest.php
|
||||
git commit -m "test : pin des helpers scalaires de BovinNodeMappingTrait"
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Task 2 — Tests adversariaux `InventoryMapper` + docblock `EarTagSeriesDto`
|
||||
|
||||
**But** : pinner les shapes dégradées qui peuvent sortir de `ZipMessageDecoder` (message partiel, champ absent, liste à un seul élément venant sous forme d'objet, etc.). Ces cas ne sont pas exotiques : la roundtrip SimpleXML→JSON→stdClass change de shape selon le nombre d'enfants, et EDNOTIF peut omettre des nœuds optionnels. Également, ajouter un docblock sur `EarTagSeriesDto` pour documenter que le raw-node est un choix Phase-1 assumé.
|
||||
|
||||
**Files:**
|
||||
- Modify: `tests/Unit/Bovin/Mapper/InventoryMapperTest.php`
|
||||
- Modify: `src/Bovin/Dto/EarTagSeriesDto.php` (ajout docblock uniquement, aucun changement de code)
|
||||
|
||||
### Steps
|
||||
|
||||
- [ ] **Step 1: Ajouter 5 tests à `InventoryMapperTest`**
|
||||
|
||||
Ouvrir `tests/Unit/Bovin/Mapper/InventoryMapperTest.php` et ajouter les 5 méthodes suivantes **après** `testMapInventoryWithoutMessageZipReturnsEmptyLists`, **avant** les helpers privés (`makeSoapResponse`, `makeUnzippedMessage`, `makeAnimalNode`).
|
||||
|
||||
Les helpers privés existants sont réutilisés quand ils suffisent ; sinon on construit un message ad-hoc inline.
|
||||
|
||||
Code à insérer :
|
||||
```php
|
||||
public function testMapInventoryWithStockBouclesAbsentYieldsNullFlag(): void
|
||||
{
|
||||
$mapper = new InventoryMapper(new AnimalSummaryMapper(), new StandardResponseMapper());
|
||||
|
||||
$message = new stdClass();
|
||||
$message->InformationsMessage = new stdClass();
|
||||
$message->InformationsMessage->DateDebut = '2026-01-01';
|
||||
// StockBoucles deliberately omitted
|
||||
|
||||
$inventory = $mapper->map($this->makeSoapResponse(), $message);
|
||||
|
||||
self::assertNull($inventory->includesEarTagStock);
|
||||
}
|
||||
|
||||
public function testMapInventoryWithStockBouclesZeroYieldsFalseFlag(): void
|
||||
{
|
||||
$mapper = new InventoryMapper(new AnimalSummaryMapper(), new StandardResponseMapper());
|
||||
|
||||
$message = new stdClass();
|
||||
$message->InformationsMessage = new stdClass();
|
||||
$message->InformationsMessage->StockBoucles = '0';
|
||||
|
||||
$inventory = $mapper->map($this->makeSoapResponse(), $message);
|
||||
|
||||
self::assertFalse($inventory->includesEarTagStock);
|
||||
}
|
||||
|
||||
public function testMapInventoryWithDateFinAbsentYieldsNullEndDate(): void
|
||||
{
|
||||
$mapper = new InventoryMapper(new AnimalSummaryMapper(), new StandardResponseMapper());
|
||||
|
||||
$message = new stdClass();
|
||||
$message->InformationsMessage = new stdClass();
|
||||
$message->InformationsMessage->DateDebut = '2026-01-01';
|
||||
// DateFin deliberately omitted
|
||||
|
||||
$inventory = $mapper->map($this->makeSoapResponse(), $message);
|
||||
|
||||
self::assertNull($inventory->endDate);
|
||||
}
|
||||
|
||||
public function testMapInventoryWithSerieBouclesAsListPreservesAllEntries(): void
|
||||
{
|
||||
$mapper = new InventoryMapper(new AnimalSummaryMapper(), new StandardResponseMapper());
|
||||
|
||||
$serie1 = new stdClass();
|
||||
$serie1->NumeroSerieDebut = 'A0001';
|
||||
$serie2 = new stdClass();
|
||||
$serie2->NumeroSerieDebut = 'B0001';
|
||||
|
||||
$message = new stdClass();
|
||||
$message->Boucles = new stdClass();
|
||||
$message->Boucles->SerieBoucles = [$serie1, $serie2];
|
||||
|
||||
$inventory = $mapper->map($this->makeSoapResponse(), $message);
|
||||
|
||||
self::assertCount(2, $inventory->earTagSeries);
|
||||
self::assertSame('A0001', $inventory->earTagSeries[0]->rawNode->NumeroSerieDebut);
|
||||
self::assertSame('B0001', $inventory->earTagSeries[1]->rawNode->NumeroSerieDebut);
|
||||
}
|
||||
|
||||
public function testMapInventoryWithMissingNbBovinsDefaultsToZero(): void
|
||||
{
|
||||
$mapper = new InventoryMapper(new AnimalSummaryMapper(), new StandardResponseMapper());
|
||||
|
||||
$soapResponse = new stdClass();
|
||||
$soapResponse->ReponseStandard = new stdClass();
|
||||
$soapResponse->ReponseStandard->Resultat = true;
|
||||
$soapResponse->ReponseSpecifique = new stdClass();
|
||||
// NbBovins deliberately omitted
|
||||
|
||||
$inventory = $mapper->map($soapResponse, null);
|
||||
|
||||
self::assertSame(0, $inventory->nbBovins);
|
||||
}
|
||||
```
|
||||
|
||||
**Rappel sur les imports** : le fichier importe déjà `DateTimeImmutable`, `InventoryDto`, `AnimalSummaryMapper`, `InventoryMapper`, `StandardResponseMapper`, `stdClass`, `TestCase`, `CoversClass`. **Aucun import supplémentaire nécessaire** pour ces 5 nouveaux tests.
|
||||
|
||||
- [ ] **Step 2: Ajouter le docblock à `EarTagSeriesDto`**
|
||||
|
||||
Ouvrir `src/Bovin/Dto/EarTagSeriesDto.php` et remplacer son contenu par :
|
||||
```php
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Malio\EdnotifBundle\Bovin\Dto;
|
||||
|
||||
/**
|
||||
* Wrapper minimal d'une entrée `SerieBoucles` du message de l'opération
|
||||
* `IpBGetInventaire` (quand `includeEarTagStock: true`).
|
||||
*
|
||||
* Le noeud XSD `typeSerieBoucles` est riche (plages de numéros, fournisseur,
|
||||
* statut, dates...). En Phase 1 on garde volontairement la structure brute
|
||||
* via `$rawNode` : les consommateurs qui ont besoin d'un champ précis y
|
||||
* accèdent par `$serie->rawNode->NomDuChamp`. Si un cas d'usage métier concret
|
||||
* remonte (rebouclage, commande de boucles), on parsera dans un DTO dédié.
|
||||
*/
|
||||
final readonly class EarTagSeriesDto
|
||||
{
|
||||
public function __construct(
|
||||
public object $rawNode,
|
||||
) {}
|
||||
}
|
||||
```
|
||||
|
||||
- [ ] **Step 3: Lancer la suite complète**
|
||||
|
||||
Run:
|
||||
```
|
||||
make test
|
||||
```
|
||||
Expected : tous les tests verts, incluant les 5 nouveaux.
|
||||
|
||||
Compte attendu : `OK (N tests, M assertions)` avec `N` = total précédent de la suite + 5.
|
||||
|
||||
- [ ] **Step 4: Commit**
|
||||
|
||||
Run:
|
||||
```
|
||||
git add tests/Unit/Bovin/Mapper/InventoryMapperTest.php src/Bovin/Dto/EarTagSeriesDto.php
|
||||
git commit -m "test : tests adversariaux InventoryMapper + docblock EarTagSeriesDto"
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Checklist finale
|
||||
|
||||
- [ ] `make test` vert sur toute la suite (tous les nouveaux tests + les tests préexistants de Phase 1)
|
||||
- [ ] 2 commits propres, un par task
|
||||
- [ ] `BovinNodeMappingTrait` reste inchangé (seule une classe adapter de test le consomme avec re-exposition publique)
|
||||
- [ ] `InventoryMapper` reste inchangé (uniquement de nouveaux tests qui exercent son code existant)
|
||||
- [ ] `EarTagSeriesDto` gagne seulement un docblock, pas de changement de comportement
|
||||
188
docs/ws-catalog.md
Normal file
188
docs/ws-catalog.md
Normal file
@@ -0,0 +1,188 @@
|
||||
# Catalogue des WebServices EDNOTIF
|
||||
|
||||
Inventaire des opérations exposées par les WSDL embarqués dans
|
||||
`resources/ednotif-ws/`, avec le statut d'implémentation et une
|
||||
recommandation de priorisation.
|
||||
|
||||
## Légende statut
|
||||
|
||||
- **Implémenté** — opération couverte par le bundle
|
||||
- **À faire** — opération pertinente non encore implémentée
|
||||
- **Optionnel** — opération hors périmètre probable, à confirmer selon le consommateur
|
||||
|
||||
---
|
||||
|
||||
## 1. wsIpBNotif — Notifications IPG Bovin
|
||||
|
||||
WS métier principal : déclarations réglementaires d'un cheptel bovin auprès de l'IPG.
|
||||
|
||||
### Lecture
|
||||
|
||||
| Opération | Statut | Description probable |
|
||||
|---|---|---|
|
||||
| `IpBGetDossierAnimal` | Implémenté | Dossier complet d'un bovin (identifications, mouvements, parents…) |
|
||||
| `IpBGetInventaire` | Implémenté | Inventaire des animaux présents sur l'exploitation |
|
||||
| `IpBGetRetourDossiers` | Implémenté | Retours de traitement des notifications envoyées |
|
||||
| `IpBGetSortiesPresumees` | Implémenté | Animaux sortis selon l'IPG mais non déclarés par l'éleveur |
|
||||
|
||||
### Écriture
|
||||
|
||||
| Opération | Statut | Description probable |
|
||||
|---|---|---|
|
||||
| `IpBCreateEntree` | À faire | Déclaration d'entrée d'un bovin sur l'exploitation |
|
||||
| `IpBCreateSortie` | À faire | Déclaration de sortie (vente, mort, abattage…) |
|
||||
| `IpBCreateNaissance` | À faire | Déclaration de naissance |
|
||||
| `IpBCreateMortNe` | À faire | Déclaration de mort-né |
|
||||
| `IpBCreateAnimalEchange` | À faire | Échange intra-UE |
|
||||
| `IpBCreateAnimalImporte` | À faire | Import pays tiers |
|
||||
| `IpBCreateAvisAnimalImporte` | À faire | Avis d'import |
|
||||
| `IpBCreateRebouclage` | À faire | Rebouclage / remplacement de boucle |
|
||||
| `IpBCreateCommandeBoucles` | À faire | Commande de boucles |
|
||||
| `IpBCreateInsemination` | À faire | Déclaration d'insémination |
|
||||
|
||||
---
|
||||
|
||||
## 2. wsDmB\* — Déclarations de Mouvement Bovin
|
||||
|
||||
Famille orientée gestion des mouvements / transporteurs.
|
||||
|
||||
### wsDmBConsultation
|
||||
- `DmBConsultationGetListeDonneesIT` — consultation de données (IT = identifiants traces ?)
|
||||
- `DmBConsultationGetListeStatutDeplacement` — statuts de déplacement
|
||||
|
||||
### wsDmBGestion
|
||||
- `DmBGestionCreateDroitAccesListeAnimalActeur` — gestion droits d'accès
|
||||
- `DmBGestionCreateListeICA` — création listes ICA (information chaîne alimentaire)
|
||||
|
||||
### wsDmBListe
|
||||
- `DmBListeCreateListeBovins` / `DmBListeGetListeBovins` — listes de bovins (lots)
|
||||
|
||||
### wsDmBTransport
|
||||
- `DmBTransportCreateChargement` — chargement camion
|
||||
- `DmBTransportCreateDechargement` — déchargement camion
|
||||
|
||||
---
|
||||
|
||||
## 3. wsMdBEdel — Maîtrise des Données Bovin (Edel)
|
||||
|
||||
Consultation en lecture seule : génétique, lactation, IA, races.
|
||||
|
||||
| Opération | Rôle |
|
||||
|---|---|
|
||||
| `MdBGetDonneesGenetiquesAnimales` | Données génétiques d'animaux |
|
||||
| `MdBGetDonneesMalesPublics` | Catalogue mâles reproducteurs publics |
|
||||
| `MdBGetDonneesOrganismeHabilite` | Référentiel organismes habilités |
|
||||
| `MdBGetDonneesOrganismeTiers` | Référentiel organismes tiers |
|
||||
| `ClBGetDonneesCL` | Contrôle laitier |
|
||||
| `CpBGetDonneesCPB` | Contrôle de performances bouchères |
|
||||
| `IaBGetDonneesIA` | Données d'insémination |
|
||||
| `OsBGetDonneesRAC` | Données race (RAC = race certifiée ?) |
|
||||
| `TkBGetDonneesTE` | Transfert embryonnaire |
|
||||
| `VaBGetDonneesCPV` | Contrôle performances veaux (?) |
|
||||
|
||||
---
|
||||
|
||||
## 4. wsMdCEdel — Maîtrise des Données Caprin
|
||||
|
||||
Équivalent caprin : CRUD + reproduction + lactation. 15 opérations (`MdCCreate*` pour l'écriture, `MdCGet*` avec variantes `MAJ` pour les deltas).
|
||||
|
||||
| Groupe | Opérations |
|
||||
|---|---|
|
||||
| Caprin | `MdCCreateCaprin`, `MdCGetDonneesCaprin`, `MdCGetDonneesCaprinMAJ` |
|
||||
| Reproduction | `MdCCreateSaillie`, `MdCCreateFinGestation`, `MdCGetFinGestation[/MAJ]`, `MdCGetEvenementReproduction[/MAJ]` |
|
||||
| Mouvement | `MdCCreateMouvement` |
|
||||
| Contrôle laitier | `MdCGetCLDonneesBrutes[/MAJ]`, `MdCGetCLDonneesElaborees[/MAJ]` |
|
||||
| Contrats | `MdCGetContratsExploitation` |
|
||||
|
||||
---
|
||||
|
||||
## 5. wsIpEdel — Identification Pérenne Edel
|
||||
|
||||
- `IpGetDonneesExploitation` — données descriptives de l'exploitation
|
||||
|
||||
---
|
||||
|
||||
## 6. wsMrAde — Échanges ICAR
|
||||
|
||||
Conforme aux standards ICAR (flux laitiers internationaux).
|
||||
|
||||
- `GetHerdList`
|
||||
- `UpdateAnimal`
|
||||
- `UpdateDevice`
|
||||
- `UpdateLivestockLocation`
|
||||
- `UpdateMilkingResults`
|
||||
|
||||
---
|
||||
|
||||
## 7. WsAnnuaire — Annuaire Guichet
|
||||
|
||||
Métadonnées techniques du guichet (pas du métier).
|
||||
|
||||
- `tkGetServices` — liste des WS disponibles
|
||||
- `tkGetVersionsService` — versions d'un WS
|
||||
- `tkGetOperationsServiceVersion` — opérations d'une version
|
||||
- `tkGetUrl` — URL d'un service
|
||||
|
||||
---
|
||||
|
||||
## Recommandation de priorisation
|
||||
|
||||
Proposition d'ordre, à valider selon le périmètre réel du consommateur.
|
||||
|
||||
### Phase 1 — Compléter le bovin (priorité haute)
|
||||
Continuer sur **wsIpBNotif**, en commençant par la **lecture** :
|
||||
|
||||
1. `IpBGetInventaire` — donne immédiatement la liste du cheptel, utile pour toute UI
|
||||
2. `IpBGetRetourDossiers` — indispensable pour savoir si les notifs passent côté IPG
|
||||
3. `IpBGetSortiesPresumees` — flux de rapprochement éleveur ↔ IPG
|
||||
|
||||
**Raison** : le dossier animal seul est peu utile sans l'inventaire qui permet de savoir *pour quels animaux* appeler `getAnimalFile`. Et sans `RetourDossiers`, toute écriture future est aveugle.
|
||||
|
||||
### Phase 2 — Écriture bovin (notifications obligatoires)
|
||||
Implémenter les déclarations **dans l'ordre des cycles de vie d'un animal** :
|
||||
|
||||
4. `IpBCreateNaissance`
|
||||
5. `IpBCreateEntree` / `IpBCreateSortie`
|
||||
6. `IpBCreateMortNe`
|
||||
7. `IpBCreateRebouclage` / `IpBCreateCommandeBoucles`
|
||||
8. `IpBCreateAnimalEchange` / `IpBCreateAnimalImporte` / `IpBCreateAvisAnimalImporte` (si imports/échanges dans le périmètre)
|
||||
9. `IpBCreateInsemination` (si non couvert par un autre outil)
|
||||
|
||||
### Phase 3 — Mouvements / transport
|
||||
Si le consommateur gère du transport ou des lots :
|
||||
|
||||
10. `wsDmBListe` (lots bovins)
|
||||
11. `wsDmBTransport` (chargement/déchargement)
|
||||
12. `wsDmBConsultation` et `wsDmBGestion` selon besoin
|
||||
|
||||
### Phase 4 — Référentiels génétiques (optionnel)
|
||||
Si le consommateur fait de la sélection / génétique :
|
||||
|
||||
13. `wsMdBEdel` — lectures ponctuelles, ne justifient une implémentation que s'il y a un usage métier concret
|
||||
|
||||
### Phase 5 — Caprin / ICAR (optionnel)
|
||||
À activer uniquement si multi-espèces ou conformité ICAR requise.
|
||||
|
||||
### Hors priorité
|
||||
- **wsIpEdel** : 1 op, à implémenter *en passant* si besoin ponctuel
|
||||
- **WsAnnuaire** : utile pour du diagnostic / supervision, pas pour le métier
|
||||
|
||||
---
|
||||
|
||||
## Découpage structurel proposé
|
||||
|
||||
Pour garder un code cohérent, reproduire le pattern existant (`src/Bovin/`) par domaine :
|
||||
|
||||
```
|
||||
src/
|
||||
├── Auth/ (existant)
|
||||
├── Bovin/ (IpBNotif + IpEdel exploitation)
|
||||
├── Mouvement/ (DmB*)
|
||||
├── Genetique/ (MdBEdel, optionnel)
|
||||
├── Caprin/ (MdCEdel, optionnel)
|
||||
├── Icar/ (MrAde, optionnel)
|
||||
├── Annuaire/ (WsAnnuaire, optionnel)
|
||||
└── Shared/ (existant)
|
||||
```
|
||||
|
||||
Chaque domaine expose une `*ApiInterface` publique + une implémentation `readonly`, avec ses DTOs et mappers dédiés. Le `TokenProvider` et `SoapClientFactory` restent partagés via `Shared/`.
|
||||
5
makefile
5
makefile
@@ -87,3 +87,8 @@ php-cs-fixer-allow-risky:
|
||||
|
||||
wait:
|
||||
sleep 10
|
||||
|
||||
# Lance la suite PHPUnit. Usage : make test (tout)
|
||||
# make test FILES=<path> (un fichier/dossier)
|
||||
test:
|
||||
$(EXEC_PHP) php vendor/bin/phpunit $(FILES)
|
||||
19
phpunit.xml.dist
Normal file
19
phpunit.xml.dist
Normal file
@@ -0,0 +1,19 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
|
||||
bootstrap="tests/bootstrap.php"
|
||||
colors="true"
|
||||
failOnWarning="true"
|
||||
failOnRisky="true"
|
||||
cacheDirectory=".phpunit.cache">
|
||||
<testsuites>
|
||||
<testsuite name="Unit">
|
||||
<directory>tests/Unit</directory>
|
||||
</testsuite>
|
||||
</testsuites>
|
||||
<source>
|
||||
<include>
|
||||
<directory>src</directory>
|
||||
</include>
|
||||
</source>
|
||||
</phpunit>
|
||||
@@ -4,10 +4,18 @@ declare(strict_types=1);
|
||||
|
||||
namespace Malio\EdnotifBundle\Bovin\Api;
|
||||
|
||||
use DateTimeInterface;
|
||||
use Malio\EdnotifBundle\Auth\TokenProvider;
|
||||
use Malio\EdnotifBundle\Bovin\Dto\AnimalFileDto;
|
||||
use Malio\EdnotifBundle\Bovin\Dto\InventoryDto;
|
||||
use Malio\EdnotifBundle\Bovin\Dto\PresumedExitsDto;
|
||||
use Malio\EdnotifBundle\Bovin\Dto\ReturnedDossiersDto;
|
||||
use Malio\EdnotifBundle\Bovin\Mapper\AnimalFileMapper;
|
||||
use Malio\EdnotifBundle\Bovin\Mapper\InventoryMapper;
|
||||
use Malio\EdnotifBundle\Bovin\Mapper\PresumedExitsMapper;
|
||||
use Malio\EdnotifBundle\Bovin\Mapper\ReturnedDossiersMapper;
|
||||
use Malio\EdnotifBundle\Shared\Exception\EdnotifException;
|
||||
use Malio\EdnotifBundle\Shared\Soap\ZipMessageDecoder;
|
||||
use RuntimeException;
|
||||
use SoapClient;
|
||||
use SoapFault;
|
||||
@@ -18,6 +26,10 @@ final readonly class BovinApi implements BovinApiInterface
|
||||
private TokenProvider $tokenProvider,
|
||||
private SoapClient $businessClient,
|
||||
private AnimalFileMapper $bovinDossierMapper,
|
||||
private InventoryMapper $inventoryMapper,
|
||||
private ReturnedDossiersMapper $returnedDossiersMapper,
|
||||
private PresumedExitsMapper $presumedExitsMapper,
|
||||
private ZipMessageDecoder $zipMessageDecoder,
|
||||
private string $exploitationCountryCode,
|
||||
private string $exploitationNumber,
|
||||
) {}
|
||||
@@ -45,20 +57,122 @@ final readonly class BovinApi implements BovinApiInterface
|
||||
throw new RuntimeException('SOAP Fault on IpBGetDossierAnimal: '.$soapFault->getMessage(), 0, $soapFault);
|
||||
}
|
||||
|
||||
// Throw uniquement si Resultat=false (erreur métier)
|
||||
$standardResponseNode = $soapResponse->ReponseStandard ?? null;
|
||||
$isOk = is_object($standardResponseNode) && (($standardResponseNode->Resultat ?? false) === true);
|
||||
|
||||
if (!$isOk) {
|
||||
$anomalyNode = is_object($standardResponseNode) ? ($standardResponseNode->Anomalie ?? null) : null;
|
||||
|
||||
throw new EdnotifException(
|
||||
codeAnomalie: (string) ($anomalyNode->Code ?? 'UNKNOWN'),
|
||||
severite: (int) ($anomalyNode->Severite ?? 1),
|
||||
message: (string) ($anomalyNode->Message ?? 'EDNOTIF error')
|
||||
);
|
||||
}
|
||||
$this->assertSuccessfulResponse($soapResponse, 'IpBGetDossierAnimal');
|
||||
|
||||
return $this->bovinDossierMapper->map($soapResponse);
|
||||
}
|
||||
|
||||
public function getInventory(
|
||||
DateTimeInterface $startDate,
|
||||
?DateTimeInterface $endDate = null,
|
||||
bool $includeEarTagStock = false,
|
||||
): InventoryDto {
|
||||
$token = $this->tokenProvider->getToken();
|
||||
|
||||
$payload = [
|
||||
'JetonAuthentification' => $token,
|
||||
'Exploitation' => [
|
||||
'CodePays' => $this->exploitationCountryCode,
|
||||
'NumeroExploitation' => $this->exploitationNumber,
|
||||
],
|
||||
'DateDebut' => $startDate->format('Y-m-d'),
|
||||
'StockBoucles' => $includeEarTagStock,
|
||||
];
|
||||
if (null !== $endDate) {
|
||||
$payload['DateFin'] = $endDate->format('Y-m-d');
|
||||
}
|
||||
|
||||
try {
|
||||
/** @var object $soapResponse */
|
||||
$soapResponse = $this->businessClient->__soapCall('IpBGetInventaire', [$payload]);
|
||||
} catch (SoapFault $soapFault) {
|
||||
throw new RuntimeException('SOAP Fault on IpBGetInventaire: '.$soapFault->getMessage(), 0, $soapFault);
|
||||
}
|
||||
|
||||
$this->assertSuccessfulResponse($soapResponse, 'IpBGetInventaire');
|
||||
|
||||
$messageZip = $soapResponse->ReponseSpecifique->MessageZip ?? null;
|
||||
$unzippedMessage = is_string($messageZip) && '' !== $messageZip
|
||||
? $this->zipMessageDecoder->decode($messageZip)
|
||||
: null;
|
||||
|
||||
return $this->inventoryMapper->map($soapResponse, $unzippedMessage);
|
||||
}
|
||||
|
||||
public function getReturnedDossiers(DateTimeInterface $startDate): ReturnedDossiersDto
|
||||
{
|
||||
$token = $this->tokenProvider->getToken();
|
||||
|
||||
$payload = [
|
||||
'JetonAuthentification' => $token,
|
||||
'Exploitation' => [
|
||||
'CodePays' => $this->exploitationCountryCode,
|
||||
'NumeroExploitation' => $this->exploitationNumber,
|
||||
],
|
||||
'DateDebut' => $startDate->format('Y-m-d'),
|
||||
];
|
||||
|
||||
try {
|
||||
/** @var object $soapResponse */
|
||||
$soapResponse = $this->businessClient->__soapCall('IpBGetRetourDossiers', [$payload]);
|
||||
} catch (SoapFault $soapFault) {
|
||||
throw new RuntimeException('SOAP Fault on IpBGetRetourDossiers: '.$soapFault->getMessage(), 0, $soapFault);
|
||||
}
|
||||
|
||||
$this->assertSuccessfulResponse($soapResponse, 'IpBGetRetourDossiers');
|
||||
|
||||
$messageZip = $soapResponse->ReponseSpecifique->MessageZip ?? null;
|
||||
$unzippedMessage = is_string($messageZip) && '' !== $messageZip
|
||||
? $this->zipMessageDecoder->decode($messageZip)
|
||||
: null;
|
||||
|
||||
return $this->returnedDossiersMapper->map($soapResponse, $unzippedMessage);
|
||||
}
|
||||
|
||||
public function getPresumedExits(): PresumedExitsDto
|
||||
{
|
||||
$token = $this->tokenProvider->getToken();
|
||||
|
||||
$payload = [
|
||||
'JetonAuthentification' => $token,
|
||||
'Exploitation' => [
|
||||
'CodePays' => $this->exploitationCountryCode,
|
||||
'NumeroExploitation' => $this->exploitationNumber,
|
||||
],
|
||||
];
|
||||
|
||||
try {
|
||||
/** @var object $soapResponse */
|
||||
$soapResponse = $this->businessClient->__soapCall('IpBGetSortiesPresumees', [$payload]);
|
||||
} catch (SoapFault $soapFault) {
|
||||
throw new RuntimeException('SOAP Fault on IpBGetSortiesPresumees: '.$soapFault->getMessage(), 0, $soapFault);
|
||||
}
|
||||
|
||||
$this->assertSuccessfulResponse($soapResponse, 'IpBGetSortiesPresumees');
|
||||
|
||||
$messageZip = $soapResponse->ReponseSpecifique->MessageZip ?? null;
|
||||
$unzippedMessage = is_string($messageZip) && '' !== $messageZip
|
||||
? $this->zipMessageDecoder->decode($messageZip)
|
||||
: null;
|
||||
|
||||
return $this->presumedExitsMapper->map($soapResponse, $unzippedMessage);
|
||||
}
|
||||
|
||||
private function assertSuccessfulResponse(object $soapResponse, string $operation): void
|
||||
{
|
||||
$standardResponseNode = $soapResponse->ReponseStandard ?? null;
|
||||
$isOk = is_object($standardResponseNode) && (($standardResponseNode->Resultat ?? false) === true);
|
||||
|
||||
if ($isOk) {
|
||||
return;
|
||||
}
|
||||
|
||||
$anomalyNode = is_object($standardResponseNode) ? ($standardResponseNode->Anomalie ?? null) : null;
|
||||
|
||||
throw new EdnotifException(
|
||||
codeAnomalie: (string) ($anomalyNode->Code ?? 'UNKNOWN'),
|
||||
severite: (int) ($anomalyNode->Severite ?? 1),
|
||||
message: (string) ($anomalyNode->Message ?? $operation.' : EDNOTIF error')
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,9 +4,23 @@ declare(strict_types=1);
|
||||
|
||||
namespace Malio\EdnotifBundle\Bovin\Api;
|
||||
|
||||
use DateTimeInterface;
|
||||
use Malio\EdnotifBundle\Bovin\Dto\AnimalFileDto;
|
||||
use Malio\EdnotifBundle\Bovin\Dto\InventoryDto;
|
||||
use Malio\EdnotifBundle\Bovin\Dto\PresumedExitsDto;
|
||||
use Malio\EdnotifBundle\Bovin\Dto\ReturnedDossiersDto;
|
||||
|
||||
interface BovinApiInterface
|
||||
{
|
||||
public function getAnimalFile(string $nationalNumber, string $countryCode = 'FR'): AnimalFileDto;
|
||||
|
||||
public function getInventory(
|
||||
DateTimeInterface $startDate,
|
||||
?DateTimeInterface $endDate = null,
|
||||
bool $includeEarTagStock = false,
|
||||
): InventoryDto;
|
||||
|
||||
public function getReturnedDossiers(DateTimeInterface $startDate): ReturnedDossiersDto;
|
||||
|
||||
public function getPresumedExits(): PresumedExitsDto;
|
||||
}
|
||||
|
||||
16
src/Bovin/Dto/AnimalSummaryDto.php
Normal file
16
src/Bovin/Dto/AnimalSummaryDto.php
Normal file
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Malio\EdnotifBundle\Bovin\Dto;
|
||||
|
||||
final readonly class AnimalSummaryDto
|
||||
{
|
||||
/**
|
||||
* @param list<PresencePeriodDto> $presencePeriods
|
||||
*/
|
||||
public function __construct(
|
||||
public ?BovinIdentificationDto $identification,
|
||||
public array $presencePeriods,
|
||||
) {}
|
||||
}
|
||||
22
src/Bovin/Dto/EarTagSeriesDto.php
Normal file
22
src/Bovin/Dto/EarTagSeriesDto.php
Normal file
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Malio\EdnotifBundle\Bovin\Dto;
|
||||
|
||||
/**
|
||||
* Wrapper minimal d'une entrée `SerieBoucles` du message de l'opération
|
||||
* `IpBGetInventaire` (quand `includeEarTagStock: true`).
|
||||
*
|
||||
* Le noeud XSD `typeSerieBoucles` est riche (plages de numéros, fournisseur,
|
||||
* statut, dates...). En Phase 1 on garde volontairement la structure brute
|
||||
* via `$rawNode` : les consommateurs qui ont besoin d'un champ précis y
|
||||
* accèdent par `$serie->rawNode->NomDuChamp`. Si un cas d'usage métier concret
|
||||
* remonte (rebouclage, commande de boucles), on parsera dans un DTO dédié.
|
||||
*/
|
||||
final readonly class EarTagSeriesDto
|
||||
{
|
||||
public function __construct(
|
||||
public object $rawNode,
|
||||
) {}
|
||||
}
|
||||
26
src/Bovin/Dto/InventoryDto.php
Normal file
26
src/Bovin/Dto/InventoryDto.php
Normal file
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Malio\EdnotifBundle\Bovin\Dto;
|
||||
|
||||
use DateTimeImmutable;
|
||||
use Malio\EdnotifBundle\Shared\Dto\StandardResponseDto;
|
||||
|
||||
final readonly class InventoryDto
|
||||
{
|
||||
/**
|
||||
* @param list<AnimalSummaryDto> $animals
|
||||
* @param list<EarTagSeriesDto> $earTagSeries
|
||||
*/
|
||||
public function __construct(
|
||||
public StandardResponseDto $standardResponse,
|
||||
public int $nbBovins,
|
||||
public ?DateTimeImmutable $startDate,
|
||||
public ?DateTimeImmutable $endDate,
|
||||
public ?bool $includesEarTagStock,
|
||||
public array $animals,
|
||||
public array $earTagSeries,
|
||||
public ?object $rawSoapResponse,
|
||||
) {}
|
||||
}
|
||||
15
src/Bovin/Dto/PresumedExitDto.php
Normal file
15
src/Bovin/Dto/PresumedExitDto.php
Normal file
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Malio\EdnotifBundle\Bovin\Dto;
|
||||
|
||||
use DateTimeImmutable;
|
||||
|
||||
final readonly class PresumedExitDto
|
||||
{
|
||||
public function __construct(
|
||||
public ?BovinRef $bovin,
|
||||
public ?DateTimeImmutable $exitDate,
|
||||
) {}
|
||||
}
|
||||
20
src/Bovin/Dto/PresumedExitsDto.php
Normal file
20
src/Bovin/Dto/PresumedExitsDto.php
Normal file
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Malio\EdnotifBundle\Bovin\Dto;
|
||||
|
||||
use Malio\EdnotifBundle\Shared\Dto\StandardResponseDto;
|
||||
|
||||
final readonly class PresumedExitsDto
|
||||
{
|
||||
/**
|
||||
* @param list<PresumedExitDto> $presumedExits
|
||||
*/
|
||||
public function __construct(
|
||||
public StandardResponseDto $standardResponse,
|
||||
public int $nbBovins,
|
||||
public array $presumedExits,
|
||||
public ?object $rawSoapResponse,
|
||||
) {}
|
||||
}
|
||||
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,
|
||||
) {}
|
||||
}
|
||||
@@ -4,24 +4,20 @@ declare(strict_types=1);
|
||||
|
||||
namespace Malio\EdnotifBundle\Bovin\Mapper;
|
||||
|
||||
use DateTimeImmutable;
|
||||
use Malio\EdnotifBundle\Bovin\Dto\AnimalFileDto;
|
||||
use Malio\EdnotifBundle\Bovin\Dto\BovinIdentificationDto;
|
||||
use Malio\EdnotifBundle\Bovin\Dto\BovinRef;
|
||||
use Malio\EdnotifBundle\Bovin\Dto\DateValueDto;
|
||||
use Malio\EdnotifBundle\Bovin\Dto\ExploitationRef;
|
||||
use Malio\EdnotifBundle\Bovin\Dto\MovementDto;
|
||||
use Malio\EdnotifBundle\Bovin\Dto\ParentInfoDto;
|
||||
use Malio\EdnotifBundle\Bovin\Dto\PresencePeriodDto;
|
||||
use Malio\EdnotifBundle\Shared\Dto\AnomalyDto;
|
||||
use Malio\EdnotifBundle\Shared\Dto\StandardResponseDto;
|
||||
use Throwable;
|
||||
use Malio\EdnotifBundle\Shared\Mapper\StandardResponseMapper;
|
||||
|
||||
final class AnimalFileMapper
|
||||
{
|
||||
use BovinNodeMappingTrait;
|
||||
|
||||
public function __construct(
|
||||
private readonly StandardResponseMapper $standardResponseMapper,
|
||||
) {}
|
||||
|
||||
public function map(object $soapResponse): AnimalFileDto
|
||||
{
|
||||
$standardResponse = $this->mapStandardResponse($soapResponse->ReponseStandard ?? null);
|
||||
$standardResponse = $this->standardResponseMapper->map($soapResponse->ReponseStandard ?? null);
|
||||
|
||||
$specificResponseNode = $soapResponse->ReponseSpecifique ?? null;
|
||||
$bovinNode = is_object($specificResponseNode) ? ($specificResponseNode->Bovin ?? null) : null;
|
||||
@@ -51,185 +47,4 @@ final class AnimalFileMapper
|
||||
rawSoapResponse: $soapResponse
|
||||
);
|
||||
}
|
||||
|
||||
private function mapStandardResponse(mixed $standardResponseNode): StandardResponseDto
|
||||
{
|
||||
$result = (bool) ($standardResponseNode->Resultat ?? false);
|
||||
|
||||
$anomalyNode = $standardResponseNode->Anomalie ?? null;
|
||||
$anomaly = null;
|
||||
|
||||
if (is_object($anomalyNode)) {
|
||||
$anomaly = new AnomalyDto(
|
||||
code: $this->toNullableString($anomalyNode->Code ?? null),
|
||||
severity: $this->toNullableInt($anomalyNode->Severite ?? null),
|
||||
message: $this->toNullableString($anomalyNode->Message ?? null),
|
||||
);
|
||||
}
|
||||
|
||||
return new StandardResponseDto($result, $anomaly);
|
||||
}
|
||||
|
||||
private function mapIdentification(object $identificationNode): BovinIdentificationDto
|
||||
{
|
||||
$bovinRef = $this->mapBovinRef($identificationNode->Bovin ?? null);
|
||||
|
||||
$birthDate = null;
|
||||
$birthDateNode = $identificationNode->DateNaissance ?? null;
|
||||
if (is_object($birthDateNode)) {
|
||||
$birthDate = new DateValueDto(
|
||||
date: $this->toNullableDate($birthDateNode->Date ?? null),
|
||||
completenessFlag: $this->toNullableString($birthDateNode->TemoinCompletude ?? null),
|
||||
);
|
||||
}
|
||||
|
||||
$motherCarrier = $this->mapParentInfo($identificationNode->MerePorteuse ?? null);
|
||||
$fatherIpg = $this->mapParentInfo($identificationNode->PereIPG ?? null);
|
||||
$birthExploitation = $this->mapExploitationRef($identificationNode->ExploitationNaissance ?? null);
|
||||
|
||||
return new BovinIdentificationDto(
|
||||
bovin: $bovinRef,
|
||||
sex: $this->toNullableString($identificationNode->Sexe ?? null),
|
||||
breedType: $this->toNullableString($identificationNode->TypeRacial ?? null),
|
||||
birthDate: $birthDate,
|
||||
workNumber: $this->toNullableString($identificationNode->NumeroTravail ?? null),
|
||||
isFilie: $this->toNullableBool($identificationNode->StatutFilie ?? null),
|
||||
motherCarrier: $motherCarrier,
|
||||
fatherIpg: $fatherIpg,
|
||||
birthExploitation: $birthExploitation,
|
||||
);
|
||||
}
|
||||
|
||||
private function mapPresencePeriod(object $presencePeriodNode): PresencePeriodDto
|
||||
{
|
||||
$entryNode = $presencePeriodNode->Entree ?? null;
|
||||
$exitNode = $presencePeriodNode->Sortie ?? null;
|
||||
|
||||
$entryMovement = is_object($entryNode) ? $this->mapMovement($entryNode, 'entry') : null;
|
||||
$exitMovement = is_object($exitNode) ? $this->mapMovement($exitNode, 'exit') : null;
|
||||
|
||||
return new PresencePeriodDto(
|
||||
entry: $entryMovement,
|
||||
exit: $exitMovement,
|
||||
);
|
||||
}
|
||||
|
||||
private function mapMovement(object $movementNode, string $direction): MovementDto
|
||||
{
|
||||
$dateValue = null;
|
||||
$causeValue = null;
|
||||
|
||||
if ('entry' === $direction) {
|
||||
// SOAP: DateEntree / CauseEntree
|
||||
$dateValue = $movementNode->DateEntree ?? ($movementNode->Date ?? ($movementNode->DateMouvement ?? null));
|
||||
$causeValue = $movementNode->CauseEntree ?? null;
|
||||
} else {
|
||||
// SOAP (souvent): DateSortie / CauseSortie
|
||||
$dateValue = $movementNode->DateSortie ?? ($movementNode->Date ?? ($movementNode->DateMouvement ?? null));
|
||||
$causeValue = $movementNode->CauseSortie ?? null;
|
||||
}
|
||||
|
||||
$exploitationRef = $this->mapExploitationRef($movementNode->Exploitation ?? null);
|
||||
|
||||
return new MovementDto(
|
||||
date: $this->toNullableDate($dateValue),
|
||||
cause: $this->toNullableString($causeValue),
|
||||
exploitation: $exploitationRef,
|
||||
);
|
||||
}
|
||||
|
||||
private function mapParentInfo(mixed $parentNode): ?ParentInfoDto
|
||||
{
|
||||
if (!is_object($parentNode)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$bovinRef = $this->mapBovinRef($parentNode->Bovin ?? null);
|
||||
|
||||
return new ParentInfoDto(
|
||||
bovin: $bovinRef,
|
||||
breedType: $this->toNullableString($parentNode->TypeRacial ?? null),
|
||||
);
|
||||
}
|
||||
|
||||
private function mapBovinRef(mixed $bovinNode): ?BovinRef
|
||||
{
|
||||
if (!is_object($bovinNode)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return new BovinRef(
|
||||
countryCode: $this->toNullableString($bovinNode->CodePays ?? null),
|
||||
nationalNumber: $this->toNullableString($bovinNode->NumeroNational ?? null),
|
||||
);
|
||||
}
|
||||
|
||||
private function mapExploitationRef(mixed $exploitationNode): ?ExploitationRef
|
||||
{
|
||||
if (!is_object($exploitationNode)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return new ExploitationRef(
|
||||
countryCode: $this->toNullableString($exploitationNode->CodePays ?? null),
|
||||
exploitationNumber: $this->toNullableString($exploitationNode->NumeroExploitation ?? null),
|
||||
);
|
||||
}
|
||||
|
||||
/** @return list<mixed> */
|
||||
private function normalizeToList(mixed $value): array
|
||||
{
|
||||
if (null === $value) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return is_array($value) ? $value : [$value];
|
||||
}
|
||||
|
||||
private function toNullableString(mixed $value): ?string
|
||||
{
|
||||
if (null === $value) {
|
||||
return null;
|
||||
}
|
||||
$stringValue = trim((string) $value);
|
||||
|
||||
return '' === $stringValue ? null : $stringValue;
|
||||
}
|
||||
|
||||
private function toNullableInt(mixed $value): ?int
|
||||
{
|
||||
if (null === $value) {
|
||||
return null;
|
||||
}
|
||||
if (is_int($value)) {
|
||||
return $value;
|
||||
}
|
||||
if (is_numeric($value)) {
|
||||
return (int) $value;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private function toNullableBool(mixed $value): ?bool
|
||||
{
|
||||
if (null === $value) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (bool) $value;
|
||||
}
|
||||
|
||||
private function toNullableDate(mixed $value): ?DateTimeImmutable
|
||||
{
|
||||
if (!is_string($value) || '' === trim($value)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
return new DateTimeImmutable($value);
|
||||
} catch (Throwable) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
32
src/Bovin/Mapper/AnimalSummaryMapper.php
Normal file
32
src/Bovin/Mapper/AnimalSummaryMapper.php
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Malio\EdnotifBundle\Bovin\Mapper;
|
||||
|
||||
use Malio\EdnotifBundle\Bovin\Dto\AnimalSummaryDto;
|
||||
|
||||
final class AnimalSummaryMapper
|
||||
{
|
||||
use BovinNodeMappingTrait;
|
||||
|
||||
public function map(object $bovinNode): AnimalSummaryDto
|
||||
{
|
||||
$identificationNode = $bovinNode->IdentiteBovin ?? null;
|
||||
$identification = is_object($identificationNode) ? $this->mapIdentification($identificationNode) : null;
|
||||
|
||||
$presencePeriods = [];
|
||||
$presencePeriodsNode = $bovinNode->PeriodesPresences->PeriodePresence ?? null;
|
||||
foreach ($this->normalizeToList($presencePeriodsNode) as $presencePeriodNode) {
|
||||
if (!is_object($presencePeriodNode)) {
|
||||
continue;
|
||||
}
|
||||
$presencePeriods[] = $this->mapPresencePeriod($presencePeriodNode);
|
||||
}
|
||||
|
||||
return new AnimalSummaryDto(
|
||||
identification: $identification,
|
||||
presencePeriods: $presencePeriods,
|
||||
);
|
||||
}
|
||||
}
|
||||
168
src/Bovin/Mapper/BovinNodeMappingTrait.php
Normal file
168
src/Bovin/Mapper/BovinNodeMappingTrait.php
Normal file
@@ -0,0 +1,168 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Malio\EdnotifBundle\Bovin\Mapper;
|
||||
|
||||
use DateTimeImmutable;
|
||||
use Malio\EdnotifBundle\Bovin\Dto\BovinIdentificationDto;
|
||||
use Malio\EdnotifBundle\Bovin\Dto\BovinRef;
|
||||
use Malio\EdnotifBundle\Bovin\Dto\DateValueDto;
|
||||
use Malio\EdnotifBundle\Bovin\Dto\ExploitationRef;
|
||||
use Malio\EdnotifBundle\Bovin\Dto\MovementDto;
|
||||
use Malio\EdnotifBundle\Bovin\Dto\ParentInfoDto;
|
||||
use Malio\EdnotifBundle\Bovin\Dto\PresencePeriodDto;
|
||||
use Throwable;
|
||||
|
||||
/**
|
||||
* Helpers partagés par les mappers travaillant sur des noeuds `Bovin` issus
|
||||
* d'EDNOTIF, que la source soit une réponse SOAP directe (stdClass via ext-soap)
|
||||
* ou un message XML zippé (stdClass via ZipMessageDecoder).
|
||||
*/
|
||||
trait BovinNodeMappingTrait
|
||||
{
|
||||
protected function mapIdentification(object $identificationNode): BovinIdentificationDto
|
||||
{
|
||||
$birthDate = null;
|
||||
$birthDateNode = $identificationNode->DateNaissance ?? null;
|
||||
if (is_object($birthDateNode)) {
|
||||
$birthDate = new DateValueDto(
|
||||
date: $this->toNullableDate($birthDateNode->Date ?? null),
|
||||
completenessFlag: $this->toNullableString($birthDateNode->TemoinCompletude ?? null),
|
||||
);
|
||||
}
|
||||
|
||||
return new BovinIdentificationDto(
|
||||
bovin: $this->mapBovinRef($identificationNode->Bovin ?? null),
|
||||
sex: $this->toNullableString($identificationNode->Sexe ?? null),
|
||||
breedType: $this->toNullableString($identificationNode->TypeRacial ?? null),
|
||||
birthDate: $birthDate,
|
||||
workNumber: $this->toNullableString($identificationNode->NumeroTravail ?? null),
|
||||
isFilie: $this->toNullableBool($identificationNode->StatutFilie ?? null),
|
||||
motherCarrier: $this->mapParentInfo($identificationNode->MerePorteuse ?? null),
|
||||
fatherIpg: $this->mapParentInfo($identificationNode->PereIPG ?? null),
|
||||
birthExploitation: $this->mapExploitationRef($identificationNode->ExploitationNaissance ?? null),
|
||||
);
|
||||
}
|
||||
|
||||
protected function mapPresencePeriod(object $presencePeriodNode): PresencePeriodDto
|
||||
{
|
||||
$entryNode = $presencePeriodNode->Entree ?? null;
|
||||
$exitNode = $presencePeriodNode->Sortie ?? null;
|
||||
|
||||
return new PresencePeriodDto(
|
||||
entry: is_object($entryNode) ? $this->mapMovement($entryNode, 'entry') : null,
|
||||
exit: is_object($exitNode) ? $this->mapMovement($exitNode, 'exit') : null,
|
||||
);
|
||||
}
|
||||
|
||||
protected function mapMovement(object $movementNode, string $direction): MovementDto
|
||||
{
|
||||
if ('entry' === $direction) {
|
||||
$dateValue = $movementNode->DateEntree ?? ($movementNode->Date ?? ($movementNode->DateMouvement ?? null));
|
||||
$causeValue = $movementNode->CauseEntree ?? null;
|
||||
} else {
|
||||
$dateValue = $movementNode->DateSortie ?? ($movementNode->Date ?? ($movementNode->DateMouvement ?? null));
|
||||
$causeValue = $movementNode->CauseSortie ?? null;
|
||||
}
|
||||
|
||||
return new MovementDto(
|
||||
date: $this->toNullableDate($dateValue),
|
||||
cause: $this->toNullableString($causeValue),
|
||||
exploitation: $this->mapExploitationRef($movementNode->Exploitation ?? null),
|
||||
);
|
||||
}
|
||||
|
||||
protected function mapParentInfo(mixed $parentNode): ?ParentInfoDto
|
||||
{
|
||||
if (!is_object($parentNode)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return new ParentInfoDto(
|
||||
bovin: $this->mapBovinRef($parentNode->Bovin ?? null),
|
||||
breedType: $this->toNullableString($parentNode->TypeRacial ?? null),
|
||||
);
|
||||
}
|
||||
|
||||
protected function mapBovinRef(mixed $bovinNode): ?BovinRef
|
||||
{
|
||||
if (!is_object($bovinNode)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return new BovinRef(
|
||||
countryCode: $this->toNullableString($bovinNode->CodePays ?? null),
|
||||
nationalNumber: $this->toNullableString($bovinNode->NumeroNational ?? null),
|
||||
);
|
||||
}
|
||||
|
||||
protected function mapExploitationRef(mixed $exploitationNode): ?ExploitationRef
|
||||
{
|
||||
if (!is_object($exploitationNode)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return new ExploitationRef(
|
||||
countryCode: $this->toNullableString($exploitationNode->CodePays ?? null),
|
||||
exploitationNumber: $this->toNullableString($exploitationNode->NumeroExploitation ?? null),
|
||||
);
|
||||
}
|
||||
|
||||
/** @return list<mixed> */
|
||||
protected function normalizeToList(mixed $value): array
|
||||
{
|
||||
if (null === $value) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return is_array($value) ? array_values($value) : [$value];
|
||||
}
|
||||
|
||||
protected function toNullableString(mixed $value): ?string
|
||||
{
|
||||
if (null === $value) {
|
||||
return null;
|
||||
}
|
||||
$stringValue = trim((string) $value);
|
||||
|
||||
return '' === $stringValue ? null : $stringValue;
|
||||
}
|
||||
|
||||
protected function toNullableInt(mixed $value): ?int
|
||||
{
|
||||
if (null === $value) {
|
||||
return null;
|
||||
}
|
||||
if (is_int($value)) {
|
||||
return $value;
|
||||
}
|
||||
if (is_numeric($value)) {
|
||||
return (int) $value;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
protected function toNullableBool(mixed $value): ?bool
|
||||
{
|
||||
if (null === $value) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (bool) $value;
|
||||
}
|
||||
|
||||
protected function toNullableDate(mixed $value): ?DateTimeImmutable
|
||||
{
|
||||
if (!is_string($value) || '' === trim($value)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
return new DateTimeImmutable($value);
|
||||
} catch (Throwable) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
68
src/Bovin/Mapper/InventoryMapper.php
Normal file
68
src/Bovin/Mapper/InventoryMapper.php
Normal file
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Malio\EdnotifBundle\Bovin\Mapper;
|
||||
|
||||
use Malio\EdnotifBundle\Bovin\Dto\EarTagSeriesDto;
|
||||
use Malio\EdnotifBundle\Bovin\Dto\InventoryDto;
|
||||
use Malio\EdnotifBundle\Shared\Mapper\StandardResponseMapper;
|
||||
|
||||
final class InventoryMapper
|
||||
{
|
||||
use BovinNodeMappingTrait;
|
||||
|
||||
public function __construct(
|
||||
private readonly AnimalSummaryMapper $animalSummaryMapper,
|
||||
private readonly StandardResponseMapper $standardResponseMapper,
|
||||
) {}
|
||||
|
||||
public function map(object $soapResponse, ?object $unzippedMessage): InventoryDto
|
||||
{
|
||||
$standardResponse = $this->standardResponseMapper->map($soapResponse->ReponseStandard ?? null);
|
||||
|
||||
$nbBovins = $this->toNullableInt($soapResponse->ReponseSpecifique->NbBovins ?? null) ?? 0;
|
||||
|
||||
$startDate = null;
|
||||
$endDate = null;
|
||||
$includesEarTagStock = null;
|
||||
$animals = [];
|
||||
$earTagSeries = [];
|
||||
|
||||
if (is_object($unzippedMessage)) {
|
||||
$infoNode = $unzippedMessage->InformationsMessage ?? null;
|
||||
if (is_object($infoNode)) {
|
||||
$startDate = $this->toNullableDate($infoNode->DateDebut ?? null);
|
||||
$endDate = $this->toNullableDate($infoNode->DateFin ?? null);
|
||||
$includesEarTagStock = $this->toNullableBool($infoNode->StockBoucles ?? null);
|
||||
}
|
||||
|
||||
$bovinsNode = $unzippedMessage->Bovins->Bovin ?? null;
|
||||
foreach ($this->normalizeToList($bovinsNode) as $bovinNode) {
|
||||
if (!is_object($bovinNode)) {
|
||||
continue;
|
||||
}
|
||||
$animals[] = $this->animalSummaryMapper->map($bovinNode);
|
||||
}
|
||||
|
||||
$seriesNode = $unzippedMessage->Boucles->SerieBoucles ?? null;
|
||||
foreach ($this->normalizeToList($seriesNode) as $serieNode) {
|
||||
if (!is_object($serieNode)) {
|
||||
continue;
|
||||
}
|
||||
$earTagSeries[] = new EarTagSeriesDto(rawNode: $serieNode);
|
||||
}
|
||||
}
|
||||
|
||||
return new InventoryDto(
|
||||
standardResponse: $standardResponse,
|
||||
nbBovins: $nbBovins,
|
||||
startDate: $startDate,
|
||||
endDate: $endDate,
|
||||
includesEarTagStock: $includesEarTagStock,
|
||||
animals: $animals,
|
||||
earTagSeries: $earTagSeries,
|
||||
rawSoapResponse: $soapResponse,
|
||||
);
|
||||
}
|
||||
}
|
||||
46
src/Bovin/Mapper/PresumedExitsMapper.php
Normal file
46
src/Bovin/Mapper/PresumedExitsMapper.php
Normal file
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Malio\EdnotifBundle\Bovin\Mapper;
|
||||
|
||||
use Malio\EdnotifBundle\Bovin\Dto\PresumedExitDto;
|
||||
use Malio\EdnotifBundle\Bovin\Dto\PresumedExitsDto;
|
||||
use Malio\EdnotifBundle\Shared\Mapper\StandardResponseMapper;
|
||||
|
||||
final class PresumedExitsMapper
|
||||
{
|
||||
use BovinNodeMappingTrait;
|
||||
|
||||
public function __construct(
|
||||
private readonly StandardResponseMapper $standardResponseMapper,
|
||||
) {}
|
||||
|
||||
public function map(object $soapResponse, ?object $unzippedMessage): PresumedExitsDto
|
||||
{
|
||||
$standardResponse = $this->standardResponseMapper->map($soapResponse->ReponseStandard ?? null);
|
||||
$nbBovins = $this->toNullableInt($soapResponse->ReponseSpecifique->NbBovins ?? null) ?? 0;
|
||||
|
||||
$presumedExits = [];
|
||||
|
||||
if (is_object($unzippedMessage)) {
|
||||
$exitsNode = $unzippedMessage->SortiesPresumees->SortiePresumee ?? null;
|
||||
foreach ($this->normalizeToList($exitsNode) as $exitNode) {
|
||||
if (!is_object($exitNode)) {
|
||||
continue;
|
||||
}
|
||||
$presumedExits[] = new PresumedExitDto(
|
||||
bovin: $this->mapBovinRef($exitNode->Bovin ?? null),
|
||||
exitDate: $this->toNullableDate($exitNode->DateSortie ?? null),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return new PresumedExitsDto(
|
||||
standardResponse: $standardResponse,
|
||||
nbBovins: $nbBovins,
|
||||
presumedExits: $presumedExits,
|
||||
rawSoapResponse: $soapResponse,
|
||||
);
|
||||
}
|
||||
}
|
||||
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,
|
||||
);
|
||||
}
|
||||
}
|
||||
53
src/Shared/Mapper/StandardResponseMapper.php
Normal file
53
src/Shared/Mapper/StandardResponseMapper.php
Normal file
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Malio\EdnotifBundle\Shared\Mapper;
|
||||
|
||||
use Malio\EdnotifBundle\Shared\Dto\AnomalyDto;
|
||||
use Malio\EdnotifBundle\Shared\Dto\StandardResponseDto;
|
||||
|
||||
final class StandardResponseMapper
|
||||
{
|
||||
public function map(mixed $standardResponseNode): StandardResponseDto
|
||||
{
|
||||
$result = (bool) ($standardResponseNode->Resultat ?? false);
|
||||
$anomalyNode = is_object($standardResponseNode) ? ($standardResponseNode->Anomalie ?? null) : null;
|
||||
|
||||
$anomaly = null;
|
||||
if (is_object($anomalyNode)) {
|
||||
$anomaly = new AnomalyDto(
|
||||
code: $this->toNullableString($anomalyNode->Code ?? null),
|
||||
severity: $this->toNullableInt($anomalyNode->Severite ?? null),
|
||||
message: $this->toNullableString($anomalyNode->Message ?? null),
|
||||
);
|
||||
}
|
||||
|
||||
return new StandardResponseDto($result, $anomaly);
|
||||
}
|
||||
|
||||
private function toNullableString(mixed $value): ?string
|
||||
{
|
||||
if (null === $value) {
|
||||
return null;
|
||||
}
|
||||
$stringValue = trim((string) $value);
|
||||
|
||||
return '' === $stringValue ? null : $stringValue;
|
||||
}
|
||||
|
||||
private function toNullableInt(mixed $value): ?int
|
||||
{
|
||||
if (null === $value) {
|
||||
return null;
|
||||
}
|
||||
if (is_int($value)) {
|
||||
return $value;
|
||||
}
|
||||
if (is_numeric($value)) {
|
||||
return (int) $value;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
87
src/Shared/Soap/ZipMessageDecoder.php
Normal file
87
src/Shared/Soap/ZipMessageDecoder.php
Normal file
@@ -0,0 +1,87 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Malio\EdnotifBundle\Shared\Soap;
|
||||
|
||||
use RuntimeException;
|
||||
use ZipArchive;
|
||||
|
||||
final class ZipMessageDecoder
|
||||
{
|
||||
/**
|
||||
* Décode le binaire `MessageZip` retourné par les opérations EDNOTIF de type
|
||||
* `Get*` (Inventaire / RetourDossiers / SortiesPresumees) : le contenu est déjà
|
||||
* décodé par ext-soap depuis base64, il reste à dézipper et parser le XML.
|
||||
*/
|
||||
public function decode(string $zipBinary): object
|
||||
{
|
||||
if ('' === $zipBinary) {
|
||||
throw new RuntimeException('ZipMessageDecoder: binaire ZIP vide.');
|
||||
}
|
||||
|
||||
$tempFile = tempnam(sys_get_temp_dir(), 'ednotif_zip_');
|
||||
if (false === $tempFile) {
|
||||
throw new RuntimeException('ZipMessageDecoder: impossible de créer un fichier temporaire.');
|
||||
}
|
||||
|
||||
try {
|
||||
if (false === file_put_contents($tempFile, $zipBinary)) {
|
||||
throw new RuntimeException('ZipMessageDecoder: impossible d\'écrire le fichier temporaire.');
|
||||
}
|
||||
|
||||
$xml = $this->readFirstEntry($tempFile);
|
||||
} finally {
|
||||
@unlink($tempFile);
|
||||
}
|
||||
|
||||
$previous = libxml_use_internal_errors(true);
|
||||
|
||||
try {
|
||||
$simpleXml = simplexml_load_string($xml);
|
||||
} finally {
|
||||
libxml_clear_errors();
|
||||
libxml_use_internal_errors($previous);
|
||||
}
|
||||
|
||||
if (false === $simpleXml) {
|
||||
throw new RuntimeException('ZipMessageDecoder: XML invalide dans l\'archive ZIP.');
|
||||
}
|
||||
|
||||
$json = json_encode($simpleXml);
|
||||
if (false === $json) {
|
||||
throw new RuntimeException('ZipMessageDecoder: échec de l\'encodage JSON intermédiaire.');
|
||||
}
|
||||
|
||||
$decoded = json_decode($json, false);
|
||||
if (!is_object($decoded)) {
|
||||
throw new RuntimeException('ZipMessageDecoder: décodage JSON non objet.');
|
||||
}
|
||||
|
||||
return $decoded;
|
||||
}
|
||||
|
||||
private function readFirstEntry(string $filePath): string
|
||||
{
|
||||
$zip = new ZipArchive();
|
||||
$openResult = $zip->open($filePath, ZipArchive::RDONLY);
|
||||
if (true !== $openResult) {
|
||||
throw new RuntimeException(sprintf('ZipMessageDecoder: ouverture ZIP impossible (code %s).', (string) $openResult));
|
||||
}
|
||||
|
||||
try {
|
||||
if (0 === $zip->numFiles) {
|
||||
throw new RuntimeException('ZipMessageDecoder: archive ZIP vide.');
|
||||
}
|
||||
|
||||
$xml = $zip->getFromIndex(0);
|
||||
if (false === $xml) {
|
||||
throw new RuntimeException('ZipMessageDecoder: lecture de l\'entrée ZIP impossible.');
|
||||
}
|
||||
} finally {
|
||||
$zip->close();
|
||||
}
|
||||
|
||||
return $xml;
|
||||
}
|
||||
}
|
||||
0
tests/Unit/.gitkeep
Normal file
0
tests/Unit/.gitkeep
Normal file
70
tests/Unit/Bovin/Mapper/AnimalSummaryMapperTest.php
Normal file
70
tests/Unit/Bovin/Mapper/AnimalSummaryMapperTest.php
Normal file
@@ -0,0 +1,70 @@
|
||||
<?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;
|
||||
}
|
||||
}
|
||||
190
tests/Unit/Bovin/Mapper/BovinNodeMappingTraitTest.php
Normal file
190
tests/Unit/Bovin/Mapper/BovinNodeMappingTraitTest.php
Normal file
@@ -0,0 +1,190 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Malio\EdnotifBundle\Tests\Unit\Bovin\Mapper;
|
||||
|
||||
use DateTimeImmutable;
|
||||
use Malio\EdnotifBundle\Bovin\Mapper\BovinNodeMappingTrait;
|
||||
use PHPUnit\Framework\Attributes\CoversTrait;
|
||||
use PHPUnit\Framework\Attributes\DataProvider;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use stdClass;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
#[CoversTrait(BovinNodeMappingTrait::class)]
|
||||
final class BovinNodeMappingTraitTest extends TestCase
|
||||
{
|
||||
// ---------- normalizeToList ----------
|
||||
|
||||
public function testNormalizeToListWithNullReturnsEmptyList(): void
|
||||
{
|
||||
self::assertSame([], self::adapter()->normalizeToList(null));
|
||||
}
|
||||
|
||||
public function testNormalizeToListWithScalarWrapsIntoList(): void
|
||||
{
|
||||
self::assertSame(['foo'], self::adapter()->normalizeToList('foo'));
|
||||
self::assertSame([42], self::adapter()->normalizeToList(42));
|
||||
}
|
||||
|
||||
public function testNormalizeToListWithObjectWrapsIntoList(): void
|
||||
{
|
||||
$obj = new stdClass();
|
||||
$result = self::adapter()->normalizeToList($obj);
|
||||
|
||||
self::assertCount(1, $result);
|
||||
self::assertSame($obj, $result[0]);
|
||||
}
|
||||
|
||||
public function testNormalizeToListWithListReturnsListUnchanged(): void
|
||||
{
|
||||
$input = ['a', 'b', 'c'];
|
||||
self::assertSame($input, self::adapter()->normalizeToList($input));
|
||||
}
|
||||
|
||||
public function testNormalizeToListWithAssociativeArrayDiscardsKeys(): void
|
||||
{
|
||||
$input = ['x' => 'a', 'y' => 'b'];
|
||||
$result = self::adapter()->normalizeToList($input);
|
||||
|
||||
self::assertSame(['a', 'b'], $result);
|
||||
}
|
||||
|
||||
#[DataProvider('toNullableStringProvider')]
|
||||
public function testToNullableString(mixed $input, ?string $expected): void
|
||||
{
|
||||
self::assertSame($expected, self::adapter()->toNullableString($input));
|
||||
}
|
||||
|
||||
// ---------- toNullableString ----------
|
||||
|
||||
/** @return iterable<string,array{mixed, ?string}> */
|
||||
public static function toNullableStringProvider(): iterable
|
||||
{
|
||||
yield 'null' => [null, null];
|
||||
|
||||
yield 'empty string' => ['', null];
|
||||
|
||||
yield 'whitespace only' => [' ', null];
|
||||
|
||||
yield 'plain' => ['abc', 'abc'];
|
||||
|
||||
yield 'trimmed' => [' abc ', 'abc'];
|
||||
|
||||
yield 'int coerced to string' => [42, '42'];
|
||||
|
||||
yield 'zero preserved' => ['0', '0'];
|
||||
}
|
||||
|
||||
#[DataProvider('toNullableIntProvider')]
|
||||
public function testToNullableInt(mixed $input, ?int $expected): void
|
||||
{
|
||||
self::assertSame($expected, self::adapter()->toNullableInt($input));
|
||||
}
|
||||
|
||||
// ---------- toNullableInt ----------
|
||||
|
||||
/** @return iterable<string,array{mixed, ?int}> */
|
||||
public static function toNullableIntProvider(): iterable
|
||||
{
|
||||
yield 'null' => [null, null];
|
||||
|
||||
yield 'int passthrough' => [42, 42];
|
||||
|
||||
yield 'zero int' => [0, 0];
|
||||
|
||||
yield 'numeric string' => ['42', 42];
|
||||
|
||||
yield 'negative string' => ['-7', -7];
|
||||
|
||||
yield 'float-like string' => ['3.14', 3];
|
||||
|
||||
yield 'non-numeric' => ['abc', null];
|
||||
|
||||
yield 'empty string' => ['', null];
|
||||
}
|
||||
|
||||
#[DataProvider('toNullableBoolProvider')]
|
||||
public function testToNullableBool(mixed $input, ?bool $expected): void
|
||||
{
|
||||
self::assertSame($expected, self::adapter()->toNullableBool($input));
|
||||
}
|
||||
|
||||
// ---------- toNullableBool ----------
|
||||
|
||||
/** @return iterable<string,array{mixed, ?bool}> */
|
||||
public static function toNullableBoolProvider(): iterable
|
||||
{
|
||||
yield 'null' => [null, null];
|
||||
|
||||
yield 'true' => [true, true];
|
||||
|
||||
yield 'false' => [false, false];
|
||||
|
||||
yield 'string 1' => ['1', true];
|
||||
|
||||
yield 'string 0' => ['0', false];
|
||||
|
||||
yield 'empty string' => ['', false];
|
||||
|
||||
yield 'int 1' => [1, true];
|
||||
|
||||
yield 'int 0' => [0, false];
|
||||
}
|
||||
|
||||
// ---------- toNullableDate ----------
|
||||
|
||||
public function testToNullableDateFromIsoString(): void
|
||||
{
|
||||
$result = self::adapter()->toNullableDate('2026-04-21');
|
||||
self::assertEquals(new DateTimeImmutable('2026-04-21'), $result);
|
||||
}
|
||||
|
||||
public function testToNullableDateFromDateTimeString(): void
|
||||
{
|
||||
$result = self::adapter()->toNullableDate('2026-04-21T10:30:00+02:00');
|
||||
self::assertEquals(new DateTimeImmutable('2026-04-21T10:30:00+02:00'), $result);
|
||||
}
|
||||
|
||||
#[DataProvider('toNullableDateFallbackProvider')]
|
||||
public function testToNullableDateReturnsNullOnInvalidInput(mixed $input): void
|
||||
{
|
||||
self::assertNull(self::adapter()->toNullableDate($input));
|
||||
}
|
||||
|
||||
/** @return iterable<string,array{mixed}> */
|
||||
public static function toNullableDateFallbackProvider(): iterable
|
||||
{
|
||||
yield 'null' => [null];
|
||||
|
||||
yield 'empty string' => [''];
|
||||
|
||||
yield 'whitespace' => [' '];
|
||||
|
||||
yield 'non-string int' => [42];
|
||||
|
||||
yield 'non-string array' => [[]];
|
||||
|
||||
yield 'invalid date string' => ['not-a-date'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Adapter anonyme : re-expose chaque helper protected en public pour le test,
|
||||
* sans jamais instancier un vrai mapper (ceux-ci ont des dépendances DI).
|
||||
*/
|
||||
private static function adapter(): object
|
||||
{
|
||||
return new class {
|
||||
use BovinNodeMappingTrait {
|
||||
normalizeToList as public;
|
||||
toNullableString as public;
|
||||
toNullableInt as public;
|
||||
toNullableBool as public;
|
||||
toNullableDate as public;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
176
tests/Unit/Bovin/Mapper/InventoryMapperTest.php
Normal file
176
tests/Unit/Bovin/Mapper/InventoryMapperTest.php
Normal file
@@ -0,0 +1,176 @@
|
||||
<?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 Malio\EdnotifBundle\Shared\Mapper\StandardResponseMapper;
|
||||
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(), new StandardResponseMapper());
|
||||
|
||||
$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(), new StandardResponseMapper());
|
||||
|
||||
$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);
|
||||
}
|
||||
|
||||
public function testMapInventoryWithStockBouclesAbsentYieldsNullFlag(): void
|
||||
{
|
||||
$mapper = new InventoryMapper(new AnimalSummaryMapper(), new StandardResponseMapper());
|
||||
|
||||
$message = new stdClass();
|
||||
$message->InformationsMessage = new stdClass();
|
||||
$message->InformationsMessage->DateDebut = '2026-01-01';
|
||||
// StockBoucles deliberately omitted
|
||||
|
||||
$inventory = $mapper->map($this->makeSoapResponse(), $message);
|
||||
|
||||
self::assertNull($inventory->includesEarTagStock);
|
||||
}
|
||||
|
||||
public function testMapInventoryWithStockBouclesZeroYieldsFalseFlag(): void
|
||||
{
|
||||
$mapper = new InventoryMapper(new AnimalSummaryMapper(), new StandardResponseMapper());
|
||||
|
||||
$message = new stdClass();
|
||||
$message->InformationsMessage = new stdClass();
|
||||
$message->InformationsMessage->StockBoucles = '0';
|
||||
|
||||
$inventory = $mapper->map($this->makeSoapResponse(), $message);
|
||||
|
||||
self::assertFalse($inventory->includesEarTagStock);
|
||||
}
|
||||
|
||||
public function testMapInventoryWithDateFinAbsentYieldsNullEndDate(): void
|
||||
{
|
||||
$mapper = new InventoryMapper(new AnimalSummaryMapper(), new StandardResponseMapper());
|
||||
|
||||
$message = new stdClass();
|
||||
$message->InformationsMessage = new stdClass();
|
||||
$message->InformationsMessage->DateDebut = '2026-01-01';
|
||||
// DateFin deliberately omitted
|
||||
|
||||
$inventory = $mapper->map($this->makeSoapResponse(), $message);
|
||||
|
||||
self::assertNull($inventory->endDate);
|
||||
}
|
||||
|
||||
public function testMapInventoryWithSerieBouclesAsListPreservesAllEntries(): void
|
||||
{
|
||||
$mapper = new InventoryMapper(new AnimalSummaryMapper(), new StandardResponseMapper());
|
||||
|
||||
$serie1 = new stdClass();
|
||||
$serie1->NumeroSerieDebut = 'A0001';
|
||||
$serie2 = new stdClass();
|
||||
$serie2->NumeroSerieDebut = 'B0001';
|
||||
|
||||
$message = new stdClass();
|
||||
$message->Boucles = new stdClass();
|
||||
$message->Boucles->SerieBoucles = [$serie1, $serie2];
|
||||
|
||||
$inventory = $mapper->map($this->makeSoapResponse(), $message);
|
||||
|
||||
self::assertCount(2, $inventory->earTagSeries);
|
||||
self::assertSame('A0001', $inventory->earTagSeries[0]->rawNode->NumeroSerieDebut);
|
||||
self::assertSame('B0001', $inventory->earTagSeries[1]->rawNode->NumeroSerieDebut);
|
||||
}
|
||||
|
||||
public function testMapInventoryWithMissingNbBovinsDefaultsToZero(): void
|
||||
{
|
||||
$mapper = new InventoryMapper(new AnimalSummaryMapper(), new StandardResponseMapper());
|
||||
|
||||
$soapResponse = new stdClass();
|
||||
$soapResponse->ReponseStandard = new stdClass();
|
||||
$soapResponse->ReponseStandard->Resultat = true;
|
||||
$soapResponse->ReponseSpecifique = new stdClass();
|
||||
// NbBovins deliberately omitted
|
||||
|
||||
$inventory = $mapper->map($soapResponse, null);
|
||||
|
||||
self::assertSame(0, $inventory->nbBovins);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
72
tests/Unit/Bovin/Mapper/PresumedExitsMapperTest.php
Normal file
72
tests/Unit/Bovin/Mapper/PresumedExitsMapperTest.php
Normal file
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Malio\EdnotifBundle\Tests\Unit\Bovin\Mapper;
|
||||
|
||||
use DateTimeImmutable;
|
||||
use Malio\EdnotifBundle\Bovin\Dto\PresumedExitsDto;
|
||||
use Malio\EdnotifBundle\Bovin\Mapper\PresumedExitsMapper;
|
||||
use Malio\EdnotifBundle\Shared\Mapper\StandardResponseMapper;
|
||||
use PHPUnit\Framework\Attributes\CoversClass;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use stdClass;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
#[CoversClass(PresumedExitsMapper::class)]
|
||||
final class PresumedExitsMapperTest extends TestCase
|
||||
{
|
||||
public function testMapWithExits(): void
|
||||
{
|
||||
$soapResponse = new stdClass();
|
||||
$soapResponse->ReponseStandard = new stdClass();
|
||||
$soapResponse->ReponseStandard->Resultat = true;
|
||||
$soapResponse->ReponseSpecifique = new stdClass();
|
||||
$soapResponse->ReponseSpecifique->NbBovins = 2;
|
||||
|
||||
$message = new stdClass();
|
||||
$message->SortiesPresumees = new stdClass();
|
||||
$message->SortiesPresumees->SortiePresumee = [
|
||||
$this->makeExit('FR111', '2026-02-15'),
|
||||
$this->makeExit('FR222', null),
|
||||
];
|
||||
|
||||
$dto = new PresumedExitsMapper(new StandardResponseMapper())->map($soapResponse, $message);
|
||||
|
||||
self::assertInstanceOf(PresumedExitsDto::class, $dto);
|
||||
self::assertSame(2, $dto->nbBovins);
|
||||
self::assertCount(2, $dto->presumedExits);
|
||||
self::assertSame('FR111', $dto->presumedExits[0]->bovin?->nationalNumber);
|
||||
self::assertEquals(new DateTimeImmutable('2026-02-15'), $dto->presumedExits[0]->exitDate);
|
||||
self::assertNull($dto->presumedExits[1]->exitDate);
|
||||
}
|
||||
|
||||
public function testMapWithoutMessageReturnsEmpty(): void
|
||||
{
|
||||
$soapResponse = new stdClass();
|
||||
$soapResponse->ReponseStandard = new stdClass();
|
||||
$soapResponse->ReponseStandard->Resultat = true;
|
||||
$soapResponse->ReponseSpecifique = new stdClass();
|
||||
$soapResponse->ReponseSpecifique->NbBovins = 0;
|
||||
|
||||
$dto = new PresumedExitsMapper(new StandardResponseMapper())->map($soapResponse, null);
|
||||
|
||||
self::assertSame(0, $dto->nbBovins);
|
||||
self::assertSame([], $dto->presumedExits);
|
||||
}
|
||||
|
||||
private function makeExit(string $nationalNumber, ?string $exitDate): object
|
||||
{
|
||||
$node = new stdClass();
|
||||
$node->Bovin = new stdClass();
|
||||
$node->Bovin->CodePays = 'FR';
|
||||
$node->Bovin->NumeroNational = $nationalNumber;
|
||||
if (null !== $exitDate) {
|
||||
$node->DateSortie = $exitDate;
|
||||
}
|
||||
|
||||
return $node;
|
||||
}
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
79
tests/Unit/Shared/Soap/ZipMessageDecoderTest.php
Normal file
79
tests/Unit/Shared/Soap/ZipMessageDecoderTest.php
Normal file
@@ -0,0 +1,79 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Malio\EdnotifBundle\Tests\Unit\Shared\Soap;
|
||||
|
||||
use Malio\EdnotifBundle\Shared\Soap\ZipMessageDecoder;
|
||||
use PHPUnit\Framework\Attributes\CoversClass;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use RuntimeException;
|
||||
use ZipArchive;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
#[CoversClass(ZipMessageDecoder::class)]
|
||||
final class ZipMessageDecoderTest extends TestCase
|
||||
{
|
||||
public function testDecodeReturnsObjectFromZippedXml(): void
|
||||
{
|
||||
$xml = '<?xml version="1.0" encoding="UTF-8"?>'
|
||||
.'<MessageIpBNotifGetInventaire>'
|
||||
.'<InformationsMessage><DateDebut>2026-01-01</DateDebut></InformationsMessage>'
|
||||
.'<Bovins><Bovin><IdentiteBovin><Sexe>F</Sexe></IdentiteBovin></Bovin></Bovins>'
|
||||
.'</MessageIpBNotifGetInventaire>';
|
||||
|
||||
$zipBinary = $this->makeZipBinary('message.xml', $xml);
|
||||
$decoded = new ZipMessageDecoder()->decode($zipBinary);
|
||||
|
||||
self::assertIsObject($decoded);
|
||||
self::assertSame('2026-01-01', (string) $decoded->InformationsMessage->DateDebut);
|
||||
self::assertSame('F', (string) $decoded->Bovins->Bovin->IdentiteBovin->Sexe);
|
||||
}
|
||||
|
||||
public function testDecodeProducesArrayForMultiChildNodes(): void
|
||||
{
|
||||
$xml = '<?xml version="1.0" encoding="UTF-8"?>'
|
||||
.'<MessageIpBNotifGetInventaire>'
|
||||
.'<Bovins>'
|
||||
.'<Bovin><IdentiteBovin><Sexe>F</Sexe></IdentiteBovin></Bovin>'
|
||||
.'<Bovin><IdentiteBovin><Sexe>M</Sexe></IdentiteBovin></Bovin>'
|
||||
.'</Bovins>'
|
||||
.'</MessageIpBNotifGetInventaire>';
|
||||
|
||||
$decoded = new ZipMessageDecoder()->decode($this->makeZipBinary('message.xml', $xml));
|
||||
|
||||
self::assertIsArray($decoded->Bovins->Bovin);
|
||||
self::assertCount(2, $decoded->Bovins->Bovin);
|
||||
self::assertSame('F', (string) $decoded->Bovins->Bovin[0]->IdentiteBovin->Sexe);
|
||||
self::assertSame('M', (string) $decoded->Bovins->Bovin[1]->IdentiteBovin->Sexe);
|
||||
}
|
||||
|
||||
public function testDecodeThrowsOnEmptyBinary(): void
|
||||
{
|
||||
$this->expectException(RuntimeException::class);
|
||||
new ZipMessageDecoder()->decode('');
|
||||
}
|
||||
|
||||
public function testDecodeThrowsOnInvalidZip(): void
|
||||
{
|
||||
$this->expectException(RuntimeException::class);
|
||||
new ZipMessageDecoder()->decode('not a zip');
|
||||
}
|
||||
|
||||
private function makeZipBinary(string $innerFile, string $content): string
|
||||
{
|
||||
$tempFile = tempnam(sys_get_temp_dir(), 'test_zip_');
|
||||
self::assertIsString($tempFile);
|
||||
$zip = new ZipArchive();
|
||||
self::assertTrue(true === $zip->open($tempFile, ZipArchive::CREATE | ZipArchive::OVERWRITE));
|
||||
self::assertTrue($zip->addFromString($innerFile, $content));
|
||||
self::assertTrue($zip->close());
|
||||
$binary = file_get_contents($tempFile);
|
||||
@unlink($tempFile);
|
||||
self::assertIsString($binary);
|
||||
|
||||
return $binary;
|
||||
}
|
||||
}
|
||||
5
tests/bootstrap.php
Normal file
5
tests/bootstrap.php
Normal file
@@ -0,0 +1,5 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
require __DIR__.'/../vendor/autoload.php';
|
||||
Reference in New Issue
Block a user