Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 37 additions & 24 deletions tests/TarTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,18 @@ protected function tearDown() : void
$this->extensions[] = null;
}

/**
* Returns the current dir with Linux style separator (/)
*
* This makes it easier to run the tests on Windows as well.
*
* @return string
*/
protected function getDir()
{
return str_replace('\\', '/', __DIR__);
}

/**
* Callback check function
* @param FileInfo $fileinfo
Expand Down Expand Up @@ -79,7 +91,7 @@ public function testCreateDynamic()
{
$tar = new Tar();

$dir = dirname(__FILE__) . '/tar';
$dir = $this->getDir() . '/tar';
$tdir = ltrim($dir, '/');

$tar->create();
Expand Down Expand Up @@ -117,7 +129,7 @@ public function testCreateFile()
{
$tar = new Tar();

$dir = dirname(__FILE__) . '/tar';
$dir = $this->getDir() . '/tar';
$tdir = ltrim($dir, '/');
$tmp = vfsStream::url('home_root_path/test.tar');

Expand Down Expand Up @@ -153,7 +165,7 @@ public function testCreateFile()
*/
public function testTarcontent()
{
$dir = dirname(__FILE__) . '/tar';
$dir = $this->getDir() . '/tar';

foreach ($this->extensions as $ext) {
$tar = new Tar();
Expand All @@ -178,7 +190,7 @@ public function testTarcontent()
public function testDogfood()
{
foreach ($this->extensions as $ext) {
$input = glob(dirname(__FILE__) . '/../src/*');
$input = glob($this->getDir() . '/../src/*');
$archive = sys_get_temp_dir() . '/dwtartest' . md5(time()) . '.' . $ext;
$extract = sys_get_temp_dir() . '/dwtartest' . md5(time() + 1);

Expand Down Expand Up @@ -250,7 +262,7 @@ protected function nativeCheck($archive, $ext)
*/
public function testTarExtract()
{
$dir = dirname(__FILE__) . '/tar';
$dir = $this->getDir() . '/tar';
$out = sys_get_temp_dir() . '/dwtartest' . md5(time());

foreach ($this->extensions as $ext) {
Expand All @@ -277,7 +289,7 @@ public function testTarExtract()
*/
public function testCompStripExtract()
{
$dir = dirname(__FILE__) . '/tar';
$dir = $this->getDir() . '/tar';
$out = sys_get_temp_dir() . '/dwtartest' . md5(time());

foreach ($this->extensions as $ext) {
Expand All @@ -304,7 +316,7 @@ public function testCompStripExtract()
*/
public function testPrefixStripExtract()
{
$dir = dirname(__FILE__) . '/tar';
$dir = $this->getDir() . '/tar';
$out = sys_get_temp_dir() . '/dwtartest' . md5(time());

foreach ($this->extensions as $ext) {
Expand All @@ -331,7 +343,7 @@ public function testPrefixStripExtract()
*/
public function testIncludeExtract()
{
$dir = dirname(__FILE__) . '/tar';
$dir = $this->getDir() . '/tar';
$out = sys_get_temp_dir() . '/dwtartest' . md5(time());

foreach ($this->extensions as $ext) {
Expand All @@ -357,7 +369,7 @@ public function testIncludeExtract()
*/
public function testExcludeExtract()
{
$dir = dirname(__FILE__) . '/tar';
$dir = $this->getDir() . '/tar';
$out = sys_get_temp_dir() . '/dwtartest' . md5(time());

foreach ($this->extensions as $ext) {
Expand Down Expand Up @@ -394,7 +406,7 @@ public function testFileType()
$this->assertEquals(Tar::COMPRESS_BZIP, $tar->filetype('foo.tar.BZ2'));
$this->assertEquals(Tar::COMPRESS_BZIP, $tar->filetype('foo.tar.bz2'));

$dir = dirname(__FILE__) . '/tar';
$dir = $this->getDir() . '/tar';
$this->assertEquals(Tar::COMPRESS_NONE, $tar->filetype("$dir/test.tar"));
$this->assertEquals(Tar::COMPRESS_GZIP, $tar->filetype("$dir/test.tgz"));
$this->assertEquals(Tar::COMPRESS_BZIP, $tar->filetype("$dir/test.tbz"));
Expand All @@ -408,7 +420,7 @@ public function testFileType()
*/
public function testLongPathExtract()
{
$dir = dirname(__FILE__) . '/tar';
$dir = $this->getDir() . '/tar';
$out = vfsStream::url('home_root_path/dwtartest' . md5(time()));

foreach (array('ustar', 'gnu') as $format) {
Expand Down Expand Up @@ -504,7 +516,7 @@ public function testCreateLongPathGnu()
*/
public function testTarBomb()
{
$dir = dirname(__FILE__) . '/tar';
$dir = $this->getDir() . '/tar';
$out = vfsStream::url('home_root_path/dwtartest' . md5(time()));

$tar = new Tar();
Expand All @@ -524,7 +536,7 @@ public function testTarBomb()
*/
public function testZeroFile()
{
$dir = dirname(__FILE__) . '/tar';
$dir = $this->getDir() . '/tar';
$tar = new Tar();
$tar->setCompression(0);
$tar->create();
Expand Down Expand Up @@ -554,7 +566,7 @@ public function testZeroByteFile() {

$tar = new Tar();
$tar->create($archive);
$tar->addFile(__DIR__ . '/zip/zero.txt', 'foo/zero.txt');
$tar->addFile($this->getDir() . '/zip/zero.txt', 'foo/zero.txt');
$tar->close();
$this->assertFileExists($archive);

Expand Down Expand Up @@ -582,7 +594,7 @@ public function testZeroByteFile() {
*/
public function testBlockFile()
{
$dir = dirname(__FILE__) . '/tar';
$dir = $this->getDir() . '/tar';
$tar = new Tar();
$tar->setCompression(0);
$tar->create();
Expand All @@ -609,7 +621,7 @@ public function testBlockData()
public function testGzipIsValid()
{
foreach (['tgz', 'tar.gz'] as $ext) {
$input = glob(dirname(__FILE__) . '/../src/*');
$input = glob($this->getDir() . '/../src/*');
$archive = sys_get_temp_dir() . '/dwtartest' . md5(time()) . '.' . $ext;
$extract = sys_get_temp_dir() . '/dwtartest' . md5(time() + 1);

Expand Down Expand Up @@ -649,8 +661,9 @@ public function testContentsWithInvalidArchiveStream()
public function testExtractWithInvalidOutDir()
{
$this->expectException(ArchiveIOException::class);
$dir = dirname(__FILE__) . '/tar';
$out = '/root/invalid_out_dir';
$dir = $this->getDir() . '/tar';
// Fails on Linux and Windows.
$out = '/root/invalid_out_dir:';

$tar = new Tar();

Expand All @@ -661,7 +674,7 @@ public function testExtractWithInvalidOutDir()
public function testExtractWithArchiveStreamIsClosed()
{
$this->expectException(ArchiveIOException::class);
$dir = dirname(__FILE__) . '/tar';
$dir = $this->getDir() . '/tar';
$out = '/root/invalid_out_dir';

$tar = new Tar();
Expand All @@ -674,11 +687,11 @@ public function testExtractWithArchiveStreamIsClosed()
public function testCreateWithInvalidFile()
{
$this->expectException(ArchiveIOException::class);
$dir = dirname(__FILE__) . '/tar';
$dir = $this->getDir() . '/tar';
$tar = new Tar();

$tar->open("$dir/tarbomb.tgz");
$tar->create('/root/invalid_file');
$tar->create('/root/invalid_file:');
}

public function testAddFileWithArchiveStreamIsClosed()
Expand Down Expand Up @@ -730,7 +743,7 @@ public function testCloseHasBeenClosed()
*/
public function testGetArchiveWithBzipCompress()
{
$dir = dirname(__FILE__) . '/tar';
$dir = $this->getDir() . '/tar';
$tar = new Tar();
$tar->setCompression(9, Tar::COMPRESS_BZIP);
$tar->create();
Expand All @@ -742,7 +755,7 @@ public function testGetArchiveWithBzipCompress()

public function testSaveWithCompressionAuto()
{
$dir = dirname(__FILE__) . '/tar';
$dir = $this->getDir() . '/tar';
$tar = new Tar();
$tar->setCompression(-1);
$tar->create();
Expand All @@ -755,7 +768,7 @@ public function testSaveWithCompressionAuto()
public function testSaveWithInvalidDestinationFile()
{
$this->expectException(ArchiveIOException::class);
$dir = dirname(__FILE__) . '/tar';
$dir = $this->getDir() . '/tar';
$tar = new Tar();
$tar->setCompression();
$tar->create();
Expand Down
45 changes: 28 additions & 17 deletions tests/ZipTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,18 @@ protected function setUp() : void
vfsStream::setup('home_root_path');
}

/**
* Returns the current dir with Linux style separator (/)
*
* This makes it easier to run the tests on Windows as well.
*
* @return string
*/
protected function getDir()
{
return str_replace('\\', '/', __DIR__);
}

/**
* Callback check function
* @param FileInfo $fileinfo
Expand Down Expand Up @@ -51,7 +63,7 @@ public function testCreateDynamic()
{
$zip = new Zip();

$dir = dirname(__FILE__) . '/zip';
$dir = $this->getDir() . '/zip';
$tdir = ltrim($dir, '/');

$zip->create();
Expand Down Expand Up @@ -91,7 +103,7 @@ public function testCreateFile()
{
$zip = new Zip();

$dir = dirname(__FILE__) . '/zip';
$dir = $this->getDir() . '/zip';
$tdir = ltrim($dir, '/');
$tmp = vfsStream::url('home_root_path/test.zip');

Expand Down Expand Up @@ -135,7 +147,7 @@ public function testAddFileWithArchiveStreamIsClosed()
{
$this->expectException(ArchiveIOException::class);
$zip = new Zip();
$dir = dirname(__FILE__) . '/zip';
$dir = $this->getDir() . '/zip';
$zip->setCompression(0);
$zip->close();
$zip->addFile("$dir/testdata1.txt", "$dir/testdata1.txt");
Expand All @@ -158,7 +170,7 @@ public function testAddFileWithInvalidFile()
*/
public function testZipContent()
{
$dir = dirname(__FILE__) . '/zip';
$dir = $this->getDir() . '/zip';

$zip = new Zip();
$file = "$dir/test.zip";
Expand All @@ -177,7 +189,7 @@ public function testZipContent()
public function testZipContentWithArchiveStreamIsClosed()
{
$this->expectException(ArchiveIOException::class);
$dir = dirname(__FILE__) . '/zip';
$dir = $this->getDir() . '/zip';
$zip = new Zip();
$file = "$dir/test.zip";
$zip->open($file);
Expand All @@ -191,7 +203,7 @@ public function testZipContentWithArchiveStreamIsClosed()
*/
public function testDogFood()
{
$input = glob(dirname(__FILE__) . '/../src/*');
$input = glob($this->getDir() . '/../src/*');
$archive = sys_get_temp_dir() . '/dwziptest' . md5(time()) . '.zip';
$extract = sys_get_temp_dir() . '/dwziptest' . md5(time() + 1);

Expand Down Expand Up @@ -235,7 +247,7 @@ public function testZeroByteFile() {

$zip = new Zip();
$zip->create($archive);
$zip->addFile(__DIR__ . '/zip/zero.txt', 'foo/zero.txt');
$zip->addFile($this->getDir() . '/zip/zero.txt', 'foo/zero.txt');
$zip->close();
$this->assertFileExists($archive);

Expand Down Expand Up @@ -312,7 +324,7 @@ public function testCloseWithArchiveStreamIsClosed()

public function testSaveArchiveFile()
{
$dir = dirname(__FILE__) . '/tar';
$dir = $this->getDir() . '/tar';
$zip = new zip();
$zip->setCompression(-1);
$zip->create();
Expand Down Expand Up @@ -382,7 +394,7 @@ protected function native7ZipCheck($archive)
*/
public function testZipExtract()
{
$dir = dirname(__FILE__) . '/zip';
$dir = $this->getDir() . '/zip';
$out = sys_get_temp_dir() . '/dwziptest' . md5(time());

$zip = new Zip();
Expand All @@ -409,7 +421,7 @@ public function testZipExtract()
public function testZipExtractWithArchiveStreamIsClosed()
{
$this->expectException(ArchiveIOException::class);
$dir = dirname(__FILE__) . '/zip';
$dir = $this->getDir() . '/zip';
$out = sys_get_temp_dir() . '/dwziptest' . md5(time());

$zip = new Zip();
Expand All @@ -426,7 +438,7 @@ public function testZipExtractWithArchiveStreamIsClosed()
*/
public function testCompStripExtract()
{
$dir = dirname(__FILE__) . '/zip';
$dir = $this->getDir() . '/zip';
$out = sys_get_temp_dir() . '/dwziptest' . md5(time());

$zip = new Zip();
Expand All @@ -452,7 +464,7 @@ public function testCompStripExtract()
*/
public function testPrefixStripExtract()
{
$dir = dirname(__FILE__) . '/zip';
$dir = $this->getDir() . '/zip';
$out = sys_get_temp_dir() . '/dwziptest' . md5(time());

$zip = new Zip();
Expand All @@ -478,7 +490,7 @@ public function testPrefixStripExtract()
*/
public function testIncludeExtract()
{
$dir = dirname(__FILE__) . '/zip';
$dir = $this->getDir() . '/zip';
$out = sys_get_temp_dir() . '/dwziptest' . md5(time());

$zip = new Zip();
Expand All @@ -503,7 +515,7 @@ public function testIncludeExtract()
*/
public function testExcludeExtract()
{
$dir = dirname(__FILE__) . '/zip';
$dir = $this->getDir() . '/zip';
$out = sys_get_temp_dir() . '/dwziptest' . md5(time());

$zip = new Zip();
Expand All @@ -530,7 +542,7 @@ public function testUmlautWinrar()
$out = vfsStream::url('home_root_path/dwtartest' . md5(time()));

$zip = new Zip();
$zip->open(__DIR__ . '/zip/issue14-winrar.zip');
$zip->open($this->getDir() . '/zip/issue14-winrar.zip');
$zip->extract($out);
$this->assertFileExists("$out/tüst.txt");
}
Expand All @@ -543,7 +555,7 @@ public function testUmlautWindows()
$out = vfsStream::url('home_root_path/dwtartest' . md5(time()));

$zip = new Zip();
$zip->open(__DIR__ . '/zip/issue14-windows.zip');
$zip->open($this->getDir() . '/zip/issue14-windows.zip');
$zip->extract($out);
$this->assertFileExists("$out/täst.txt");
}
Expand All @@ -570,5 +582,4 @@ public static function RDelete($target)
rmdir($target);
}
}

}