xref: /PHP-7.3/ext/phar/tests/fopen.phpt (revision f1d7e3ca)
1--TEST--
2Phar: test fopen() interception
3--SKIPIF--
4<?php if (!extension_loaded("phar")) die("skip");?>
5--INI--
6phar.require_hash=1
7phar.readonly=0
8--FILE--
9<?php
10Phar::interceptFileFuncs();
11$a = fopen(__FILE__, 'rb'); // this satisfies 1 line of code coverage
12fclose($a);
13$a = fopen(); // this satisfies another line of code coverage
14
15$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php';
16$a = new Phar($fname);
17$a['index.php'] = '<?php
18$a = fopen("dir/file1.txt", "r");
19echo fread($a, 2);
20fclose($a);
21$a = fopen("file1.txt", "r", true);
22echo fread($a, 2);
23fclose($a);
24$a = fopen("notfound.txt", "r", true);
25?>';
26$a['dir/file1.txt'] = 'hi';
27$a['dir/file2.txt'] = 'hi2';
28$a['dir/file3.txt'] = 'hi3';
29$a->setStub('<?php
30set_include_path("phar://" . __FILE__ . "/dir" . PATH_SEPARATOR . "phar://" . __FILE__);
31include "index.php";
32__HALT_COMPILER();');
33include $fname;
34?>
35===DONE===
36--CLEAN--
37<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.php'); ?>
38--EXPECTF--
39Warning: fopen() expects at least 2 parameters, 0 given in %sfopen.php on line %d
40hihi
41Warning: fopen(notfound.txt): failed to open stream: No such file or directory in phar://%sfopen.phar.php/index.php on line %d
42===DONE===
43