Skip to content

Commit

Permalink
Merge tag '3.2.2' into develop
Browse files Browse the repository at this point in the history
Tagging hotfix 3.2.2 3.2.2

# Conflicts:
#	.travis.yml
#	tests/ZipFileTest.php
  • Loading branch information
Ne-Lexa committed Feb 4, 2020
2 parents 820c63c + 074443d commit f3d7697
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 4 deletions.
5 changes: 4 additions & 1 deletion src/Model/Data/ZipFileData.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use PhpZip\Exception\ZipException;
use PhpZip\Model\ZipData;
use PhpZip\Model\ZipEntry;

/**
* Class ZipFileData.
Expand All @@ -16,11 +17,12 @@ class ZipFileData implements ZipData
/**
* ZipStringData constructor.
*
* @param ZipEntry $zipEntry
* @param \SplFileInfo $fileInfo
*
* @throws ZipException
*/
public function __construct(\SplFileInfo $fileInfo)
public function __construct(ZipEntry $zipEntry, \SplFileInfo $fileInfo)
{
if (!$fileInfo->isFile()) {
throw new ZipException('$fileInfo is not a file.');
Expand All @@ -31,6 +33,7 @@ public function __construct(\SplFileInfo $fileInfo)
}

$this->file = $fileInfo;
$zipEntry->setUncompressedSize($fileInfo->getSize());
}

/**
Expand Down
3 changes: 1 addition & 2 deletions src/ZipFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -711,10 +711,9 @@ public function addSplFile(\SplFileInfo $file, $entryName = null, array $options
ZipCompressionMethod::DEFLATED;
}

$zipEntry->setUncompressedSize($file->getSize());
$zipEntry->setCompressionMethod($compressionMethod);

$zipData = new ZipFileData($file);
$zipData = new ZipFileData($zipEntry, $file);
} elseif ($file->isDir()) {
$zipEntry->setCompressionMethod(ZipCompressionMethod::STORED);
$zipEntry->setUncompressedSize(0);
Expand Down
3 changes: 2 additions & 1 deletion tests/ZipEntryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1571,9 +1571,10 @@ public function provideExtraTime()
public function testClone()
{
$newUnixExtra = new NewUnixExtraField();
$zipData = new ZipFileData(new \SplFileInfo(__FILE__));

$zipEntry = new ZipEntry('entry');
$zipData = new ZipFileData($zipEntry, new \SplFileInfo(__FILE__));

$zipEntry->addExtraField($newUnixExtra);
$zipEntry->setData($zipData);

Expand Down
35 changes: 35 additions & 0 deletions tests/ZipFileTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use PhpZip\Exception\ZipEntryNotFoundException;
use PhpZip\Exception\ZipException;
use PhpZip\Exception\ZipUnsupportMethodException;
use PhpZip\Model\Data\ZipFileData;
use PhpZip\Model\ZipEntry;
use PhpZip\Model\ZipInfo;
use PhpZip\Util\FilesUtil;
Expand Down Expand Up @@ -2459,6 +2460,10 @@ public function testMultiSave()
$zipFile->close();
}

/**
* @throws ZipEntryNotFoundException
* @throws ZipException
*/
public function testNoData()
{
$this->setExpectedException(ZipException::class, 'No data for zip entry file');
Expand All @@ -2476,4 +2481,34 @@ public function testNoData()
$zipFile->close();
}
}

/**
* @throws ZipEntryNotFoundException
* @throws ZipException
*/
public function testReplaceEntryContentsByFile()
{
$entryName = basename(__FILE__);

$zipFile = new ZipFile();
$zipFile[$entryName] = 'contents';
$zipFile->saveAsFile($this->outputFilename);
$zipFile->close();

$zipFile->openFile($this->outputFilename);
$entry = $zipFile->getEntry($entryName);
$data = new ZipFileData($entry, new \SplFileInfo(__FILE__));
$entry->setData($data);
$zipFile->saveAsFile($this->outputFilename);
$zipFile->close();

self::assertCorrectZipArchive($this->outputFilename);

$zipFile->openFile($this->outputFilename);
static::assertSame(
$zipFile->getEntryContents($entryName),
file_get_contents(__FILE__)
);
$zipFile->close();
}
}

0 comments on commit f3d7697

Please sign in to comment.