summaryrefslogtreecommitdiff
path: root/ext/phar/tests
diff options
context:
space:
mode:
authorGreg Beaver <cellog@php.net>2008-05-11 19:17:51 +0000
committerGreg Beaver <cellog@php.net>2008-05-11 19:17:51 +0000
commit38d5943ee6e31f921fe40d7f0049cb14e8222b27 (patch)
tree6c5ec5fa4edd3435fd0d6a27a8af01304d2467b5 /ext/phar/tests
parent5ddb49caec245fd9e055d348350198e0e57592a0 (diff)
downloadphp-git-38d5943ee6e31f921fe40d7f0049cb14e8222b27.tar.gz
increase code coverage of funcinterceptors to 90%+, fix many bugs, fix errant wrong test condition in fgc_edgecases
Diffstat (limited to 'ext/phar/tests')
-rw-r--r--ext/phar/tests/fgc_edgecases.phpt94
-rw-r--r--ext/phar/tests/fopen_edgecases.phpt7
-rw-r--r--ext/phar/tests/fopen_edgecases2.phpt43
-rw-r--r--ext/phar/tests/opendir_edgecases.phpt46
-rw-r--r--ext/phar/tests/phar_buildfromdirectory4.phpt4
-rw-r--r--ext/phar/tests/phar_buildfromdirectory5.phpt4
-rw-r--r--ext/phar/tests/readfile_edgecases.phpt62
-rw-r--r--ext/phar/tests/stat.phpt2
-rw-r--r--ext/phar/tests/stat2.phpt59
9 files changed, 319 insertions, 2 deletions
diff --git a/ext/phar/tests/fgc_edgecases.phpt b/ext/phar/tests/fgc_edgecases.phpt
new file mode 100644
index 0000000000..c440ea4afa
--- /dev/null
+++ b/ext/phar/tests/fgc_edgecases.phpt
@@ -0,0 +1,94 @@
+--TEST--
+Phar: test edge cases of file_get_contents() function interception
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip");?>
+--INI--
+phar.readonly=0
+--FILE--
+<?php
+Phar::interceptFileFuncs();
+$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php';
+$pname = 'phar://' . $fname;
+
+file_get_contents(array());
+chdir(dirname(__FILE__));
+file_put_contents($fname, "blah\n");
+file_put_contents("foob", "test\n");
+echo file_get_contents($fname);
+unlink($fname);
+mkdir($pname . '/oops');
+file_put_contents($pname . '/foo/hi', '<?php
+echo file_get_contents("foo/" . basename(__FILE__));
+$context = stream_context_create();
+file_get_contents("./hi", 0, $context, 0, -1);
+echo file_get_contents("foob");
+set_include_path("' . addslashes(dirname(__FILE__)) . '");
+echo file_get_contents("foob", true);
+echo file_get_contents("./hi", 0, $context);
+echo file_get_contents("../oops");
+echo file_get_contents("./hi", 0, $context, 50000);
+ini_set("magic_quotes_runtime", 1);
+echo file_get_contents("./hi");
+echo file_get_contents("./hi", 0, $context, 0, 0);
+?>
+');
+include $pname . '/foo/hi';
+?>
+===DONE===
+--CLEAN--
+<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.php'); ?>
+<?php rmdir(dirname(__FILE__) . '/poo'); ?>
+<?php unlink(dirname(__FILE__) . '/foob'); ?>
+--EXPECTF--
+blah
+<?php
+echo file_get_contents("foo/" . basename(__FILE__));
+$context = stream_context_create();
+file_get_contents("./hi", 0, $context, 0, -1);
+echo file_get_contents("foob");
+set_include_path("/home/cellog/workspace/php5/ext/phar/tests");
+echo file_get_contents("foob", true);
+echo file_get_contents("./hi", 0, $context);
+echo file_get_contents("../oops");
+echo file_get_contents("./hi", 0, $context, 50000);
+ini_set("magic_quotes_runtime", 1);
+echo file_get_contents("./hi");
+echo file_get_contents("./hi", 0, $context, 0, 0);
+?>
+
+Warning: file_get_contents(): length must be greater than or equal to zero in phar://%sfgc_edgecases.phar.php/foo/hi on line %d
+test
+test
+<?php
+echo file_get_contents("foo/" . basename(__FILE__));
+$context = stream_context_create();
+file_get_contents("./hi", 0, $context, 0, -1);
+echo file_get_contents("foob");
+set_include_path("/home/cellog/workspace/php5/ext/phar/tests");
+echo file_get_contents("foob", true);
+echo file_get_contents("./hi", 0, $context);
+echo file_get_contents("../oops");
+echo file_get_contents("./hi", 0, $context, 50000);
+ini_set("magic_quotes_runtime", 1);
+echo file_get_contents("./hi");
+echo file_get_contents("./hi", 0, $context, 0, 0);
+?>
+
+Warning: file_get_contents(phar://%sfgc_edgecases.phar.php/oops): failed to open stream: phar error: path "oops" is a directory in phar://%sfgc_edgecases.phar.php/foo/hi on line %d
+
+Warning: file_get_contents(): Failed to seek to position 50000 in the stream in phar://%sfgc_edgecases.phar.php/foo/hi on line %d
+<?php
+echo file_get_contents(\"foo/\" . basename(__FILE__));
+$context = stream_context_create();
+file_get_contents(\"./hi\", 0, $context, 0, -1);
+echo file_get_contents(\"foob\");
+set_include_path(\"/home/cellog/workspace/php5/ext/phar/tests\");
+echo file_get_contents(\"foob\", true);
+echo file_get_contents(\"./hi\", 0, $context);
+echo file_get_contents(\"../oops\");
+echo file_get_contents(\"./hi\", 0, $context, 50000);
+ini_set(\"magic_quotes_runtime\", 1);
+echo file_get_contents(\"./hi\");
+echo file_get_contents(\"./hi\", 0, $context, 0, 0);
+?>
+===DONE=== \ No newline at end of file
diff --git a/ext/phar/tests/fopen_edgecases.phpt b/ext/phar/tests/fopen_edgecases.phpt
index 209fc482a0..4c28ff31a1 100644
--- a/ext/phar/tests/fopen_edgecases.phpt
+++ b/ext/phar/tests/fopen_edgecases.phpt
@@ -59,6 +59,11 @@ rename($pname . '/hi', 'phar://foo.phar/hi');
ini_set('phar.readonly', 1);
rename($pname . '/hi', $pname . '/there');
ini_set('phar.readonly', 0);
+Phar::unlinkArchive($fname);
+file_put_contents($pname . '/test.php', '<?php
+$a = fopen("./notfound.php", "r");
+?>');
+include $pname . '/test.php';
?>
===DONE===
@@ -114,4 +119,6 @@ Warning: rename(): phar error: cannot rename "phar://%sfopen_edgecases.phar.php/
Warning: 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
+Warning: fopen(./notfound.php): failed to open stream: No such file or directory in phar://%sfopen_edgecases.phar.php/test.php on line %d
+
===DONE=== \ No newline at end of file
diff --git a/ext/phar/tests/fopen_edgecases2.phpt b/ext/phar/tests/fopen_edgecases2.phpt
new file mode 100644
index 0000000000..3579a2c221
--- /dev/null
+++ b/ext/phar/tests/fopen_edgecases2.phpt
@@ -0,0 +1,43 @@
+--TEST--
+Phar: test edge cases of fopen() function interception #2
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip");?>
+--INI--
+phar.readonly=0
+--FILE--
+<?php
+Phar::interceptFileFuncs();
+$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php';
+$pname = 'phar://' . $fname;
+
+fopen(array(), 'r');
+chdir(dirname(__FILE__));
+file_put_contents($fname, "blah\n");
+file_put_contents("foob", "test\n");
+$a = fopen($fname, 'rb');
+echo fread($a, 1000);
+fclose($a);
+unlink($fname);
+mkdir($pname . '/oops');
+file_put_contents($pname . '/foo/hi', '<?php
+$context = stream_context_create();
+$a = fopen("foob", "rb", false, $context);
+echo fread($a, 1000);
+fclose($a);
+fopen("../oops", "r");
+?>
+');
+include $pname . '/foo/hi';
+?>
+===DONE===
+--CLEAN--
+<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.php'); ?>
+<?php rmdir(dirname(__FILE__) . '/poo'); ?>
+<?php unlink(dirname(__FILE__) . '/foob'); ?>
+--EXPECTF--
+Warning: fopen() expects parameter 1 to be string, array given in %sfopen_edgecases2.php on line %d
+blah
+test
+
+Warning: fopen(phar://%sfopen_edgecases2.phar.php/oops): failed to open stream: phar error: path "oops" is a directory in phar://%sfopen_edgecases2.phar.php/foo/hi on line %d
+===DONE=== \ No newline at end of file
diff --git a/ext/phar/tests/opendir_edgecases.phpt b/ext/phar/tests/opendir_edgecases.phpt
new file mode 100644
index 0000000000..9fb515f116
--- /dev/null
+++ b/ext/phar/tests/opendir_edgecases.phpt
@@ -0,0 +1,46 @@
+--TEST--
+Phar: test edge cases of opendir() function interception
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip");?>
+--INI--
+phar.readonly=0
+--FILE--
+<?php
+Phar::interceptFileFuncs();
+$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php';
+$pname = 'phar://' . $fname;
+opendir(array());
+mkdir(dirname(__FILE__) . '/poo');
+chdir(dirname(__FILE__));
+$a = opendir('poo');
+while (false !== ($b = readdir($a))) {
+echo "$b\n";
+}
+closedir($a);
+file_put_contents($pname . '/foo', '<?php
+$context = stream_context_create();
+$a = opendir(".", $context);
+$res = array();
+while (false !== ($b = readdir($a))) {
+$res[] = $b;
+}
+sort($res);
+foreach ($res as $b) {
+echo "$b\n";
+}
+opendir("oops");
+?>');
+include $pname . '/foo';
+?>
+===DONE===
+--CLEAN--
+<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.php'); ?>
+<?php rmdir(dirname(__FILE__) . '/poo');
+--EXPECTF--
+Warning: opendir() expects parameter 1 to be string, array given in %sopendir_edgecases.php on line %d
+.
+..
+foo
+
+Warning: opendir(phar://%sopendir_edgecases.phar.php/oops): failed to open dir: No such file or directory in phar://%sopendir_edgecases.phar.php/foo on line %d
+===DONE=== \ No newline at end of file
diff --git a/ext/phar/tests/phar_buildfromdirectory4.phpt b/ext/phar/tests/phar_buildfromdirectory4.phpt
index 886cad82d6..cf11d62af6 100644
--- a/ext/phar/tests/phar_buildfromdirectory4.phpt
+++ b/ext/phar/tests/phar_buildfromdirectory4.phpt
@@ -15,7 +15,9 @@ foreach(range(1, 4) as $i) {
try {
$phar = new Phar(dirname(__FILE__) . '/buildfromdirectory.phar');
- var_dump($phar->buildFromDirectory(dirname(__FILE__) . '/testdir'));
+ $a = $phar->buildFromDirectory(dirname(__FILE__) . '/testdir');
+ asort($a);
+ var_dump($a);
} catch (Exception $e) {
var_dump(get_class($e));
echo $e->getMessage() . "\n";
diff --git a/ext/phar/tests/phar_buildfromdirectory5.phpt b/ext/phar/tests/phar_buildfromdirectory5.phpt
index fbf3e9b533..51e5cec691 100644
--- a/ext/phar/tests/phar_buildfromdirectory5.phpt
+++ b/ext/phar/tests/phar_buildfromdirectory5.phpt
@@ -15,7 +15,9 @@ foreach(range(1, 4) as $i) {
try {
$phar = new Phar(dirname(__FILE__) . '/buildfromdirectory.phar');
- var_dump($phar->buildFromDirectory(dirname(__FILE__) . '/testdir', '/\.txt/'));
+ $a = $phar->buildFromDirectory(dirname(__FILE__) . '/testdir', '/\.txt/');
+ asort($a);
+ var_dump($a);
} catch (Exception $e) {
var_dump(get_class($e));
echo $e->getMessage() . "\n";
diff --git a/ext/phar/tests/readfile_edgecases.phpt b/ext/phar/tests/readfile_edgecases.phpt
new file mode 100644
index 0000000000..de1f5912df
--- /dev/null
+++ b/ext/phar/tests/readfile_edgecases.phpt
@@ -0,0 +1,62 @@
+--TEST--
+Phar: test edge cases of readfile() function interception
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip");?>
+--INI--
+phar.readonly=0
+--FILE--
+<?php
+Phar::interceptFileFuncs();
+$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php';
+$pname = 'phar://' . $fname;
+
+readfile(array());
+chdir(dirname(__FILE__));
+file_put_contents($fname, "blah\n");
+file_put_contents("foob", "test\n");
+readfile($fname);
+unlink($fname);
+mkdir($pname . '/oops');
+file_put_contents($pname . '/foo/hi', '<?php
+readfile("foo/" . basename(__FILE__));
+$context = stream_context_create();
+readfile("foob");
+set_include_path("' . addslashes(dirname(__FILE__)) . '");
+readfile("foob", true);
+readfile("./hi", 0, $context);
+readfile("../oops");
+?>
+');
+include $pname . '/foo/hi';
+?>
+===DONE===
+--CLEAN--
+<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.php'); ?>
+<?php rmdir(dirname(__FILE__) . '/poo'); ?>
+<?php unlink(dirname(__FILE__) . '/foob'); ?>
+--EXPECTF--
+Warning: readfile() expects parameter 1 to be string, array given in %sreadfile_edgecases.php on line %d
+blah
+<?php
+readfile("foo/" . basename(__FILE__));
+$context = stream_context_create();
+readfile("foob");
+set_include_path("/home/cellog/workspace/php5/ext/phar/tests");
+readfile("foob", true);
+readfile("./hi", 0, $context);
+readfile("../oops");
+?>
+test
+test
+<?php
+readfile("foo/" . basename(__FILE__));
+$context = stream_context_create();
+readfile("foob");
+set_include_path("/home/cellog/workspace/php5/ext/phar/tests");
+readfile("foob", true);
+readfile("./hi", 0, $context);
+readfile("../oops");
+?>
+
+Warning: readfile(phar://%sreadfile_edgecases.phar.php/oops): failed to open stream: phar error: path "oops" is a directory in phar://%sreadfile_edgecases.phar.php/foo/hi on line %d
+===DONE=== \ No newline at end of file
diff --git a/ext/phar/tests/stat.phpt b/ext/phar/tests/stat.phpt
index e450cc3b01..020fc24f86 100644
--- a/ext/phar/tests/stat.phpt
+++ b/ext/phar/tests/stat.phpt
@@ -11,6 +11,8 @@ Phar::interceptFileFuncs();
var_dump(stat(""));
$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php';
+$fname2 = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.tar';
+$fname3 = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.tar';
$a = new Phar($fname);
$a['index.php'] = '<?php
echo "stat\n";
diff --git a/ext/phar/tests/stat2.phpt b/ext/phar/tests/stat2.phpt
new file mode 100644
index 0000000000..559a28d3f0
--- /dev/null
+++ b/ext/phar/tests/stat2.phpt
@@ -0,0 +1,59 @@
+--TEST--
+Phar: test stat function interceptions and is_file/is_link edge cases
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip");?>
+--INI--
+phar.readonly=0
+--FILE--
+<?php
+Phar::interceptFileFuncs();
+is_file();
+is_link();
+var_dump(is_file(__FILE__));
+
+$fname2 = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.tar';
+$fname3 = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.tar';
+copy(dirname(__FILE__) . '/tar/files/links.tar', $fname2);
+$a = new PharData($fname2);
+$b = $a->convertToExecutable();
+unset($a);
+Phar::unlinkArchive($fname2);
+$b['foo/stat.php'] = '<?php
+echo "is_link\n";
+var_dump(is_link("./stat.php"),is_file("./stat.php"), is_link("./oops"), is_file("./oops"));
+var_dump(is_link("testit/link"), filetype("testit/link"), filetype("testit"), is_file("testit/link"));
+echo "not found\n";
+var_dump(is_link("notfound"));
+echo "dir\n";
+var_dump(is_dir("./bar"), is_file("foo/bar/blah"));
+?>';
+$b->addEmptyDir('foo/bar/blah');
+$b->setStub('<?php
+include "phar://" . __FILE__ . "/foo/stat.php";
+__HALT_COMPILER();');
+include $fname3;
+?>
+===DONE===
+--CLEAN--
+<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.tar'); ?>
+<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.tar'); ?>
+--EXPECTF--
+Warning: Wrong parameter count for is_file() in %sstat2.php on line %d
+
+Warning: Wrong parameter count for is_link() in %sstat2.php on line %d
+bool(true)
+is_link
+bool(false)
+bool(true)
+bool(false)
+bool(false)
+bool(true)
+string(4) "link"
+string(3) "dir"
+bool(true)
+not found
+bool(false)
+dir
+bool(true)
+bool(false)
+===DONE=== \ No newline at end of file