. */ namespace SP\Tests\Storage; use PHPUnit\Framework\TestCase; use RuntimeException; use SP\Core\Exceptions\CheckException; use SP\Core\PhpExtensionChecker; use SP\Storage\File\ArchiveHandler; use SP\Storage\File\FileException; use UnexpectedValueException; /** * Class ArchiveHandlerTest * * @package SP\Tests\Storage */ class ArchiveHandlerTest extends TestCase { const ARCHIVE = TMP_PATH . DIRECTORY_SEPARATOR . 'test_archive'; /** * @throws CheckException * @throws FileException */ public function testCompressFile() { $archive = TMP_PATH . DIRECTORY_SEPARATOR . 'test_archive_file'; $handler = new ArchiveHandler($archive, new PhpExtensionChecker()); $handler->compressFile(RESOURCE_PATH . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'config.xml'); $this->assertFileExists($archive . ArchiveHandler::COMPRESS_EXTENSION); } /** * @throws CheckException * @throws FileException */ public function testCompressInvalidFile() { $this->expectException(RuntimeException::class); $archive = TMP_PATH . DIRECTORY_SEPARATOR . 'test_archive_file'; $handler = new ArchiveHandler($archive, new PhpExtensionChecker()); $handler->compressFile(RESOURCE_PATH . DIRECTORY_SEPARATOR . 'non_existant_file'); } /** * @throws CheckException * @throws FileException */ public function testCompressDirectory() { $archive = TMP_PATH . DIRECTORY_SEPARATOR . 'test_archive_dir'; $handler = new ArchiveHandler($archive, new PhpExtensionChecker()); $handler->compressDirectory(RESOURCE_PATH); $this->assertFileExists($archive . ArchiveHandler::COMPRESS_EXTENSION); } /** * @throws CheckException * @throws FileException */ public function testCompressInvalidDirectory() { $this->expectException(UnexpectedValueException::class); $archive = TMP_PATH . DIRECTORY_SEPARATOR . 'test_archive_dir'; $handler = new ArchiveHandler($archive, new PhpExtensionChecker()); $handler->compressDirectory(RESOURCE_PATH . DIRECTORY_SEPARATOR . 'non_existant_dir'); } /** * Sets up the fixture, for example, open a network connection. * This method is called before a test is executed. */ protected function setUp(): void { array_map('unlink', glob(TMP_PATH . DIRECTORY_SEPARATOR . 'test_archive_*')); } }