Skip to content

Commit 0ca3e26

Browse files
authored
Merge pull request #32 from fietserwin/windowstests
Windows tests
2 parents 39b3e18 + a54081a commit 0ca3e26

File tree

2 files changed

+65
-41
lines changed

2 files changed

+65
-41
lines changed

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();

tests/ZipTestCase.php

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,18 @@ protected function setUp() : void
1616
vfsStream::setup('home_root_path');
1717
}
1818

19+
/**
20+
* Returns the current dir with Linux style separator (/)
21+
*
22+
* This makes it easier to run the tests on Windows as well.
23+
*
24+
* @return string
25+
*/
26+
protected function getDir()
27+
{
28+
return str_replace('\\', '/', __DIR__);
29+
}
30+
1931
/**
2032
* Callback check function
2133
* @param FileInfo $fileinfo
@@ -51,7 +63,7 @@ public function testCreateDynamic()
5163
{
5264
$zip = new Zip();
5365

54-
$dir = dirname(__FILE__) . '/zip';
66+
$dir = $this->getDir() . '/zip';
5567
$tdir = ltrim($dir, '/');
5668

5769
$zip->create();
@@ -91,7 +103,7 @@ public function testCreateFile()
91103
{
92104
$zip = new Zip();
93105

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

@@ -135,7 +147,7 @@ public function testAddFileWithArchiveStreamIsClosed()
135147
{
136148
$this->expectException(ArchiveIOException::class);
137149
$zip = new Zip();
138-
$dir = dirname(__FILE__) . '/zip';
150+
$dir = $this->getDir() . '/zip';
139151
$zip->setCompression(0);
140152
$zip->close();
141153
$zip->addFile("$dir/testdata1.txt", "$dir/testdata1.txt");
@@ -158,7 +170,7 @@ public function testAddFileWithInvalidFile()
158170
*/
159171
public function testZipContent()
160172
{
161-
$dir = dirname(__FILE__) . '/zip';
173+
$dir = $this->getDir() . '/zip';
162174

163175
$zip = new Zip();
164176
$file = "$dir/test.zip";
@@ -177,7 +189,7 @@ public function testZipContent()
177189
public function testZipContentWithArchiveStreamIsClosed()
178190
{
179191
$this->expectException(ArchiveIOException::class);
180-
$dir = dirname(__FILE__) . '/zip';
192+
$dir = $this->getDir() . '/zip';
181193
$zip = new Zip();
182194
$file = "$dir/test.zip";
183195
$zip->open($file);
@@ -191,7 +203,7 @@ public function testZipContentWithArchiveStreamIsClosed()
191203
*/
192204
public function testDogFood()
193205
{
194-
$input = glob(dirname(__FILE__) . '/../src/*');
206+
$input = glob($this->getDir() . '/../src/*');
195207
$archive = sys_get_temp_dir() . '/dwziptest' . md5(time()) . '.zip';
196208
$extract = sys_get_temp_dir() . '/dwziptest' . md5(time() + 1);
197209

@@ -235,7 +247,7 @@ public function testZeroByteFile() {
235247

236248
$zip = new Zip();
237249
$zip->create($archive);
238-
$zip->addFile(__DIR__ . '/zip/zero.txt', 'foo/zero.txt');
250+
$zip->addFile($this->getDir() . '/zip/zero.txt', 'foo/zero.txt');
239251
$zip->close();
240252
$this->assertFileExists($archive);
241253

@@ -312,7 +324,7 @@ public function testCloseWithArchiveStreamIsClosed()
312324

313325
public function testSaveArchiveFile()
314326
{
315-
$dir = dirname(__FILE__) . '/tar';
327+
$dir = $this->getDir() . '/tar';
316328
$zip = new zip();
317329
$zip->setCompression(-1);
318330
$zip->create();
@@ -382,7 +394,7 @@ protected function native7ZipCheck($archive)
382394
*/
383395
public function testZipExtract()
384396
{
385-
$dir = dirname(__FILE__) . '/zip';
397+
$dir = $this->getDir() . '/zip';
386398
$out = sys_get_temp_dir() . '/dwziptest' . md5(time());
387399

388400
$zip = new Zip();
@@ -409,7 +421,7 @@ public function testZipExtract()
409421
public function testZipExtractWithArchiveStreamIsClosed()
410422
{
411423
$this->expectException(ArchiveIOException::class);
412-
$dir = dirname(__FILE__) . '/zip';
424+
$dir = $this->getDir() . '/zip';
413425
$out = sys_get_temp_dir() . '/dwziptest' . md5(time());
414426

415427
$zip = new Zip();
@@ -426,7 +438,7 @@ public function testZipExtractWithArchiveStreamIsClosed()
426438
*/
427439
public function testCompStripExtract()
428440
{
429-
$dir = dirname(__FILE__) . '/zip';
441+
$dir = $this->getDir() . '/zip';
430442
$out = sys_get_temp_dir() . '/dwziptest' . md5(time());
431443

432444
$zip = new Zip();
@@ -452,7 +464,7 @@ public function testCompStripExtract()
452464
*/
453465
public function testPrefixStripExtract()
454466
{
455-
$dir = dirname(__FILE__) . '/zip';
467+
$dir = $this->getDir() . '/zip';
456468
$out = sys_get_temp_dir() . '/dwziptest' . md5(time());
457469

458470
$zip = new Zip();
@@ -478,7 +490,7 @@ public function testPrefixStripExtract()
478490
*/
479491
public function testIncludeExtract()
480492
{
481-
$dir = dirname(__FILE__) . '/zip';
493+
$dir = $this->getDir() . '/zip';
482494
$out = sys_get_temp_dir() . '/dwziptest' . md5(time());
483495

484496
$zip = new Zip();
@@ -503,7 +515,7 @@ public function testIncludeExtract()
503515
*/
504516
public function testExcludeExtract()
505517
{
506-
$dir = dirname(__FILE__) . '/zip';
518+
$dir = $this->getDir() . '/zip';
507519
$out = sys_get_temp_dir() . '/dwziptest' . md5(time());
508520

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

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

545557
$zip = new Zip();
546-
$zip->open(__DIR__ . '/zip/issue14-windows.zip');
558+
$zip->open($this->getDir() . '/zip/issue14-windows.zip');
547559
$zip->extract($out);
548560
$this->assertFileExists("$out/täst.txt");
549561
}
@@ -570,5 +582,4 @@ public static function RDelete($target)
570582
rmdir($target);
571583
}
572584
}
573-
574585
}

0 commit comments

Comments
 (0)