1--TEST--
2Test rename() function: usage variations
3--SKIPIF--
4<?php
5if (substr(PHP_OS, 0, 3) != 'WIN') {
6    die('skip.. only for Windows');
7}
8?>
9--FILE--
10<?php
11require __DIR__.'/file.inc';
12
13/* creating directory */
14$file_path = __DIR__;
15$dirname = "$file_path/rename_variation3_dir";
16mkdir($dirname);
17
18/* test rename() by trying to rename an existing file/dir to the same name
19  and one another */
20
21$filename = "$file_path/rename_variation3.tmp";
22$fp = fopen($filename, "w");
23if (!$fp) {
24    die("Cannot create $filename\n");
25}
26fclose($fp);
27
28echo "\n-- Renaming file to same file name --\n";
29var_dump( rename($filename, $filename) );
30var_dump( file_exists($filename) );
31
32echo "\n-- Renaming directory to same directory name --\n";
33var_dump( rename($dirname, $dirname) );
34var_dump( file_exists($dirname) );
35
36echo "\n-- Renaming existing file to existing directory name --\n";
37var_dump( rename($filename, $dirname) );
38var_dump( file_exists($filename) );
39var_dump( file_exists($dirname) );
40
41echo "\n-- Renaming existing directory to existing file name --\n";
42$fp = fopen($filename, "w");
43fclose($fp);
44
45var_dump( rename($dirname, $filename) );
46var_dump( file_exists($filename) );
47var_dump( file_exists($dirname) );
48
49echo "Done\n";
50?>
51--CLEAN--
52<?php
53$file_path = __DIR__;
54rmdir($file_path."/rename_variation3.tmp");
55?>
56--EXPECTF--
57-- Renaming file to same file name --
58bool(true)
59bool(true)
60
61-- Renaming directory to same directory name --
62bool(true)
63bool(true)
64
65-- Renaming existing file to existing directory name --
66
67Warning: rename(%s/rename_variation3.tmp,%s/rename_variation3_dir): Access is denied (code: 5) in %s on line %d
68bool(false)
69bool(true)
70bool(true)
71
72-- Renaming existing directory to existing file name --
73bool(true)
74bool(true)
75bool(false)
76Done
77