<?php

namespace App\Tests\Service\System;

use App\Service\System\ZipArchiver;
use PHPUnit\Framework\TestCase;

class ZipArchiverTest extends TestCase
{
    public function testCreateArchive(): void
    {
        $archiver = new ZipArchiver();
        
        $tmpDir = sys_get_temp_dir() . '/zip_test_' . uniqid();
        mkdir($tmpDir);
        file_put_contents($tmpDir . '/file.txt', 'content');
        
        $zipPath = $tmpDir . '/archive.zip';
        $sqlPath = $tmpDir . '/dump.sql';
        file_put_contents($sqlPath, 'SQL');

        $archiver->createArchive($zipPath, $sqlPath, ['files' => $tmpDir]);
        
        $this->assertFileExists($zipPath);
        
        // Check content
        $zip = new \ZipArchive();
        $zip->open($zipPath);
        $this->assertNotFalse($zip->getFromName('database.sql'));
        $this->assertNotFalse($zip->getFromName('files/file.txt')); // Might be slightly different path depending on recursive iterator
        $zip->close();

        // Cleanup
        unlink($zipPath);
        unlink($sqlPath);
        unlink($tmpDir . '/file.txt');
        rmdir($tmpDir);
    }
}
