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