xref: /PHP-8.1/ext/phar/tests/fopen.phpt (revision 74859783)
1--TEST--
2Phar: test fopen() interception
3--EXTENSIONS--
4phar
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
14$fname = __DIR__ . '/' . basename(__FILE__, '.php') . '.phar.php';
15$a = new Phar($fname);
16$a['index.php'] = '<?php
17$a = fopen("dir/file1.txt", "r");
18echo fread($a, 2);
19fclose($a);
20$a = fopen("file1.txt", "r", true);
21echo fread($a, 2);
22fclose($a);
23$a = fopen("notfound.txt", "r", true);
24?>';
25$a['dir/file1.txt'] = 'hi';
26$a['dir/file2.txt'] = 'hi2';
27$a['dir/file3.txt'] = 'hi3';
28$a->setStub('<?php
29set_include_path("phar://" . __FILE__ . "/dir" . PATH_SEPARATOR . "phar://" . __FILE__);
30include "index.php";
31__HALT_COMPILER();');
32include $fname;
33?>
34--CLEAN--
35<?php unlink(__DIR__ . '/' . basename(__FILE__, '.clean.php') . '.phar.php'); ?>
36--EXPECTF--
37hihi
38Warning: fopen(notfound.txt): Failed to open stream: No such file or directory in phar://%sfopen.phar.php/index.php on line %d
39