' .'' .'2026-01-01' .'F' .''; $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 = '' .'' .'' .'F' .'M' .'' .''; $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; } }