xref: /PHP-5.6/ext/phar/tests/fgc_edgecases.phpt (revision 2c2c113b)
1--TEST--
2Phar: test edge cases of file_get_contents() function interception
3--SKIPIF--
4<?php
5if (!extension_loaded("phar")) die("skip");
6if (version_compare(PHP_VERSION, "6.0", ">")) die("skip pre-unicode version of PHP required");
7?>
8--INI--
9phar.readonly=0
10--FILE--
11<?php
12
13Phar::interceptFileFuncs();
14
15$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php';
16$pname = 'phar://' . $fname;
17
18file_get_contents(array());
19chdir(dirname(__FILE__));
20file_put_contents($fname, "blah\n");
21file_put_contents("foob", "test\n");
22echo file_get_contents($fname);
23unlink($fname);
24mkdir($pname . '/oops');
25
26file_put_contents($pname . '/foo/hi', '<?php
27echo file_get_contents("foo/" . basename(__FILE__));
28$context = stream_context_create();
29file_get_contents("./hi", 0, $context, 0, -1);
30echo file_get_contents("foob");
31set_include_path("' . addslashes(dirname(__FILE__)) . '");
32echo file_get_contents("foob", true);
33echo file_get_contents("./hi", 0, $context);
34echo file_get_contents("../oops");
35echo file_get_contents("./hi", 0, $context, 50000);
36echo file_get_contents("./hi");
37echo file_get_contents("./hi", 0, $context, 0, 0);
38?>
39');
40
41include $pname . '/foo/hi';
42
43?>
44===DONE===
45--CLEAN--
46<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.php'); ?>
47<?php rmdir(dirname(__FILE__) . '/poo'); ?>
48<?php unlink(dirname(__FILE__) . '/foob'); ?>
49--EXPECTF--
50Warning: file_get_contents() expects parameter 1 to be a valid path, array given in %sfgc_edgecases.php on line %d
51blah
52<?php
53echo file_get_contents("foo/" . basename(__FILE__));
54$context = stream_context_create();
55file_get_contents("./hi", 0, $context, 0, -1);
56echo file_get_contents("foob");
57set_include_path("%stests");
58echo file_get_contents("foob", true);
59echo file_get_contents("./hi", 0, $context);
60echo file_get_contents("../oops");
61echo file_get_contents("./hi", 0, $context, 50000);
62echo file_get_contents("./hi");
63echo file_get_contents("./hi", 0, $context, 0, 0);
64?>
65
66Warning: file_get_contents(): length must be greater than or equal to zero in phar://%sfgc_edgecases.phar.php/foo/hi on line %d
67test
68test
69<?php
70echo file_get_contents("foo/" . basename(__FILE__));
71$context = stream_context_create();
72file_get_contents("./hi", 0, $context, 0, -1);
73echo file_get_contents("foob");
74set_include_path("%stests");
75echo file_get_contents("foob", true);
76echo file_get_contents("./hi", 0, $context);
77echo file_get_contents("../oops");
78echo file_get_contents("./hi", 0, $context, 50000);
79echo file_get_contents("./hi");
80echo file_get_contents("./hi", 0, $context, 0, 0);
81?>
82
83Warning: 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
84
85Warning: file_get_contents(): Failed to seek to position 50000 in the stream in phar://%sfgc_edgecases.phar.php/foo/hi on line %d
86<?php
87echo file_get_contents("foo/" . basename(__FILE__));
88$context = stream_context_create();
89file_get_contents("./hi", 0, $context, 0, -1);
90echo file_get_contents("foob");
91set_include_path("%stests");
92echo file_get_contents("foob", true);
93echo file_get_contents("./hi", 0, $context);
94echo file_get_contents("../oops");
95echo file_get_contents("./hi", 0, $context, 50000);
96echo file_get_contents("./hi");
97echo file_get_contents("./hi", 0, $context, 0, 0);
98?>
99===DONE===
100