| 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>
80 lines
2.8 KiB
PHP
80 lines
2.8 KiB
PHP
<?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;
|
|
}
|
|
}
|