1--TEST--
2Test rename() function: usage variations-6
3--SKIPIF--
4<?php
5if (substr(PHP_OS, 0, 3) == 'WIN') {
6    die('skip.. only for Linux');
7}
8?>
9--FILE--
10<?php
11
12/* test rename() by trying to rename an existing file/dir/link to the same name
13  and one another */
14// create a dir
15$file_path = __DIR__;
16$dirname = "$file_path/rename_variation5_dir";
17mkdir($dirname);
18//create a file
19$filename = "$file_path/rename_variation5.tmp";
20$fp = fopen($filename, "w");
21fclose($fp);
22// create a link
23$linkname = "$file_path/rename_variation5_link.tmp";
24symlink($filename, $linkname);
25
26echo "\n-- Renaming link to same link name --\n";
27var_dump( rename($linkname, $linkname) );
28
29echo "\n-- Renaming file to same file name --\n";
30var_dump( rename($filename, $filename) );
31
32echo "\n-- Renaming directory to same directory name --\n";
33var_dump( rename($dirname, $dirname) );
34
35echo "\n-- Renaming existing link to existing directory name --\n";
36var_dump( rename($linkname, $dirname) );
37echo "\n-- Renaming existing link to existing file name --\n";
38var_dump( rename($linkname, $filename) );
39
40echo "\n-- Renaming existing file to existing directory name --\n";
41var_dump( rename($filename, $dirname) );
42echo "\n-- Renaming existing file to existing link name --\n";
43var_dump( rename($filename, $linkname) );
44
45echo "\n-- Renaming existing directory to existing file name --\n";
46$fp = fopen($filename, "w");
47fclose($fp);
48var_dump( rename($dirname, $filename) );
49echo "\n-- Renaming existing directory to existing link name --\n";
50var_dump( rename($dirname, $linkname) );
51
52echo "Done\n";
53?>
54--CLEAN--
55<?php
56$file_path = __DIR__;
57unlink($file_path."/rename_variation5_link.tmp");
58unlink($file_path."/rename_variation5.tmp");
59rmdir($file_path."/rename_variation5_dir");
60?>
61--EXPECTF--
62-- Renaming link to same link name --
63bool(true)
64
65-- Renaming file to same file name --
66bool(true)
67
68-- Renaming directory to same directory name --
69bool(true)
70
71-- Renaming existing link to existing directory name --
72
73Warning: rename(%s,%s): Is a directory in %s on line %d
74bool(false)
75
76-- Renaming existing link to existing file name --
77bool(true)
78
79-- Renaming existing file to existing directory name --
80
81Warning: rename(%s,%s): Is a directory in %s on line %d
82bool(false)
83
84-- Renaming existing file to existing link name --
85bool(true)
86
87-- Renaming existing directory to existing file name --
88
89Warning: rename(%s,%s): Not a directory in %s on line %d
90bool(false)
91
92-- Renaming existing directory to existing link name --
93
94Warning: rename(%s,%s): Not a directory in %s on line %d
95bool(false)
96Done
97