1--TEST-- 2Test symlink(), linkinfo(), link() and is_link() functions: basic functionality - link to dirs 3--SKIPIF-- 4<?php 5if (PHP_OS_FAMILY === 'Windows') { 6 require_once __DIR__ . '/windows_links/common.inc'; 7 skipIfSeCreateSymbolicLinkPrivilegeIsDisabled(__FILE__); 8} 9?> 10--FILE-- 11<?php 12/* Prototype: bool symlink ( string $target, string $link ); 13 Description: creates a symbolic link to the existing target with the specified name link 14 15 Prototype: bool is_link ( string $filename ); 16 Description: Tells whether the given file is a symbolic link. 17 18 Prototype: bool link ( string $target, string $link ); 19 Description: Create a hard link 20 21 Prototype: int linkinfo ( string $path ); 22 Description: Gets information about a link 23*/ 24 25$file_path = __DIR__; 26 27echo "*** Testing symlink(), linkinfo(), link() and is_link() : basic functionality ***\n"; 28 29/* Creating soft/hard link to the temporary dir $dirname and checking 30 linkinfo() and is_link() on the link created to $dirname */ 31 32$dirname = "symlink_link_linkinfo_is_link_basic2"; 33mkdir($file_path."/".$dirname); 34 35echo "\n*** Testing symlink(), linkinfo(), link() and is_link() on directory ***\n"; 36 37// name of the soft link created to $dirname 38$sym_linkname = "$file_path/$dirname/symlink_link_linkinfo_is_link_softlink_basic2.tmp"; 39 40// name of the hard link created to $dirname 41$linkname = "$file_path/$dirname/symlink_link_linkinfo_is_link_hardlink_basic2.tmp"; 42 43// testing on soft link 44echo "\n-- Testing on soft links --\n"; 45// creating soft link to $dirname 46var_dump( symlink("$file_path/$dirname", $sym_linkname) ); // this works, expected true 47// gets information about soft link created to directory; expected: true 48$linkinfo = linkinfo($sym_linkname); 49var_dump( is_int($linkinfo) && $linkinfo !== -1 ); 50// checks if link created is soft link; expected: true 51var_dump( is_link($sym_linkname) ); 52// clear the cache 53clearstatcache(); 54 55// testing on hard link 56echo "\n-- Testing on hard links --\n"; 57// creating hard link to $dirname; expected: false 58var_dump( link("$file_path/$dirname", $linkname) ); // this doesn't work, expected false 59var_dump( linkinfo($linkname) ); // link doesn't exists as not created, expected false 60var_dump( is_link($linkname) ); // link doesn't exists as not created, expected false 61// clear the cache 62clearstatcache(); 63 64// deleting the links 65if (PHP_OS_FAMILY === 'Windows') { 66 rmdir($sym_linkname); 67} else { 68 unlink($sym_linkname); 69} 70 71echo "Done\n"; 72?> 73--CLEAN-- 74<?php 75$dirname = __DIR__."/symlink_link_linkinfo_is_link_basic2"; 76rmdir($dirname); 77?> 78--EXPECTF-- 79*** Testing symlink(), linkinfo(), link() and is_link() : basic functionality *** 80 81*** Testing symlink(), linkinfo(), link() and is_link() on directory *** 82 83-- Testing on soft links -- 84bool(true) 85bool(true) 86bool(true) 87 88-- Testing on hard links -- 89 90Warning: link(): %s in %s on line %d 91bool(false) 92 93Warning: linkinfo(): No such file or directory in %s on line %d 94int(-1) 95bool(false) 96Done 97