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