readfile_variation10.phpt 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. --TEST--
  2. Test readfile() function : variation - various invalid paths
  3. --CREDITS--
  4. Dave Kelsey <d_kelsey@uk.ibm.com>
  5. --SKIPIF--
  6. <?php
  7. if(substr(PHP_OS, 0, 3) == "WIN")
  8. die("skip Not for Windows");
  9. ?>
  10. --CONFLICTS--
  11. obscure_filename
  12. --FILE--
  13. <?php
  14. echo "*** Testing readfile() : variation ***\n";
  15. /* An array of files */
  16. $names_arr = array(
  17. /* Invalid args */
  18. -1,
  19. TRUE,
  20. FALSE,
  21. "",
  22. " ",
  23. "\0",
  24. /* prefix with path separator of a non existing directory*/
  25. "/no/such/file/dir",
  26. "php/php"
  27. );
  28. for( $i=0; $i<count($names_arr); $i++ ) {
  29. $name = $names_arr[$i];
  30. echo "-- testing '$name' --\n";
  31. try {
  32. readfile($name);
  33. } catch (\TypeError|\ValueError $e) {
  34. echo get_class($e) . ': ' . $e->getMessage(), "\n";
  35. }
  36. }
  37. ?>
  38. --EXPECTF--
  39. *** Testing readfile() : variation ***
  40. -- testing '-1' --
  41. Warning: readfile(-1): Failed to open stream: %s in %s on line %d
  42. -- testing '1' --
  43. Warning: readfile(1): Failed to open stream: %s in %s on line %d
  44. -- testing '' --
  45. ValueError: Path cannot be empty
  46. -- testing '' --
  47. ValueError: Path cannot be empty
  48. -- testing ' ' --
  49. Warning: readfile( ): Failed to open stream: %s in %s on line %d
  50. -- testing '%0' --
  51. ValueError: readfile(): Argument #1 ($filename) must not contain any null bytes
  52. -- testing '%sdir' --
  53. Warning: readfile(%sdir): Failed to open stream: %s in %s on line %d
  54. -- testing '%sphp' --
  55. Warning: readfile(%sphp): Failed to open stream: %s in %s on line %d