copy_variation11.phpt 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. --TEST--
  2. Test copy() function: usage variations - existing dir as destination
  3. --FILE--
  4. <?php
  5. /* Prototype: bool copy ( string $source, string $dest );
  6. Description: Makes a copy of the file source to dest.
  7. Returns TRUE on success or FALSE on failure.
  8. */
  9. /* Test copy(): Trying to copy the file to a destination, where destination is an existing dir */
  10. $file_path = dirname(__FILE__);
  11. echo "*** Test copy() function: Trying to create a copy of source file as a dir ***\n";
  12. $file = $file_path."/copy_variation11.tmp";
  13. $file_handle = fopen($file, "w");
  14. fwrite($file_handle, str_repeat(b"Hello, world...", 20));
  15. fclose($file_handle);
  16. $dir = $file_path."/copy_variation11";
  17. mkdir($dir);
  18. echo "Size of source before copy operation => ";
  19. var_dump( filesize($file) ); //size of source before copy
  20. clearstatcache();
  21. echo "Size of destination before copy operation => ";
  22. var_dump( filesize($dir) ); //size of destination before copy
  23. clearstatcache();
  24. echo "\n-- Now applying copy() operation --\n";
  25. var_dump( copy($file, $dir) ); //expected: bool(false)
  26. var_dump( file_exists($file) ); //expected: bool(true)
  27. var_dump( file_exists($dir) ); //expected: bool(true)
  28. var_dump( is_file($file) ); //expected: bool(true)
  29. var_dump( is_dir($file) ); //expected: bool(false)
  30. var_dump( is_file($dir) ); //expected: bool(false)
  31. var_dump( is_dir($dir) ); //expected: bool(true)
  32. var_dump( filesize($file) ); //size of source after copy
  33. var_dump( filesize($dir) ); //size of destination after copy
  34. echo "*** Done ***\n";
  35. ?>
  36. --CLEAN--
  37. <?php
  38. unlink(dirname(__FILE__)."/copy_variation11.tmp");
  39. rmdir(dirname(__FILE__)."/copy_variation11");
  40. ?>
  41. --EXPECTF--
  42. *** Test copy() function: Trying to create a copy of source file as a dir ***
  43. Size of source before copy operation => int(300)
  44. Size of destination before copy operation => int(%d)
  45. -- Now applying copy() operation --
  46. Warning: %s
  47. bool(false)
  48. bool(true)
  49. bool(true)
  50. bool(true)
  51. bool(false)
  52. bool(false)
  53. bool(true)
  54. int(300)
  55. int(%d)
  56. *** Done ***