1
0
mirror of https://github.com/php/php-src.git synced 2026-04-27 10:16:41 +02:00
Files
archived-php-src/ext/standard/tests/file/copy_variation2.phpt
T
Peter Kokot d679f02295 Sync leading and final newlines in *.phpt sections
This patch adds missing newlines, trims multiple redundant final
newlines into a single one, and trims redundant leading newlines in all
*.phpt sections.

According to POSIX, a line is a sequence of zero or more non-' <newline>'
characters plus a terminating '<newline>' character. [1] Files should
normally have at least one final newline character.

C89 [2] and later standards [3] mention a final newline:
"A source file that is not empty shall end in a new-line character,
which shall not be immediately preceded by a backslash character."

Although it is not mandatory for all files to have a final newline
fixed, a more consistent and homogeneous approach brings less of commit
differences issues and a better development experience in certain text
editors and IDEs.

[1] http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap03.html#tag_03_206
[2] https://port70.net/~nsz/c/c89/c89-draft.html#2.1.1.2
[3] https://port70.net/~nsz/c/c99/n1256.html#5.1.1.2
2018-10-15 04:33:09 +02:00

236 lines
6.7 KiB
PHP

--TEST--
Test copy() function: usage variations - destination file names(special chars)
--SKIPIF--
<?php
if(substr(PHP_OS, 0, 3) == "WIN")
die("skip do not run on Windows");
?>
--FILE--
<?php
/* Prototype: bool copy ( string $source, string $dest );
Description: Makes a copy of the file source to dest.
Returns TRUE on success or FALSE on failure.
*/
/* Test copy() function: In creation of destination file names containing special characters
and checking the existence and size of destination files
*/
echo "*** Test copy() function: destination file names containing special characters ***\n";
$file_path = dirname(__FILE__);
$src_file_name = $file_path."/copy_variation2.tmp";
$file_handle = fopen($src_file_name, "w");
fwrite( $file_handle, str_repeat("Hello2World...\n", 100) );
fclose($file_handle);
/* array of destination file names */
$dest_files = array(
/* File names containing special(non-alpha numeric) characters */
"_copy_variation2.tmp",
"@copy_variation2.tmp",
"#copy_variation2.tmp",
"+copy_variation2.tmp",
"*copy_variation2.tmp",
"?copy_variation2.tmp",
"<copy_variation2.tmp",
">copy_variation2.tmp",
"!copy_variation2.tmp",
"&copy_variation2.tmp",
"(copy_variation2.tmp",
":copy_variation2.tmp",
";copy_variation2.tmp",
"=copy_variation2.tmp",
"[copy_variation2.tmp",
"^copy_variation2.tmp",
"{copy_variation2.tmp",
"|copy_variation2.tmp",
"~copy_variation2.tmp",
"\$copy_variation2.tmp"
);
echo "Size of the source file before copy operation => ";
var_dump( filesize("$src_file_name") );
clearstatcache();
echo "\n--- Now applying copy() on source file to create copies ---";
$count = 1;
foreach($dest_files as $dest_file) {
echo "\n-- Iteration $count --\n";
$dest_file_name = $file_path."/$dest_file";
echo "Copy operation => ";
var_dump( copy($src_file_name, $dest_file_name) );
echo "Existence of destination file => ";
var_dump( file_exists($dest_file_name) );
echo "Destination file name => ";
print($dest_file_name);
echo "\n";
echo "Size of source file => ";
var_dump( filesize($src_file_name) );
clearstatcache();
echo "Size of destination file => ";
var_dump( filesize($dest_file_name) );
clearstatcache();
unlink($dest_file_name);
$count++;
}
echo "*** Done ***\n";
?>
--CLEAN--
<?php
unlink(dirname(__FILE__)."/copy_variation2.tmp");
?>
--EXPECTF--
*** Test copy() function: destination file names containing special characters ***
Size of the source file before copy operation => int(1500)
--- Now applying copy() on source file to create copies ---
-- Iteration 1 --
Copy operation => bool(true)
Existence of destination file => bool(true)
Destination file name => %s/_copy_variation2.tmp
Size of source file => int(1500)
Size of destination file => int(1500)
-- Iteration 2 --
Copy operation => bool(true)
Existence of destination file => bool(true)
Destination file name => %s/@copy_variation2.tmp
Size of source file => int(1500)
Size of destination file => int(1500)
-- Iteration 3 --
Copy operation => bool(true)
Existence of destination file => bool(true)
Destination file name => %s/#copy_variation2.tmp
Size of source file => int(1500)
Size of destination file => int(1500)
-- Iteration 4 --
Copy operation => bool(true)
Existence of destination file => bool(true)
Destination file name => %s/+copy_variation2.tmp
Size of source file => int(1500)
Size of destination file => int(1500)
-- Iteration 5 --
Copy operation => bool(true)
Existence of destination file => bool(true)
Destination file name => %s/*copy_variation2.tmp
Size of source file => int(1500)
Size of destination file => int(1500)
-- Iteration 6 --
Copy operation => bool(true)
Existence of destination file => bool(true)
Destination file name => %s/?copy_variation2.tmp
Size of source file => int(1500)
Size of destination file => int(1500)
-- Iteration 7 --
Copy operation => bool(true)
Existence of destination file => bool(true)
Destination file name => %s/<copy_variation2.tmp
Size of source file => int(1500)
Size of destination file => int(1500)
-- Iteration 8 --
Copy operation => bool(true)
Existence of destination file => bool(true)
Destination file name => %s/>copy_variation2.tmp
Size of source file => int(1500)
Size of destination file => int(1500)
-- Iteration 9 --
Copy operation => bool(true)
Existence of destination file => bool(true)
Destination file name => %s/!copy_variation2.tmp
Size of source file => int(1500)
Size of destination file => int(1500)
-- Iteration 10 --
Copy operation => bool(true)
Existence of destination file => bool(true)
Destination file name => %s/&copy_variation2.tmp
Size of source file => int(1500)
Size of destination file => int(1500)
-- Iteration 11 --
Copy operation => bool(true)
Existence of destination file => bool(true)
Destination file name => %s/(copy_variation2.tmp
Size of source file => int(1500)
Size of destination file => int(1500)
-- Iteration 12 --
Copy operation => bool(true)
Existence of destination file => bool(true)
Destination file name => %s/:copy_variation2.tmp
Size of source file => int(1500)
Size of destination file => int(1500)
-- Iteration 13 --
Copy operation => bool(true)
Existence of destination file => bool(true)
Destination file name => %s/;copy_variation2.tmp
Size of source file => int(1500)
Size of destination file => int(1500)
-- Iteration 14 --
Copy operation => bool(true)
Existence of destination file => bool(true)
Destination file name => %s/=copy_variation2.tmp
Size of source file => int(1500)
Size of destination file => int(1500)
-- Iteration 15 --
Copy operation => bool(true)
Existence of destination file => bool(true)
Destination file name => %s/[copy_variation2.tmp
Size of source file => int(1500)
Size of destination file => int(1500)
-- Iteration 16 --
Copy operation => bool(true)
Existence of destination file => bool(true)
Destination file name => %s/^copy_variation2.tmp
Size of source file => int(1500)
Size of destination file => int(1500)
-- Iteration 17 --
Copy operation => bool(true)
Existence of destination file => bool(true)
Destination file name => %s/{copy_variation2.tmp
Size of source file => int(1500)
Size of destination file => int(1500)
-- Iteration 18 --
Copy operation => bool(true)
Existence of destination file => bool(true)
Destination file name => %s/|copy_variation2.tmp
Size of source file => int(1500)
Size of destination file => int(1500)
-- Iteration 19 --
Copy operation => bool(true)
Existence of destination file => bool(true)
Destination file name => %s/~copy_variation2.tmp
Size of source file => int(1500)
Size of destination file => int(1500)
-- Iteration 20 --
Copy operation => bool(true)
Existence of destination file => bool(true)
Destination file name => %s/$copy_variation2.tmp
Size of source file => int(1500)
Size of destination file => int(1500)
*** Done ***