1--TEST-- 2Phar: Phar::extractTo() 3--EXTENSIONS-- 4phar 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', new stdClass()); 49} catch (TypeError $e) { 50 echo $e->getMessage(), "\n"; 51} 52 53try { 54 $a->extractTo(array()); 55} catch (TypeError $e) { 56 echo $e->getMessage(), "\n"; 57} 58 59try { 60 $a->extractTo(''); 61} catch (Exception $e) { 62 echo $e->getMessage(), "\n"; 63} 64 65file_put_contents(__DIR__ . '/oops', 'I is file'); 66 67try { 68 $a->extractTo(__DIR__ . '/oops', 'file1.txt'); 69} catch (Exception $e) { 70 echo $e->getMessage(), "\n"; 71} 72 73try { 74 $a->extractTo(__DIR__ . '/oops1', array(array(), 'file1.txt')); 75} catch (Exception $e) { 76 echo $e->getMessage(), "\n"; 77} 78 79try { 80 $a->extractTo(__DIR__ . '/extract', 'file1.txt'); 81} catch (Exception $e) { 82 echo $e->getMessage(), "\n"; 83} 84 85file_put_contents(__DIR__ . '/extract/file1.txt', 'first'); 86var_dump(file_get_contents(__DIR__ . '/extract/file1.txt')); 87 88$a->extractTo(__DIR__ . '/extract', 'file1.txt', true); 89var_dump(file_get_contents(__DIR__ . '/extract/file1.txt')); 90 91try { 92 $a->extractTo(str_repeat('a', 20000), 'file1.txt'); 93} catch (Exception $e) { 94 echo $e->getMessage(), "\n"; 95} 96 97$a[str_repeat('a', 20000)] = 'long'; 98 99try { 100 $a->extractTo(__DIR__ . '/extract', str_repeat('a', 20000)); 101} catch (Exception $e) { 102 echo $e->getMessage(), "\n"; 103} 104 105?> 106--CLEAN-- 107<?php 108@rmdir(__DIR__ . '/whatever'); 109@unlink(__DIR__ . '/oops'); 110@rmdir(__DIR__ . '/oops1'); 111@unlink(__DIR__ . '/tempmanifest1.phar.php'); 112$e = __DIR__ . '/extract/'; 113@unlink($e . 'file1.txt'); 114@unlink($e . 'file2.txt'); 115@unlink($e . 'subdir/ectory/file.txt'); 116@rmdir($e . 'subdir/ectory'); 117@rmdir($e . 'subdir'); 118@rmdir($e . 'one/level'); 119@rmdir($e . 'one'); 120@rmdir($e); 121$e = __DIR__ . '/extract1/'; 122@unlink($e . 'file1.txt'); 123@unlink($e . 'subdir/ectory/file.txt'); 124@rmdir($e . 'subdir/ectory'); 125@rmdir($e . 'subdir'); 126@rmdir($e); 127$e = __DIR__ . '/extract1-2/'; 128@unlink($e . 'file2.txt'); 129@rmdir($e . 'one/level'); 130@rmdir($e . 'one'); 131@rmdir($e); 132?> 133--EXPECTF-- 134%sextract%cfile1.txt 135%sextract%cfile2.txt 136%sextract%cone 137%sextract%csubdir 138%sextract%csubdir%cectory 139%sextract%csubdir%cectory%cfile.txt 140string(2) "hi" 141string(3) "hi3" 142string(3) "hi2" 143bool(false) 144Phar::extractTo(): Argument #2 ($files) must be of type array|string|null, stdClass given 145Phar::extractTo(): Argument #1 ($directory) must be of type string, array given 146Invalid argument, extraction path must be non-zero length 147Unable to use path "%soops" for extraction, it is a file, must be a directory 148Invalid argument, array of filenames to extract contains non-string value 149Extraction from phar "%stempmanifest1.phar.php" failed: Cannot extract "file1.txt" to "%sextract/file1.txt", path already exists 150string(5) "first" 151string(2) "hi" 152Cannot extract to "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...", destination directory is too long for filesystem 153Extraction from phar "%stempmanifest1.phar.php" failed: Cannot extract "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa..." to "%s...", extracted filename is too long for filesystem 154