feat : décodeur ZIP+XML partagé pour les réponses Get* bovin
This commit is contained in:
61
tests/Unit/Shared/Soap/ZipMessageDecoderTest.php
Normal file
61
tests/Unit/Shared/Soap/ZipMessageDecoderTest.php
Normal file
@@ -0,0 +1,61 @@
|
||||
<?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 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