1--TEST--
2Bug #71317: regression in opening tar based phar files
3--SKIPIF--
4<?php if (!extension_loaded('phar')) die('skip'); ?>
5<?php if (!extension_loaded("spl")) die("skip SPL not available"); ?>
6<?php if (!extension_loaded("zlib")) die("skip zlib not available"); ?>
7--FILE--
8<?php
9include dirname(__FILE__) . '/files/tarmaker.php.inc';
10
11$testDirectory = __DIR__ . '/files/test_bug71317';
12$testTarFilename  = __DIR__ . '/files/test_bug71317.tar';
13
14$tar = new tarmaker($testTarFilename, 'none');
15$tar->init();
16$tar->addFile('file1.txt', 'file1');
17$tar->addFile('file2.txt', 'file2');
18$tar->addFile('file3.txt', 'file3');
19$tar->addFile('file4.txt', 'file4');
20$tar->addFile('file5.txt', 'file5');
21$tar->addFile('file2.txt', 'file2a');
22$tar->close();
23
24$fname = str_replace('\\', '/', $testTarFilename);
25try {
26	mkdir($testDirectory);
27	$tar = new PharData($fname);
28	$tar->extractTo($testDirectory);
29
30	$fileContent = file_get_contents($testDirectory . '/file2.txt');
31	$expectedContent = 'file2a';
32	if ($fileContent !== $expectedContent) {
33		throw new Exception(sprintf('Contents of file2.txt ("%s") is invalid, expected "%s"', $fileContent, $expectedContent));
34	}
35} catch(Exception $e) {
36	echo $e->getMessage() . "\n";
37}
38?>
39===DONE===
40--CLEAN--
41<?php
42$testDirectory = __DIR__ . '/files/test_bug71317';
43$testTarFilename  = __DIR__ . '/files/test_bug71317.tar';
44
45unlink($testTarFilename);
46array_map('unlink', glob($testDirectory . "/*.txt"));
47rmdir($testDirectory);
48?>
49--EXPECT--
50===DONE===
51