Return to tempnam_variation7.phpt CVS log | Up to [ELWIX - Embedded LightWeight unIX -] / embedaddon / php / ext / standard / tests / file |
1.1 misho 1: --TEST-- 2: Test tempnam() function: usage variations - invalid/non-existing dir 3: --SKIPIF-- 4: <?php 5: if(substr(PHP_OS, 0, 3) == "WIN") 6: die("skip Do not run on Windows"); 7: ?> 8: --FILE-- 9: <?php 10: /* Prototype: string tempnam ( string $dir, string $prefix ); 11: Description: Create file with unique file name. 12: */ 13: 14: /* Passing invalid/non-existing args for $dir, 15: hence the unique files will be created in temporary dir */ 16: 17: echo "*** Testing tempnam() with invalid/non-existing directory names ***\n"; 18: /* An array of names, which will be passed as a dir name */ 19: $names_arr = array( 20: /* Invalid args */ 21: -1, 22: TRUE, 23: FALSE, 24: NULL, 25: "", 26: " ", 27: "\0", 28: array(), 29: 30: /* Non-existing dirs */ 31: "/no/such/file/dir", 32: "php" 33: 34: ); 35: 36: for( $i=0; $i<count($names_arr); $i++ ) { 37: echo "-- Iteration $i --\n"; 38: $file_name = tempnam($names_arr[$i], "tempnam_variation3.tmp"); 39: 40: if( file_exists($file_name) ){ 41: 42: echo "File name is => "; 43: print($file_name); 44: echo "\n"; 45: 46: echo "File permissions are => "; 47: printf("%o", fileperms($file_name) ); 48: echo "\n"; 49: 50: echo "File created in => "; 51: $file_dir = dirname($file_name); 52: 53: if (realpath($file_dir) == realpath(sys_get_temp_dir())) { 54: echo "temp dir\n"; 55: } 56: else { 57: echo "unknown location\n"; 58: } 59: 60: } 61: else { 62: echo "-- File is not created --\n"; 63: } 64: 65: unlink($file_name); 66: } 67: 68: echo "\n*** Done ***\n"; 69: ?> 70: --EXPECTF-- 71: *** Testing tempnam() with invalid/non-existing directory names *** 72: -- Iteration 0 -- 73: File name is => %s%etempnam_variation3.tmp%s 74: File permissions are => 100600 75: File created in => temp dir 76: -- Iteration 1 -- 77: File name is => %s%etempnam_variation3.tmp%s 78: File permissions are => 100600 79: File created in => temp dir 80: -- Iteration 2 -- 81: File name is => %s%etempnam_variation3.tmp%s 82: File permissions are => 100600 83: File created in => temp dir 84: -- Iteration 3 -- 85: File name is => %s%etempnam_variation3.tmp%s 86: File permissions are => 100600 87: File created in => temp dir 88: -- Iteration 4 -- 89: File name is => %s%etempnam_variation3.tmp%s 90: File permissions are => 100600 91: File created in => temp dir 92: -- Iteration 5 -- 93: File name is => %s%etempnam_variation3.tmp%s 94: File permissions are => 100600 95: File created in => temp dir 96: -- Iteration 6 -- 1.1.1.2 ! misho 97: ! 98: Warning: tempnam() expects parameter 1 to be a valid path, string given in %s on line %d 1.1 misho 99: -- File is not created -- 100: 101: Warning: unlink(): %s in %s on line %d 102: -- Iteration 7 -- 103: 1.1.1.2 ! misho 104: Warning: tempnam() expects parameter 1 to be a valid path, array given in %s on line %d 1.1 misho 105: -- File is not created -- 106: 107: Warning: unlink(): %s in %s on line %d 108: -- Iteration 8 -- 1.1.1.2 ! misho 109: File name is => %s/tempnam_variation3.tmp%s 1.1 misho 110: File permissions are => 100600 111: File created in => temp dir 112: -- Iteration 9 -- 1.1.1.2 ! misho 113: File name is => %s/tempnam_variation3.tmp%s 1.1 misho 114: File permissions are => 100600 115: File created in => temp dir 116: 117: *** Done *** 118: