1--TEST--
2Test rename() function: usage variations-1 (Bug#42638)
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/* creating directory */
13$file_path = __DIR__;
14mkdir("$file_path/rename_variation");
15
16/* rename files across directories */
17echo "*** Testing rename() : rename files across directories ***\n";
18$src_filenames = array(
19  "$file_path/rename_variation/rename_variation.tmp",
20
21  /* Testing a file trailing slash */
22  "$file_path/rename_variation/rename_variation.tmp/",
23
24  /* Testing file with double slashes */
25  "$file_path/rename_variation//rename_variation.tmp",
26  "$file_path//rename_variation//rename_variation.tmp",
27);
28$counter = 1;
29/* loop through each $file and rename it to rename_variation_renamed.tmp */
30foreach($src_filenames as $src_filename) {
31  echo "-- Iteration $counter --\n";
32  $fp = fopen("$file_path/rename_variation/rename_variation.tmp", "w");
33  fclose($fp);
34  $dest_filename = "$file_path/rename_variation_renamed.tmp";
35  var_dump( rename($src_filename, $dest_filename) );
36  // ensure that file got renamed to new name
37  var_dump( file_exists($src_filename) );  // expecting false
38  var_dump( file_exists($dest_filename) );  // expecting true
39  $counter++;
40
41  // unlink the file
42  unlink($dest_filename);
43}
44
45// clean the temp dir and file
46rmdir("$file_path/rename_variation");
47
48echo "Done\n";
49?>
50--EXPECTF--
51*** Testing rename() : rename files across directories ***
52-- Iteration 1 --
53bool(true)
54bool(false)
55bool(true)
56-- Iteration 2 --
57
58Warning: rename(%s,%s): Not a directory in %s on line %d
59bool(false)
60bool(false)
61bool(false)
62
63Warning: unlink(%s): No such file or directory in %s on line %d
64-- Iteration 3 --
65bool(true)
66bool(false)
67bool(true)
68-- Iteration 4 --
69bool(true)
70bool(false)
71bool(true)
72Done
73