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