1--TEST-- 2Phar: fopen/stat/fseek/unlink/rename edge cases 3--EXTENSIONS-- 4phar 5--INI-- 6phar.readonly=0 7phar.require_hash=0 8--FILE-- 9<?php 10$fname = __DIR__ . '/' . basename(__FILE__, '.php') . '.phar.php'; 11$fname2 = __DIR__ . '/' . basename(__FILE__, '.php') . '.2.phar.php'; 12$fname3 = __DIR__ . '/' . basename(__FILE__, '.php') . '.3.phar.php'; 13$pname = 'phar://' . $fname; 14$pname2 = 'phar://' . $fname2; 15$pname3 = 'phar://' . $fname3; 16 17// create in cwd 18chdir(__DIR__); 19file_put_contents('phar://fopen_edgetest.phar/hi', 'hi'); 20// append 21$a = fopen($pname . '/b/c.php', 'a'); 22// invalid pharname 23$a = fopen($pname . '.phar.gz', 'r'); 24// test phar_open_url() with quiet stat for code coverage 25var_dump(file_exists($pname . '.phar.gz/hi')); 26// test open for write with new phar 27$a = fopen($pname . '/hi', 'w'); 28fclose($a); 29// test open for write with corrupted phar 30file_put_contents($fname2, '<?php oh crap __HALT_COMPILER();'); 31$a = fopen($pname2 . '/hi', 'w'); 32$a = fopen('phar://', 'r'); 33$a = fopen('phar://foo.phar', 'r'); 34 35file_put_contents($pname . '/hi', 'hi'); 36$a = fopen($pname . '/hi', 'r'); 37var_dump(fseek($a, 1), ftell($a)); 38var_dump(fseek($a, 1, SEEK_CUR), ftell($a)); 39fclose($a); 40 41var_dump(stat('phar://')); 42var_dump(stat('phar://foo.phar')); 43var_dump(is_dir($pname)); 44 45// this tests coverage of the case where the phar exists and has no files 46$phar = new Phar($fname3); 47var_dump(file_exists($pname3 . '/test')); 48 49unlink($pname2 . '/hi'); 50unlink('phar://'); 51unlink('phar://foo.phar'); 52unlink($pname . '/oops'); 53 54rename('phar://', 'phar://'); 55rename($pname . '/hi', 'phar://'); 56rename('phar://foo.phar/hi', 'phar://'); 57rename($pname . '/hi', 'phar://foo.phar/hi'); 58 59ini_set('phar.readonly', 1); 60rename($pname . '/hi', $pname . '/there'); 61ini_set('phar.readonly', 0); 62Phar::unlinkArchive($fname); 63file_put_contents($pname . '/test.php', '<?php 64$a = fopen("./notfound.php", "r"); 65?>'); 66include $pname . '/test.php'; 67?> 68 69--CLEAN-- 70<?php unlink(__DIR__ . '/' . basename(__FILE__, '.clean.php') . '.phar.php'); ?> 71<?php unlink(__DIR__ . '/' . basename(__FILE__, '.clean.php') . '.2.phar.php'); ?> 72<?php unlink(__DIR__ . '/fopen_edgetest.phar'); ?> 73--EXPECTF-- 74Warning: fopen(phar://%sfopen_edgecases.phar.php/b/c.php): Failed to open stream: phar error: open mode append not supported in %sfopen_edgecases.php on line %d 75 76Warning: fopen(phar://%sfopen_edgecases.phar.php.phar.gz): Failed to open stream: phar error: invalid url or non-existent phar "phar://%sfopen_edgecases.phar.php.phar.gz" in %sfopen_edgecases.php on line %d 77bool(false) 78 79Warning: fopen(phar://%sfopen_edgecases.2.phar.php/hi): Failed to open stream: internal corruption of phar "%sfopen_edgecases.2.phar.php" (truncated manifest at stub end) in %sfopen_edgecases.php on line %d 80 81Warning: fopen(phar://): Failed to open stream: phar error: no directory in "phar://", must have at least phar:/// for root directory (always use full path to a new phar) in %sfopen_edgecases.php on line %d 82 83Warning: fopen(phar://foo.phar): Failed to open stream: %s in %sfopen_edgecases.php on line %d 84int(0) 85int(1) 86int(0) 87int(2) 88 89Warning: stat(): stat failed for phar:// in %sfopen_edgecases.php on line %d 90bool(false) 91 92Warning: stat(): stat failed for phar://foo.phar in %sfopen_edgecases.php on line %d 93bool(false) 94bool(true) 95bool(false) 96 97Warning: unlink(): internal corruption of phar "%sfopen_edgecases.2.phar.php" (truncated manifest at stub end) in %sfopen_edgecases.php on line %d 98 99Warning: unlink(): phar error: unlink failed in %sfopen_edgecases.php on line %d 100 101Warning: unlink(): phar error: no directory in "phar://", must have at least phar:/// for root directory (always use full path to a new phar) in %sfopen_edgecases.php on line %d 102 103Warning: unlink(): phar error: unlink failed in %sfopen_edgecases.php on line %d 104 105Warning: unlink(): phar error: invalid url or non-existent phar "phar://foo.phar" in %sfopen_edgecases.php on line %d 106 107Warning: unlink(): phar error: unlink failed in %sfopen_edgecases.php on line %d 108 109Warning: unlink(): unlink of "phar://%sfopen_edgecases.phar.php/oops" failed, file does not exist in %sfopen_edgecases.php on line %d 110 111Warning: rename(): phar error: cannot rename "phar://" to "phar://": invalid or non-writable url "phar://" in %sfopen_edgecases.php on line %d 112 113Warning: rename(): phar error: cannot rename "phar://%sfopen_edgecases.phar.php/hi" to "phar://": invalid or non-writable url "phar://" in %sfopen_edgecases.php on line %d 114 115Warning: rename(): phar error: cannot rename "phar://foo.phar/hi" to "phar://": invalid or non-writable url "phar://" in %sfopen_edgecases.php on line %d 116 117Warning: rename(): phar error: cannot rename "phar://%sfopen_edgecases.phar.php/hi" to "phar://foo.phar/hi", not within the same phar archive in %sfopen_edgecases.php on line %d 118 119Warning: rename(): phar error: cannot rename "phar://%sfopen_edgecases.phar.php/hi" to "phar://%sfopen_edgecases.phar.php/there": invalid or non-writable url "phar://%sfopen_edgecases.phar.php/hi" in %sfopen_edgecases.php on line %d 120 121Warning: fopen(./notfound.php): Failed to open stream: No such file or directory in phar://%sfopen_edgecases.phar.php/test.php on line %d 122 123