copy_variation4.phpt 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. --TEST--
  2. Test copy() function: usage variations - destination file names(empty string, nulls & bools)
  3. --SKIPIF--
  4. <?php
  5. if(substr(PHP_OS, 0, 3) == "WIN")
  6. die("skip Do not run on Windows");
  7. if(substr(PHP_OS, 0, 3) == "AIX")
  8. die("skip Do not run on AIX");
  9. ?>
  10. --FILE--
  11. <?php
  12. /* Test copy() function: In creation of destination file names with empty string, nulls & bools
  13. and checking the existence and size of destination files
  14. */
  15. echo "*** Test copy() function: destination file names with empty string, nulls & bools ***\n";
  16. $file_path = __DIR__;
  17. $src_file_name = $file_path."/copy_variation4.tmp";
  18. $file_handle = fopen($src_file_name, "w");
  19. fwrite( $file_handle, str_repeat("Hello2World...\n", 100) );
  20. fclose($file_handle);
  21. /* array of destination file names */
  22. $dest_files = array(
  23. /* File names containing(or with) nulls */
  24. "",
  25. NULL,
  26. FALSE,
  27. false,
  28. TRUE,
  29. true
  30. );
  31. echo "Size of the source file before copy operation => ";
  32. var_dump( filesize($src_file_name) );
  33. clearstatcache();
  34. echo "\n-- Now applying copy() on source file to create copies --";
  35. $count = 1;
  36. foreach($dest_files as $dest_file) {
  37. echo "\n-- Iteration $count --\n";
  38. $dest_file_name = $file_path."/$dest_file";
  39. echo "Existence of destination file before copy => ";
  40. var_dump( file_exists($dest_file_name) );
  41. echo "Copy operation => ";
  42. var_dump( copy($src_file_name, $dest_file_name) );
  43. echo "Existence of destination file => ";
  44. var_dump( file_exists($dest_file_name) );
  45. echo "Destination file name => ";
  46. print($dest_file_name);
  47. echo "\n";
  48. echo "Size of source file => ";
  49. var_dump( filesize($src_file_name) );
  50. clearstatcache();
  51. echo "Size of destination file => ";
  52. var_dump( filesize($dest_file_name) );
  53. clearstatcache();
  54. unlink($dest_file_name);
  55. $count++;
  56. }
  57. echo "*** Done ***\n";
  58. ?>
  59. --CLEAN--
  60. <?php
  61. unlink(__DIR__."/copy_variation4.tmp");
  62. ?>
  63. --EXPECTF--
  64. *** Test copy() function: destination file names with empty string, nulls & bools ***
  65. Size of the source file before copy operation => int(1500)
  66. -- Now applying copy() on source file to create copies --
  67. -- Iteration 1 --
  68. Existence of destination file before copy => bool(true)
  69. Copy operation =>
  70. Warning: copy(): The second argument to copy() function cannot be a directory in %s on line %d
  71. bool(false)
  72. Existence of destination file => bool(true)
  73. Destination file name => %s/
  74. Size of source file => int(1500)
  75. Size of destination file => int(%d)
  76. Warning: unlink(%s): %s
  77. -- Iteration 2 --
  78. Existence of destination file before copy => bool(true)
  79. Copy operation =>
  80. Warning: copy(): The second argument to copy() function cannot be a directory in %s on line %d
  81. bool(false)
  82. Existence of destination file => bool(true)
  83. Destination file name => %s/
  84. Size of source file => int(1500)
  85. Size of destination file => int(%d)
  86. Warning: unlink(%s): %s
  87. -- Iteration 3 --
  88. Existence of destination file before copy => bool(true)
  89. Copy operation =>
  90. Warning: copy(): The second argument to copy() function cannot be a directory in %s on line %d
  91. bool(false)
  92. Existence of destination file => bool(true)
  93. Destination file name => %s/
  94. Size of source file => int(1500)
  95. Size of destination file => int(%d)
  96. Warning: unlink(%s): %s
  97. -- Iteration 4 --
  98. Existence of destination file before copy => bool(true)
  99. Copy operation =>
  100. Warning: copy(): The second argument to copy() function cannot be a directory in %s on line %d
  101. bool(false)
  102. Existence of destination file => bool(true)
  103. Destination file name => %s/
  104. Size of source file => int(1500)
  105. Size of destination file => int(%d)
  106. Warning: unlink(%s): %s
  107. -- Iteration 5 --
  108. Existence of destination file before copy => bool(false)
  109. Copy operation => bool(true)
  110. Existence of destination file => bool(true)
  111. Destination file name => %s/1
  112. Size of source file => int(1500)
  113. Size of destination file => int(1500)
  114. -- Iteration 6 --
  115. Existence of destination file before copy => bool(false)
  116. Copy operation => bool(true)
  117. Existence of destination file => bool(true)
  118. Destination file name => %s/1
  119. Size of source file => int(1500)
  120. Size of destination file => int(1500)
  121. *** Done ***