[#ED-1] Ajout des API de lecture bovin (#2)
| Numéro du ticket | Titre du ticket | |------------------|-----------------| | | | ## Description de la PR ## Modification du .env ## Check list - [ ] Pas de régression - [x] TU/TI/TF rédigée - [x] TU/TI/TF OK - [ ] CHANGELOG modifié Reviewed-on: #2 Co-authored-by: tristan <tristan@yuno.malio.fr> Co-committed-by: tristan <tristan@yuno.malio.fr>
This commit was merged in pull request #2.
This commit is contained in:
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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user