ftruncate.phpt 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. --TEST--
  2. ftruncate() tests
  3. --FILE--
  4. <?php
  5. $filename = __DIR__."/ftruncate.dat";
  6. file_put_contents($filename, "some test data inside");
  7. $fp = fopen($filename, "r");
  8. var_dump(ftruncate($fp, 10));
  9. fclose($fp);
  10. var_dump(file_get_contents($filename));
  11. $fp = fopen($filename, "w");
  12. var_dump(ftruncate($fp, 10));
  13. fclose($fp);
  14. var_dump(file_get_contents($filename));
  15. file_put_contents($filename, "some test data inside");
  16. $fp = fopen($filename, "a");
  17. var_dump(ftruncate($fp, 10));
  18. fclose($fp);
  19. var_dump(file_get_contents($filename));
  20. $fp = fopen($filename, "a");
  21. var_dump(ftruncate($fp, 0));
  22. fclose($fp);
  23. var_dump(file_get_contents($filename));
  24. file_put_contents($filename, "some test data inside");
  25. $fp = fopen($filename, "a");
  26. try {
  27. var_dump(ftruncate($fp, -1000000000));
  28. } catch (\ValueError $e) {
  29. echo $e->getMessage() . \PHP_EOL;
  30. }
  31. fclose($fp);
  32. var_dump(file_get_contents($filename));
  33. @unlink($filename);
  34. ?>
  35. --EXPECTF--
  36. bool(false)
  37. string(21) "some test data inside"
  38. bool(true)
  39. string(10) "%0%0%0%0%0%0%0%0%0%0"
  40. bool(true)
  41. string(10) "some test "
  42. bool(true)
  43. string(0) ""
  44. ftruncate(): Argument #2 ($size) must be greater than or equal to 0
  45. string(21) "some test data inside"