Annotation of embedaddon/php/ext/standard/tests/file/copy_variation4.phpt, revision 1.1.1.2
1.1 misho 1: --TEST--
2: Test copy() function: usage variations - destination file names(empty string, nulls & bools)
3: --SKIPIF--
4: <?php
1.1.1.2 ! misho 5: if(substr(PHP_OS, 0, 3) == "WIN")
! 6: die("skip Do not run on Windows");
! 7:
1.1 misho 8: if(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:
22: echo "*** 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";
1.1.1.2 ! misho 25: $file_handle = fopen($src_file_name, "w");
1.1 misho 26: fwrite( $file_handle, str_repeat(b"Hello2World...\n", 100) );
27: fclose($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:
42: echo "Size of the source file before copy operation => ";
43: var_dump( filesize($src_file_name) );
44: clearstatcache();
45:
46: echo "\n-- Now applying copy() on source file to create copies --";
47: $count = 1;
48: foreach($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:
79: echo "*** Done ***\n";
80: ?>
81:
82: --CLEAN--
83: <?php
84: unlink(dirname(__FILE__)."/copy_variation4.tmp");
85: ?>
86:
87: --EXPECTF--
88: *** Test copy() function: destination file names with empty string, nulls & bools ***
89: Size of the source file before copy operation => int(1500)
90:
91: -- Now applying copy() on source file to create copies --
92: -- Iteration 1 --
93: Existence of destination file before copy => bool(true)
94: Copy operation =>
95: Warning: copy(): The second argument to copy() function cannot be a directory in %s on line %d
96: bool(false)
97: Existence of destination file => bool(true)
98: Destination file name => %s/
99: Size of source file => int(1500)
100: Size of destination file => int(%d)
101:
102: Warning: unlink(%s): %s
103:
104: -- Iteration 2 --
105: Existence of destination file before copy => bool(true)
106: Copy operation =>
107: Warning: copy(): The second argument to copy() function cannot be a directory in %s on line %d
108: bool(false)
109: Existence of destination file => bool(true)
110: Destination file name => %s/
111: Size of source file => int(1500)
112: Size of destination file => int(%d)
113:
114: Warning: unlink(%s): %s
115:
116: -- Iteration 3 --
1.1.1.2 ! misho 117: Existence of destination file before copy =>
! 118: Warning: file_exists() expects parameter 1 to be a valid path, string given in %s on line %d
! 119: NULL
! 120: Copy operation =>
! 121: Warning: copy() expects parameter 2 to be a valid path, string given in %s on line %d
! 122: NULL
! 123: Existence of destination file =>
! 124: Warning: file_exists() expects parameter 1 to be a valid path, string given in %s on line %d
! 125: NULL
1.1 misho 126: Destination file name => %s/
127: Size of source file => int(1500)
1.1.1.2 ! misho 128: Size of destination file =>
! 129: Warning: filesize() expects parameter 1 to be a valid path, string given in %s on line %d
! 130: NULL
! 131:
! 132: Warning: unlink() expects parameter 1 to be a valid path, string given in %s on line %d
1.1 misho 133:
134: -- Iteration 4 --
135: Existence of destination file before copy => bool(true)
136: Copy operation =>
137: Warning: copy(): The second argument to copy() function cannot be a directory in %s on line %d
138: bool(false)
139: Existence of destination file => bool(true)
140: Destination file name => %s/
141: Size of source file => int(1500)
142: Size of destination file => int(%d)
143:
144: Warning: unlink(%s): %s
145:
146: -- Iteration 5 --
147: Existence of destination file before copy => bool(true)
148: Copy operation =>
149: Warning: copy(): The second argument to copy() function cannot be a directory in %s on line %d
150: bool(false)
151: Existence of destination file => bool(true)
152: Destination file name => %s/
153: Size of source file => int(1500)
154: Size of destination file => int(%d)
155:
156: Warning: unlink(%s): %s
157:
158: -- Iteration 6 --
159: Existence of destination file before copy => bool(false)
160: Copy operation => bool(true)
161: Existence of destination file => bool(true)
162: Destination file name => %s/1
163: Size of source file => int(1500)
164: Size of destination file => int(1500)
165:
166: -- Iteration 7 --
167: Existence of destination file before copy => bool(false)
168: Copy operation => bool(true)
169: Existence of destination file => bool(true)
170: Destination file name => %s/1
171: Size of source file => int(1500)
172: Size of destination file => int(1500)
173: *** Done ***
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>