Skip to content

Commit 2bdf379

Browse files
authored
Merge pull request #33 from splitbrain/windowstests
Windowstests
2 parents 211a219 + 0ca3e26 commit 2bdf379

File tree

3 files changed

+69
-43
lines changed

3 files changed

+69
-43
lines changed

.github/workflows/test.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@ on: [push, pull_request]
44

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

1111
strategy:
1212
matrix:
1313
php-versions: ['7.2', '7.3', '7.4', '8.0']
14+
os: ['ubuntu-latest', 'windows-latest']
1415
fail-fast: false
1516

1617
steps:
@@ -21,6 +22,7 @@ jobs:
2122
uses: shivammathur/setup-php@v2
2223
with:
2324
php-version: ${{ matrix.php-versions }}
25+
extensions: bz2, zip
2426

2527
- name: Setup problem matchers
2628
run: |

tests/TarTestCase.php

Lines changed: 37 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,18 @@ protected function tearDown() : void
3737
$this->extensions[] = null;
3838
}
3939

40+
/**
41+
* Returns the current dir with Linux style separator (/)
42+
*
43+
* This makes it easier to run the tests on Windows as well.
44+
*
45+
* @return string
46+
*/
47+
protected function getDir()
48+
{
49+
return str_replace('\\', '/', __DIR__);
50+
}
51+
4052
/**
4153
* Callback check function
4254
* @param FileInfo $fileinfo
@@ -79,7 +91,7 @@ public function testCreateDynamic()
7991
{
8092
$tar = new Tar();
8193

82-
$dir = dirname(__FILE__) . '/tar';
94+
$dir = $this->getDir() . '/tar';
8395
$tdir = ltrim($dir, '/');
8496

8597
$tar->create();
@@ -117,7 +129,7 @@ public function testCreateFile()
117129
{
118130
$tar = new Tar();
119131

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

@@ -153,7 +165,7 @@ public function testCreateFile()
153165
*/
154166
public function testTarcontent()
155167
{
156-
$dir = dirname(__FILE__) . '/tar';
168+
$dir = $this->getDir() . '/tar';
157169

158170
foreach ($this->extensions as $ext) {
159171
$tar = new Tar();
@@ -178,7 +190,7 @@ public function testTarcontent()
178190
public function testDogfood()
179191
{
180192
foreach ($this->extensions as $ext) {
181-
$input = glob(dirname(__FILE__) . '/../src/*');
193+
$input = glob($this->getDir() . '/../src/*');
182194
$archive = sys_get_temp_dir() . '/dwtartest' . md5(time()) . '.' . $ext;
183195
$extract = sys_get_temp_dir() . '/dwtartest' . md5(time() + 1);
184196

@@ -250,7 +262,7 @@ protected function nativeCheck($archive, $ext)
250262
*/
251263
public function testTarExtract()
252264
{
253-
$dir = dirname(__FILE__) . '/tar';
265+
$dir = $this->getDir() . '/tar';
254266
$out = sys_get_temp_dir() . '/dwtartest' . md5(time());
255267

256268
foreach ($this->extensions as $ext) {
@@ -277,7 +289,7 @@ public function testTarExtract()
277289
*/
278290
public function testCompStripExtract()
279291
{
280-
$dir = dirname(__FILE__) . '/tar';
292+
$dir = $this->getDir() . '/tar';
281293
$out = sys_get_temp_dir() . '/dwtartest' . md5(time());
282294

283295
foreach ($this->extensions as $ext) {
@@ -304,7 +316,7 @@ public function testCompStripExtract()
304316
*/
305317
public function testPrefixStripExtract()
306318
{
307-
$dir = dirname(__FILE__) . '/tar';
319+
$dir = $this->getDir() . '/tar';
308320
$out = sys_get_temp_dir() . '/dwtartest' . md5(time());
309321

310322
foreach ($this->extensions as $ext) {
@@ -331,7 +343,7 @@ public function testPrefixStripExtract()
331343
*/
332344
public function testIncludeExtract()
333345
{
334-
$dir = dirname(__FILE__) . '/tar';
346+
$dir = $this->getDir() . '/tar';
335347
$out = sys_get_temp_dir() . '/dwtartest' . md5(time());
336348

337349
foreach ($this->extensions as $ext) {
@@ -357,7 +369,7 @@ public function testIncludeExtract()
357369
*/
358370
public function testExcludeExtract()
359371
{
360-
$dir = dirname(__FILE__) . '/tar';
372+
$dir = $this->getDir() . '/tar';
361373
$out = sys_get_temp_dir() . '/dwtartest' . md5(time());
362374

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

397-
$dir = dirname(__FILE__) . '/tar';
409+
$dir = $this->getDir() . '/tar';
398410
$this->assertEquals(Tar::COMPRESS_NONE, $tar->filetype("$dir/test.tar"));
399411
$this->assertEquals(Tar::COMPRESS_GZIP, $tar->filetype("$dir/test.tgz"));
400412
$this->assertEquals(Tar::COMPRESS_BZIP, $tar->filetype("$dir/test.tbz"));
@@ -408,7 +420,7 @@ public function testFileType()
408420
*/
409421
public function testLongPathExtract()
410422
{
411-
$dir = dirname(__FILE__) . '/tar';
423+
$dir = $this->getDir() . '/tar';
412424
$out = vfsStream::url('home_root_path/dwtartest' . md5(time()));
413425

414426
foreach (array('ustar', 'gnu') as $format) {
@@ -504,7 +516,7 @@ public function testCreateLongPathGnu()
504516
*/
505517
public function testTarBomb()
506518
{
507-
$dir = dirname(__FILE__) . '/tar';
519+
$dir = $this->getDir() . '/tar';
508520
$out = vfsStream::url('home_root_path/dwtartest' . md5(time()));
509521

510522
$tar = new Tar();
@@ -524,7 +536,7 @@ public function testTarBomb()
524536
*/
525537
public function testZeroFile()
526538
{
527-
$dir = dirname(__FILE__) . '/tar';
539+
$dir = $this->getDir() . '/tar';
528540
$tar = new Tar();
529541
$tar->setCompression(0);
530542
$tar->create();
@@ -554,7 +566,7 @@ public function testZeroByteFile() {
554566

555567
$tar = new Tar();
556568
$tar->create($archive);
557-
$tar->addFile(__DIR__ . '/zip/zero.txt', 'foo/zero.txt');
569+
$tar->addFile($this->getDir() . '/zip/zero.txt', 'foo/zero.txt');
558570
$tar->close();
559571
$this->assertFileExists($archive);
560572

@@ -582,7 +594,7 @@ public function testZeroByteFile() {
582594
*/
583595
public function testBlockFile()
584596
{
585-
$dir = dirname(__FILE__) . '/tar';
597+
$dir = $this->getDir() . '/tar';
586598
$tar = new Tar();
587599
$tar->setCompression(0);
588600
$tar->create();
@@ -609,7 +621,7 @@ public function testBlockData()
609621
public function testGzipIsValid()
610622
{
611623
foreach (['tgz', 'tar.gz'] as $ext) {
612-
$input = glob(dirname(__FILE__) . '/../src/*');
624+
$input = glob($this->getDir() . '/../src/*');
613625
$archive = sys_get_temp_dir() . '/dwtartest' . md5(time()) . '.' . $ext;
614626
$extract = sys_get_temp_dir() . '/dwtartest' . md5(time() + 1);
615627

@@ -649,8 +661,9 @@ public function testContentsWithInvalidArchiveStream()
649661
public function testExtractWithInvalidOutDir()
650662
{
651663
$this->expectException(ArchiveIOException::class);
652-
$dir = dirname(__FILE__) . '/tar';
653-
$out = '/root/invalid_out_dir';
664+
$dir = $this->getDir() . '/tar';
665+
// Fails on Linux and Windows.
666+
$out = '/root/invalid_out_dir:';
654667

655668
$tar = new Tar();
656669

@@ -661,7 +674,7 @@ public function testExtractWithInvalidOutDir()
661674
public function testExtractWithArchiveStreamIsClosed()
662675
{
663676
$this->expectException(ArchiveIOException::class);
664-
$dir = dirname(__FILE__) . '/tar';
677+
$dir = $this->getDir() . '/tar';
665678
$out = '/root/invalid_out_dir';
666679

667680
$tar = new Tar();
@@ -674,11 +687,11 @@ public function testExtractWithArchiveStreamIsClosed()
674687
public function testCreateWithInvalidFile()
675688
{
676689
$this->expectException(ArchiveIOException::class);
677-
$dir = dirname(__FILE__) . '/tar';
690+
$dir = $this->getDir() . '/tar';
678691
$tar = new Tar();
679692

680693
$tar->open("$dir/tarbomb.tgz");
681-
$tar->create('/root/invalid_file');
694+
$tar->create('/root/invalid_file:');
682695
}
683696

684697
public function testAddFileWithArchiveStreamIsClosed()
@@ -730,7 +743,7 @@ public function testCloseHasBeenClosed()
730743
*/
731744
public function testGetArchiveWithBzipCompress()
732745
{
733-
$dir = dirname(__FILE__) . '/tar';
746+
$dir = $this->getDir() . '/tar';
734747
$tar = new Tar();
735748
$tar->setCompression(9, Tar::COMPRESS_BZIP);
736749
$tar->create();
@@ -742,7 +755,7 @@ public function testGetArchiveWithBzipCompress()
742755

743756
public function testSaveWithCompressionAuto()
744757
{
745-
$dir = dirname(__FILE__) . '/tar';
758+
$dir = $this->getDir() . '/tar';
746759
$tar = new Tar();
747760
$tar->setCompression(-1);
748761
$tar->create();
@@ -755,7 +768,7 @@ public function testSaveWithCompressionAuto()
755768
public function testSaveWithInvalidDestinationFile()
756769
{
757770
$this->expectException(ArchiveIOException::class);
758-
$dir = dirname(__FILE__) . '/tar';
771+
$dir = $this->getDir() . '/tar';
759772
$tar = new Tar();
760773
$tar->setCompression();
761774
$tar->create();

0 commit comments

Comments
 (0)