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
6 changes: 4 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ on: [push, pull_request]

jobs:
run:
name: PHP ${{ matrix.php-versions }}
runs-on: ubuntu-latest
name: PHP ${{ matrix.php-versions }} ${{ matrix.os }}
runs-on: ${{ matrix.os }}
if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name != github.repository

strategy:
matrix:
php-versions: ['7.2', '7.3', '7.4', '8.0']
os: ['ubuntu-latest', 'windows-latest']
fail-fast: false

steps:
Expand All @@ -21,6 +22,7 @@ jobs:
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-versions }}
extensions: bz2, zip

- name: Setup problem matchers
run: |
Expand Down
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
Loading