004.phpt 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. --TEST--
  2. file_put_contents() test
  3. --FILE--
  4. <?php
  5. chdir(__DIR__);
  6. for ($i = 1; $i < 6; $i++) {
  7. @unlink("./TEST{$i}");
  8. }
  9. echo "String Test: ";
  10. echo file_put_contents("TEST1", file_get_contents(__FILE__)) !== FALSE ? 'OK' : 'FAIL';
  11. echo "\n";
  12. $old_int = $int = rand();
  13. $ret = file_put_contents("TEST2", $int);
  14. echo "Integer Test: ";
  15. if ($int === $old_int && $ret !== FALSE && md5($int) == md5_file("TEST2")) {
  16. echo 'OK';
  17. } else {
  18. echo 'FAIL';
  19. }
  20. echo "\n";
  21. $old_int = $int = time() / 1000;
  22. $ret = file_put_contents("TEST3", $int);
  23. echo "Float Test: ";
  24. if ($int === $old_int && $ret !== FALSE && md5($int) == md5_file("TEST3")) {
  25. echo 'OK';
  26. } else {
  27. echo 'FAIL';
  28. }
  29. echo "\n";
  30. $ret = file_put_contents("TEST4", __FILE__);
  31. echo "Bool Test: ";
  32. if ($ret !== FALSE && md5(__FILE__) == md5_file("TEST4")) {
  33. echo 'OK';
  34. } else {
  35. echo 'FAIL';
  36. }
  37. echo "\n";
  38. $ret = @file_put_contents("TEST5", $_SERVER);
  39. echo "Array Test: ";
  40. if ($ret !== FALSE && @md5(implode('', $_SERVER)) == md5_file("TEST5")) {
  41. echo 'OK';
  42. } else {
  43. echo 'FAIL';
  44. }
  45. echo "\n";
  46. for ($i = 1; $i < 6; $i++) {
  47. @unlink("./TEST{$i}");
  48. }
  49. ?>
  50. --EXPECT--
  51. String Test: OK
  52. Integer Test: OK
  53. Float Test: OK
  54. Bool Test: OK
  55. Array Test: OK