Skip to content

Commit

Permalink
Update 7zip test
Browse files Browse the repository at this point in the history
  • Loading branch information
wapmorgan committed Nov 13, 2019
1 parent d58fb50 commit 718fff0
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 7 deletions.
2 changes: 0 additions & 2 deletions .travis.yml
@@ -1,4 +1,3 @@
dist: bionic
language: php
matrix:
include:
Expand All @@ -12,7 +11,6 @@ matrix:

install:
- phpenv config-rm xdebug.ini || echo "xdebug is not installed"

- sudo apt-get install p7zip-full

# install php-lzma2
Expand Down
22 changes: 22 additions & 0 deletions src/Formats/Archive7z.php
@@ -0,0 +1,22 @@
<?php
namespace wapmorgan\UnifiedArchive\Formats;

use Symfony\Component\Process\Process;

class Archive7z extends \Archive7z\Archive7z
{

/**
* @throws \Archive7z\Exception
*/
public static function getBinaryVersion()
{
$binary = static::makeBinary7z();
$process = new Process(escapeshellarg(str_replace('\\', '/', $binary)));
$result = $process->mustRun()->getOutput();
if (!preg_match('~7-Zip (\d+\.\d+)~i', $result, $version))
return false;

return $version[1];
}
}
7 changes: 4 additions & 3 deletions src/Formats/SevenZip.php
@@ -1,14 +1,13 @@
<?php
namespace wapmorgan\UnifiedArchive\Formats;

use Archive7z\Archive7z;
use Exception;
use wapmorgan\UnifiedArchive\ArchiveEntry;
use wapmorgan\UnifiedArchive\ArchiveInformation;

class SevenZip extends BasicFormat
{
/** @var \Archive7z\Archive7z */
/** @var Archive7z */
protected $sevenZip;

/**
Expand Down Expand Up @@ -210,10 +209,12 @@ public static function createArchive(array $files, $archiveFileName) {

/**
* @return bool
* @throws \Archive7z\Exception
*/
public static function canAddFiles()
{
return true;
$version = Archive7z::getBinaryVersion();
return $version !== false && version_compare('9.30', $version, '<=');
}

/**
Expand Down
12 changes: 10 additions & 2 deletions tests/ArchivingTest.php
@@ -1,4 +1,6 @@
<?php

use wapmorgan\UnifiedArchive\Formats\SevenZip;
use wapmorgan\UnifiedArchive\UnifiedArchive;

class ArchivingTest extends PhpUnitTestCase
Expand Down Expand Up @@ -64,13 +66,19 @@ public function testModify($archiveFileName, $archiveType)

/**
* @return array
* @throws \Archive7z\Exception
*/
public function modifyableArchiveTypes()
{
return [
// dynamic types list
$types = [
['fixtures.zip', UnifiedArchive::ZIP],
['fixtures.7z', UnifiedArchive::SEVEN_ZIP],
['fixtures.tar', UnifiedArchive::TAR],
];

if (SevenZip::canAddFiles())
$types[] = ['fixtures.7z', UnifiedArchive::SEVEN_ZIP];

return $types;
}
}

0 comments on commit 718fff0

Please sign in to comment.