1--TEST--
2Test rename() function: variation
3--SKIPIF--
4<?php
5if (substr(PHP_OS, 0, 3) == 'WIN') die('skip..  not for Windows');
6?>
7--FILE--
8<?php
9/* Prototype: bool rename ( string $oldname, string $newname [, resource $context] );
10   Description: Renames a file or directory
11*/
12
13echo "\n*** Testing rename() on non-existing file ***\n";
14$file_path = dirname(__FILE__);
15
16// try renaming a non existing file
17$src_name = $file_path."/non_existent_file.tmp";
18$dest_name = $file_path."/rename_variation8_new.tmp";
19var_dump( rename($src_name, $dest_name) );
20
21// ensure that $dest_name didn't get created
22var_dump( file_exists($src_name) );  // expecting false
23var_dump( file_exists($dest_name) ); // expecting false
24
25// rename a existing dir to new name
26echo "\n*** Testing rename() on existing directory ***\n";
27$dir_name = $file_path."/rename_basic_dir";
28mkdir($dir_name);
29$new_dir_name = $file_path."/rename_basic_dir1";
30var_dump( rename($dir_name, $new_dir_name) );
31//ensure that $new_dir_name got created
32var_dump( file_exists($dir_name) );  // expecting false
33var_dump( file_exists($new_dir_name) );  // expecting true
34
35// try to rename an non_existing dir
36echo "\n*** Testing rename() on non-existing directory ***\n";
37$non_existent_dir_name = $file_path."/non_existent_dir";
38$new_dir_name = "$file_path/rename_basic_dir2";
39var_dump( rename($non_existent_dir_name, $new_dir_name) );
40// ensure that $new_dir_name didn't get created
41var_dump( file_exists($non_existent_dir_name) );  // expecting flase
42var_dump( file_exists($new_dir_name) );  // expecting false
43
44echo "Done\n";
45?>
46--CLEAN--
47<?php
48unlink(dirname(__FILE__)."/rename_basic_new2.tmp");
49rmdir(dirname(__FILE__)."/rename_basic_dir1");
50?>
51--EXPECTF--
52*** Testing rename() on non-existing file ***
53
54Warning: rename(%s/non_existent_file.tmp,%s/rename_variation8_new.tmp): No such file or directory in %s on line %d
55bool(false)
56bool(false)
57bool(false)
58
59*** Testing rename() on existing directory ***
60bool(true)
61bool(false)
62bool(true)
63
64*** Testing rename() on non-existing directory ***
65
66Warning: rename(%s/non_existent_dir,%s/rename_basic_dir2): No such file or directory in %s on line %d
67bool(false)
68bool(false)
69bool(false)
70Done
71
72