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