Fix CS issues, refs #6159
parent
0a337e7c75
commit
61511cfed6
|
@ -29,10 +29,11 @@ use ZipArchive;
|
||||||
*/
|
*/
|
||||||
class ZipDownloader extends ArchiveDownloader
|
class ZipDownloader extends ArchiveDownloader
|
||||||
{
|
{
|
||||||
|
private static $hasSystemUnzip;
|
||||||
|
private static $hasZipArchive;
|
||||||
|
private static $isWindows;
|
||||||
|
|
||||||
protected $process;
|
protected $process;
|
||||||
public static $hasSystemUnzip;
|
|
||||||
public static $hasZipArchive;
|
|
||||||
public static $isWindows;
|
|
||||||
private $zipArchiveObject;
|
private $zipArchiveObject;
|
||||||
|
|
||||||
public function __construct(IOInterface $io, Config $config, EventDispatcher $eventDispatcher = null, Cache $cache = null, ProcessExecutor $process = null, RemoteFilesystem $rfs = null)
|
public function __construct(IOInterface $io, Config $config, EventDispatcher $eventDispatcher = null, Cache $cache = null, ProcessExecutor $process = null, RemoteFilesystem $rfs = null)
|
||||||
|
@ -107,17 +108,14 @@ class ZipDownloader extends ArchiveDownloader
|
||||||
$processError = $e;
|
$processError = $e;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (! self::$hasZipArchive) {
|
|
||||||
$isLastChance = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($isLastChance) {
|
if ($isLastChance) {
|
||||||
throw $processError;
|
throw $processError;
|
||||||
} else {
|
|
||||||
$this->io->write($processError->getMessage());
|
|
||||||
$this->io->write('Unzip with unzip command failed, falling back to ZipArchive class');
|
|
||||||
return $this->extractWithZipArchive($file, $path, true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->io->writeError(' '.$processError->getMessage());
|
||||||
|
$this->io->writeError(' Unzip with unzip command failed, falling back to ZipArchive class');
|
||||||
|
|
||||||
|
return $this->extractWithZipArchive($file, $path, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -150,10 +148,11 @@ class ZipDownloader extends ArchiveDownloader
|
||||||
|
|
||||||
if (true === $extractResult) {
|
if (true === $extractResult) {
|
||||||
$zipArchive->close();
|
$zipArchive->close();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
} else {
|
|
||||||
$processError = new \RuntimeException(rtrim("There was an error extracting the ZIP file, it is either corrupted or using an invalid format.\n"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$processError = new \RuntimeException(rtrim("There was an error extracting the ZIP file, it is either corrupted or using an invalid format.\n"));
|
||||||
} else {
|
} else {
|
||||||
$processError = new \UnexpectedValueException(rtrim($this->getErrorMessage($retval, $file)."\n"), $retval);
|
$processError = new \UnexpectedValueException(rtrim($this->getErrorMessage($retval, $file)."\n"), $retval);
|
||||||
}
|
}
|
||||||
|
@ -163,11 +162,12 @@ class ZipDownloader extends ArchiveDownloader
|
||||||
|
|
||||||
if ($isLastChance) {
|
if ($isLastChance) {
|
||||||
throw $processError;
|
throw $processError;
|
||||||
} else {
|
|
||||||
$this->io->write($processError->getMessage());
|
|
||||||
$this->io->write('Unzip with ZipArchive class failed, falling back to unzip command');
|
|
||||||
return $this->extractWithSystemUnzip($file, $path, true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->io->writeError(' '.$processError->getMessage());
|
||||||
|
$this->io->writeError(' Unzip with ZipArchive class failed, falling back to unzip command');
|
||||||
|
|
||||||
|
return $this->extractWithSystemUnzip($file, $path, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -37,8 +37,8 @@ class ZipDownloaderTest extends TestCase
|
||||||
{
|
{
|
||||||
$fs = new Filesystem;
|
$fs = new Filesystem;
|
||||||
$fs->removeDirectory($this->testDir);
|
$fs->removeDirectory($this->testDir);
|
||||||
ZipDownloader::$hasSystemUnzip = null;
|
$this->setPrivateProperty('hasSystemUnzip', null);
|
||||||
ZipDownloader::$hasZipArchive = null;
|
$this->setPrivateProperty('hasZipArchive', null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setPrivateProperty($name, $value, $obj = null)
|
public function setPrivateProperty($name, $value, $obj = null)
|
||||||
|
@ -95,7 +95,7 @@ class ZipDownloaderTest extends TestCase
|
||||||
|
|
||||||
$downloader = new ZipDownloader($this->io, $this->config);
|
$downloader = new ZipDownloader($this->io, $this->config);
|
||||||
|
|
||||||
ZipDownloader::$hasSystemUnzip = false;
|
$this->setPrivateProperty('hasSystemUnzip', false);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$downloader->download($packageMock, sys_get_temp_dir().'/composer-zip-test');
|
$downloader->download($packageMock, sys_get_temp_dir().'/composer-zip-test');
|
||||||
|
@ -111,8 +111,8 @@ class ZipDownloaderTest extends TestCase
|
||||||
*/
|
*/
|
||||||
public function testZipArchiveOnlyFailed()
|
public function testZipArchiveOnlyFailed()
|
||||||
{
|
{
|
||||||
MockedZipDownloader::$hasSystemUnzip = false;
|
$this->setPrivateProperty('hasSystemUnzip', false);
|
||||||
MockedZipDownloader::$hasZipArchive = true;
|
$this->setPrivateProperty('hasZipArchive', true);
|
||||||
$downloader = new MockedZipDownloader($this->io, $this->config);
|
$downloader = new MockedZipDownloader($this->io, $this->config);
|
||||||
|
|
||||||
$zipArchive = $this->getMock('ZipArchive');
|
$zipArchive = $this->getMock('ZipArchive');
|
||||||
|
@ -132,8 +132,8 @@ class ZipDownloaderTest extends TestCase
|
||||||
*/
|
*/
|
||||||
public function testZipArchiveOnlyGood()
|
public function testZipArchiveOnlyGood()
|
||||||
{
|
{
|
||||||
MockedZipDownloader::$hasSystemUnzip = false;
|
$this->setPrivateProperty('hasSystemUnzip', false);
|
||||||
MockedZipDownloader::$hasZipArchive = true;
|
$this->setPrivateProperty('hasZipArchive', true);
|
||||||
$downloader = new MockedZipDownloader($this->io, $this->config);
|
$downloader = new MockedZipDownloader($this->io, $this->config);
|
||||||
|
|
||||||
$zipArchive = $this->getMock('ZipArchive');
|
$zipArchive = $this->getMock('ZipArchive');
|
||||||
|
@ -154,8 +154,8 @@ class ZipDownloaderTest extends TestCase
|
||||||
*/
|
*/
|
||||||
public function testSystemUnzipOnlyFailed()
|
public function testSystemUnzipOnlyFailed()
|
||||||
{
|
{
|
||||||
MockedZipDownloader::$hasSystemUnzip = true;
|
$this->setPrivateProperty('hasSystemUnzip', true);
|
||||||
MockedZipDownloader::$hasZipArchive = false;
|
$this->setPrivateProperty('hasZipArchive', false);
|
||||||
$processExecutor = $this->getMock('Composer\Util\ProcessExecutor');
|
$processExecutor = $this->getMock('Composer\Util\ProcessExecutor');
|
||||||
$processExecutor->expects($this->at(0))
|
$processExecutor->expects($this->at(0))
|
||||||
->method('execute')
|
->method('execute')
|
||||||
|
@ -167,8 +167,8 @@ class ZipDownloaderTest extends TestCase
|
||||||
|
|
||||||
public function testSystemUnzipOnlyGood()
|
public function testSystemUnzipOnlyGood()
|
||||||
{
|
{
|
||||||
MockedZipDownloader::$hasSystemUnzip = true;
|
$this->setPrivateProperty('hasSystemUnzip', true);
|
||||||
MockedZipDownloader::$hasZipArchive = false;
|
$this->setPrivateProperty('hasZipArchive', false);
|
||||||
$processExecutor = $this->getMock('Composer\Util\ProcessExecutor');
|
$processExecutor = $this->getMock('Composer\Util\ProcessExecutor');
|
||||||
$processExecutor->expects($this->at(0))
|
$processExecutor->expects($this->at(0))
|
||||||
->method('execute')
|
->method('execute')
|
||||||
|
@ -180,9 +180,9 @@ class ZipDownloaderTest extends TestCase
|
||||||
|
|
||||||
public function testNonWindowsFallbackGood()
|
public function testNonWindowsFallbackGood()
|
||||||
{
|
{
|
||||||
MockedZipDownloader::$isWindows = false;
|
$this->setPrivateProperty('isWindows', false);
|
||||||
MockedZipDownloader::$hasSystemUnzip = true;
|
$this->setPrivateProperty('hasSystemUnzip', true);
|
||||||
MockedZipDownloader::$hasZipArchive = true;
|
$this->setPrivateProperty('hasZipArchive', true);
|
||||||
|
|
||||||
$processExecutor = $this->getMock('Composer\Util\ProcessExecutor');
|
$processExecutor = $this->getMock('Composer\Util\ProcessExecutor');
|
||||||
$processExecutor->expects($this->at(0))
|
$processExecutor->expects($this->at(0))
|
||||||
|
@ -208,9 +208,9 @@ class ZipDownloaderTest extends TestCase
|
||||||
*/
|
*/
|
||||||
public function testNonWindowsFallbackFailed()
|
public function testNonWindowsFallbackFailed()
|
||||||
{
|
{
|
||||||
MockedZipDownloader::$isWindows = false;
|
$this->setPrivateProperty('isWindows', false);
|
||||||
MockedZipDownloader::$hasSystemUnzip = true;
|
$this->setPrivateProperty('hasSystemUnzip', true);
|
||||||
MockedZipDownloader::$hasZipArchive = true;
|
$this->setPrivateProperty('hasZipArchive', true);
|
||||||
|
|
||||||
$processExecutor = $this->getMock('Composer\Util\ProcessExecutor');
|
$processExecutor = $this->getMock('Composer\Util\ProcessExecutor');
|
||||||
$processExecutor->expects($this->at(0))
|
$processExecutor->expects($this->at(0))
|
||||||
|
@ -232,9 +232,9 @@ class ZipDownloaderTest extends TestCase
|
||||||
|
|
||||||
public function testWindowsFallbackGood()
|
public function testWindowsFallbackGood()
|
||||||
{
|
{
|
||||||
MockedZipDownloader::$isWindows = true;
|
$this->setPrivateProperty('isWindows', true);
|
||||||
MockedZipDownloader::$hasSystemUnzip = true;
|
$this->setPrivateProperty('hasSystemUnzip', true);
|
||||||
MockedZipDownloader::$hasZipArchive = true;
|
$this->setPrivateProperty('hasZipArchive', true);
|
||||||
|
|
||||||
$processExecutor = $this->getMock('Composer\Util\ProcessExecutor');
|
$processExecutor = $this->getMock('Composer\Util\ProcessExecutor');
|
||||||
$processExecutor->expects($this->atLeastOnce())
|
$processExecutor->expects($this->atLeastOnce())
|
||||||
|
@ -260,9 +260,9 @@ class ZipDownloaderTest extends TestCase
|
||||||
*/
|
*/
|
||||||
public function testWindowsFallbackFailed()
|
public function testWindowsFallbackFailed()
|
||||||
{
|
{
|
||||||
MockedZipDownloader::$isWindows = true;
|
$this->setPrivateProperty('isWindows', true);
|
||||||
MockedZipDownloader::$hasSystemUnzip = true;
|
$this->setPrivateProperty('hasSystemUnzip', true);
|
||||||
MockedZipDownloader::$hasZipArchive = true;
|
$this->setPrivateProperty('hasZipArchive', true);
|
||||||
|
|
||||||
$processExecutor = $this->getMock('Composer\Util\ProcessExecutor');
|
$processExecutor = $this->getMock('Composer\Util\ProcessExecutor');
|
||||||
$processExecutor->expects($this->atLeastOnce())
|
$processExecutor->expects($this->atLeastOnce())
|
||||||
|
|
Loading…
Reference in New Issue