1--TEST-- 2Phar: Phar::extractTo() 3--SKIPIF-- 4<?php if (!extension_loaded("phar")) die("skip"); ?> 5--CONFLICTS-- 6tempmanifest1.phar.php 7--INI-- 8phar.readonly=0 9--FILE-- 10<?php 11 12$fname = __DIR__ . '/tempmanifest1.phar.php'; 13$pname = 'phar://' . $fname; 14 15$a = new Phar($fname); 16$a['file1.txt'] = 'hi'; 17$a['file2.txt'] = 'hi2'; 18$a['subdir/ectory/file.txt'] = 'hi3'; 19$a->mount($pname . '/mount', __FILE__); 20$a->addEmptyDir('one/level'); 21 22$a->extractTo(__DIR__ . '/extract', 'mount'); 23$a->extractTo(__DIR__ . '/extract'); 24 25$out = array(); 26 27foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator(__DIR__ . '/extract', 0x00003000), RecursiveIteratorIterator::CHILD_FIRST) as $p => $b) { 28 $out[] = $p; 29} 30 31sort($out); 32 33foreach ($out as $b) { 34 echo "$b\n"; 35} 36 37$a->extractTo(__DIR__ . '/extract1', 'file1.txt'); 38var_dump(file_get_contents(__DIR__ . '/extract1/file1.txt')); 39 40$a->extractTo(__DIR__ . '/extract1', 'subdir/ectory/file.txt'); 41var_dump(file_get_contents(__DIR__ . '/extract1/subdir/ectory/file.txt')); 42 43$a->extractTo(__DIR__ . '/extract1-2', array('file2.txt', 'one/level')); 44var_dump(file_get_contents(__DIR__ . '/extract1-2/file2.txt')); 45var_dump(is_dir(__DIR__ . '/extract1-2/one/level')); 46 47try { 48 $a->extractTo(__DIR__ . '/whatever', 134); 49} catch (Exception $e) { 50 echo $e->getMessage(), "\n"; 51} 52 53$a->extractTo(array()); 54 55try { 56 $a->extractTo(''); 57} catch (Exception $e) { 58 echo $e->getMessage(), "\n"; 59} 60 61file_put_contents(__DIR__ . '/oops', 'I is file'); 62 63try { 64 $a->extractTo(__DIR__ . '/oops', 'file1.txt'); 65} catch (Exception $e) { 66 echo $e->getMessage(), "\n"; 67} 68 69try { 70 $a->extractTo(__DIR__ . '/oops1', array(array(), 'file1.txt')); 71} catch (Exception $e) { 72 echo $e->getMessage(), "\n"; 73} 74 75try { 76 $a->extractTo(__DIR__ . '/extract', 'file1.txt'); 77} catch (Exception $e) { 78 echo $e->getMessage(), "\n"; 79} 80 81file_put_contents(__DIR__ . '/extract/file1.txt', 'first'); 82var_dump(file_get_contents(__DIR__ . '/extract/file1.txt')); 83 84$a->extractTo(__DIR__ . '/extract', 'file1.txt', true); 85var_dump(file_get_contents(__DIR__ . '/extract/file1.txt')); 86 87try { 88 $a->extractTo(str_repeat('a', 20000), 'file1.txt'); 89} catch (Exception $e) { 90 echo $e->getMessage(), "\n"; 91} 92 93$a[str_repeat('a', 20000)] = 'long'; 94 95try { 96 $a->extractTo(__DIR__ . '/extract', str_repeat('a', 20000)); 97} catch (Exception $e) { 98 echo $e->getMessage(), "\n"; 99} 100 101?> 102===DONE=== 103--CLEAN-- 104<?php 105@rmdir(__DIR__ . '/whatever'); 106@unlink(__DIR__ . '/oops'); 107@rmdir(__DIR__ . '/oops1'); 108@unlink(__DIR__ . '/tempmanifest1.phar.php'); 109$e = __DIR__ . '/extract/'; 110@unlink($e . 'file1.txt'); 111@unlink($e . 'file2.txt'); 112@unlink($e . 'subdir/ectory/file.txt'); 113@rmdir($e . 'subdir/ectory'); 114@rmdir($e . 'subdir'); 115@rmdir($e . 'one/level'); 116@rmdir($e . 'one'); 117@rmdir($e); 118$e = __DIR__ . '/extract1/'; 119@unlink($e . 'file1.txt'); 120@unlink($e . 'subdir/ectory/file.txt'); 121@rmdir($e . 'subdir/ectory'); 122@rmdir($e . 'subdir'); 123@rmdir($e); 124$e = __DIR__ . '/extract1-2/'; 125@unlink($e . 'file2.txt'); 126@rmdir($e . 'one/level'); 127@rmdir($e . 'one'); 128@rmdir($e); 129?> 130--EXPECTF-- 131%sextract%cfile1.txt 132%sextract%cfile2.txt 133%sextract%cone 134%sextract%csubdir 135%sextract%csubdir%cectory 136%sextract%csubdir%cectory%cfile.txt 137string(2) "hi" 138string(3) "hi3" 139string(3) "hi2" 140bool(false) 141Invalid argument, expected a filename (string) or array of filenames 142 143Warning: Phar::extractTo() expects parameter 1 to be a valid path, array given in %sphar_extract.php on line %d 144Invalid argument, extraction path must be non-zero length 145Unable to use path "%soops" for extraction, it is a file, must be a directory 146Invalid argument, array of filenames to extract contains non-string value 147Extraction from phar "%stempmanifest1.phar.php" failed: Cannot extract "file1.txt" to "%sextract/file1.txt", path already exists 148string(5) "first" 149string(2) "hi" 150Cannot extract to "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...", destination directory is too long for filesystem 151Extraction from phar "%stempmanifest1.phar.php" failed: Cannot extract "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa..." to "%s...", extracted filename is too long for filesystem 152===DONE=== 153