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