copy_variation4.phpt 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  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. /* Prototype: bool copy ( string $source, string $dest );
  13. Description: Makes a copy of the file source to dest.
  14. Returns TRUE on success or FALSE on failure.
  15. */
  16. /* Test copy() function: In creation of destination file names with empty string, nulls & bools
  17. and checking the existence and size of destination files
  18. */
  19. echo "*** Test copy() function: destination file names with empty string, nulls & bools ***\n";
  20. $file_path = dirname(__FILE__);
  21. $src_file_name = $file_path."/copy_variation4.tmp";
  22. $file_handle = fopen($src_file_name, "w");
  23. fwrite( $file_handle, str_repeat(b"Hello2World...\n", 100) );
  24. fclose($file_handle);
  25. /* array of destination file names */
  26. $dest_files = array(
  27. /* File names containing(or with) nulls */
  28. "",
  29. NULL,
  30. "\0",
  31. FALSE,
  32. false,
  33. TRUE,
  34. true
  35. );
  36. echo "Size of the source file before copy operation => ";
  37. var_dump( filesize($src_file_name) );
  38. clearstatcache();
  39. echo "\n-- Now applying copy() on source file to create copies --";
  40. $count = 1;
  41. foreach($dest_files as $dest_file) {
  42. echo "\n-- Iteration $count --\n";
  43. $dest_file_name = $file_path."/$dest_file";
  44. echo "Existence of destination file before copy => ";
  45. var_dump( file_exists($dest_file_name) );
  46. echo "Copy operation => ";
  47. var_dump( copy($src_file_name, $dest_file_name) );
  48. echo "Existence of destination file => ";
  49. var_dump( file_exists($dest_file_name) );
  50. echo "Destination file name => ";
  51. print($dest_file_name);
  52. echo "\n";
  53. echo "Size of source file => ";
  54. var_dump( filesize($src_file_name) );
  55. clearstatcache();
  56. echo "Size of destination file => ";
  57. var_dump( filesize($dest_file_name) );
  58. clearstatcache();
  59. unlink($dest_file_name);
  60. $count++;
  61. }
  62. echo "*** Done ***\n";
  63. ?>
  64. --CLEAN--
  65. <?php
  66. unlink(dirname(__FILE__)."/copy_variation4.tmp");
  67. ?>
  68. --EXPECTF--
  69. *** Test copy() function: destination file names with empty string, nulls & bools ***
  70. Size of the source file before copy operation => int(1500)
  71. -- Now applying copy() on source file to create copies --
  72. -- Iteration 1 --
  73. Existence of destination file before copy => bool(true)
  74. Copy operation =>
  75. Warning: copy(): The second argument to copy() function cannot be a directory in %s on line %d
  76. bool(false)
  77. Existence of destination file => bool(true)
  78. Destination file name => %s/
  79. Size of source file => int(1500)
  80. Size of destination file => int(%d)
  81. Warning: unlink(%s): %s
  82. -- Iteration 2 --
  83. Existence of destination file before copy => bool(true)
  84. Copy operation =>
  85. Warning: copy(): The second argument to copy() function cannot be a directory in %s on line %d
  86. bool(false)
  87. Existence of destination file => bool(true)
  88. Destination file name => %s/
  89. Size of source file => int(1500)
  90. Size of destination file => int(%d)
  91. Warning: unlink(%s): %s
  92. -- Iteration 3 --
  93. Existence of destination file before copy =>
  94. Warning: file_exists() expects parameter 1 to be a valid path, string given in %s on line %d
  95. NULL
  96. Copy operation =>
  97. Warning: copy() expects parameter 2 to be a valid path, string given in %s on line %d
  98. NULL
  99. Existence of destination file =>
  100. Warning: file_exists() expects parameter 1 to be a valid path, string given in %s on line %d
  101. NULL
  102. Destination file name => %s/�
  103. Size of source file => int(1500)
  104. Size of destination file =>
  105. Warning: filesize() expects parameter 1 to be a valid path, string given in %s on line %d
  106. NULL
  107. Warning: unlink() expects parameter 1 to be a valid path, string given in %s on line %d
  108. -- Iteration 4 --
  109. Existence of destination file before copy => bool(true)
  110. Copy operation =>
  111. Warning: copy(): The second argument to copy() function cannot be a directory in %s on line %d
  112. bool(false)
  113. Existence of destination file => bool(true)
  114. Destination file name => %s/
  115. Size of source file => int(1500)
  116. Size of destination file => int(%d)
  117. Warning: unlink(%s): %s
  118. -- Iteration 5 --
  119. Existence of destination file before copy => bool(true)
  120. Copy operation =>
  121. Warning: copy(): The second argument to copy() function cannot be a directory in %s on line %d
  122. bool(false)
  123. Existence of destination file => bool(true)
  124. Destination file name => %s/
  125. Size of source file => int(1500)
  126. Size of destination file => int(%d)
  127. Warning: unlink(%s): %s
  128. -- Iteration 6 --
  129. Existence of destination file before copy => bool(false)
  130. Copy operation => bool(true)
  131. Existence of destination file => bool(true)
  132. Destination file name => %s/1
  133. Size of source file => int(1500)
  134. Size of destination file => int(1500)
  135. -- Iteration 7 --
  136. Existence of destination file before copy => bool(false)
  137. Copy operation => bool(true)
  138. Existence of destination file => bool(true)
  139. Destination file name => %s/1
  140. Size of source file => int(1500)
  141. Size of destination file => int(1500)
  142. *** Done ***