fopen5.2.phpt 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. --TEST--
  2. Phar: 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.2 required for this test");?>
  6. --INI--
  7. phar.require_hash=1
  8. phar.readonly=0
  9. --FILE--
  10. <?php
  11. Phar::interceptFileFuncs();
  12. $a = fopen(__FILE__, 'rb'); // this satisfies 1 line of code coverage
  13. fclose($a);
  14. $a = fopen(); // this satisfies another line of code coverage
  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");
  19. echo fread($a, 2);
  20. fclose($a);
  21. $a = fopen("file1.txt", "r", true);
  22. echo fread($a, 2);
  23. fclose($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
  30. set_include_path("phar://" . __FILE__ . "/dir" . PATH_SEPARATOR . "phar://" . __FILE__);
  31. include "index.php";
  32. __HALT_COMPILER();');
  33. include $fname;
  34. ?>
  35. ===DONE===
  36. --CLEAN--
  37. <?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.php'); ?>
  38. --EXPECTF--
  39. Warning: fopen() expects at least 2 parameters, 0 given in %sfopen5.2.php on line %d
  40. hihi
  41. Warning: fopen(phar://%sfopen5.2.phar.php/notfound.txt): failed to open stream: phar error: "notfound.txt" is not a file in phar "%sfopen5.2.phar.php" in phar://%sfopen5.2.phar.php/index.php on line %d
  42. ===DONE===