Annotation of embedaddon/php/ext/standard/tests/file/lstat_stat_basic.phpt, revision 1.1.1.1

1.1       misho       1: --TEST--
                      2: Test lstat() & stat() functions: basic functionality
                      3: --SKIPIF--
                      4: <?php
                      5: if (getenv("SKIP_SLOW_TESTS")) die("skip slow test");
                      6: if (substr(PHP_OS, 0, 3) == 'WIN') {
                      7:     die('skip.. lstat() not available on Windows');
                      8: }
                      9: ?>
                     10: --FILE--
                     11: <?php
                     12: /* Prototype: array lstat ( string $filename );
                     13:    Description: Gives information about a file or symbolic link
                     14: 
                     15:    Prototype: array stat ( string $filename );
                     16:    Description: Gives information about a file
                     17: */
                     18: 
                     19: $file_path = dirname(__FILE__);
                     20: require("$file_path/file.inc");
                     21: 
                     22: echo "*** Testing lstat() & stat() : basic functionality ***\n";
                     23: 
                     24: /* creating temp directory and file */
                     25: 
                     26: // creating dir
                     27: $dirname = "$file_path/lstat_stat_basic";
                     28: @rmdir($dirname);
                     29: mkdir($dirname);
                     30: // stat of the dir created
                     31: $dir_stat = stat($dirname);
                     32: clearstatcache();
                     33: sleep(2);
                     34: 
                     35: // creating file
                     36: $filename = "$dirname/lstat_stat_basic.tmp";
                     37: $file_handle = fopen($filename, "w");
                     38: fclose($file_handle);
                     39: // stat of the file created
                     40: $file_stat = stat($filename);
                     41: sleep(2);
                     42: 
                     43: // now new stat of the dir after file is created
                     44: $new_dir_stat = stat($dirname);
                     45: clearstatcache();
                     46: 
                     47: // create soft link and record stat
                     48: $sym_linkname = "$file_path/lstat_stat_basic_link.tmp";
                     49: symlink($filename, $sym_linkname);
                     50: // stat of the link created
                     51: $link_stat = lstat($sym_linkname);
                     52: sleep(2);
                     53: // new stat of the file, after a softlink to this file is created
                     54: $new_file_stat = stat($filename);
                     55: clearstatcache();
                     56: 
                     57: // stat contains 13 different values stored twice, can be accessed using 
                     58: // numeric and named keys, compare them to see they are same  
                     59: echo "*** Testing stat() and lstat() : validating the values stored in stat ***\n";
                     60: // Initial stat values
                     61: var_dump( compare_self_stat($file_stat) ); //expect true
                     62: var_dump( compare_self_stat($dir_stat) );  //expect true
                     63: var_dump( compare_self_stat($link_stat) ); // expect true
                     64: 
                     65: // New stat values taken after creation of file & link
                     66: var_dump( compare_self_stat($new_file_stat) ); //expect true
                     67: var_dump( compare_self_stat($new_dir_stat) );  // expect true
                     68: 
                     69: // compare the two stat values, initial stat and stat recorded after 
                     70: // creating files and link, also dump the value of stats
                     71: echo "*** Testing stat() and lstat() : comparing stats (recorded before and after file/link creation) ***\n";
                     72: echo "-- comparing difference in dir stats before and after creating file in it --\n";
                     73: $affected_elements = array( 9, 10, 'mtime', 'ctime' );
                     74: var_dump( compare_stats($dir_stat, $new_dir_stat, $affected_elements, '!=', true) ); // expect true
                     75: 
                     76: echo "-- comparing difference in file stats before and after creating link to it --\n";
                     77: var_dump( compare_stats($file_stat, $new_file_stat, $all_stat_keys, "==", true) ); // expect true
                     78: 
                     79: echo "Done\n";
                     80: ?>
                     81: --CLEAN--
                     82: <?php
                     83: $file_path = dirname(__FILE__);
                     84: unlink("$file_path/lstat_stat_basic_link.tmp");
                     85: unlink("$file_path/lstat_stat_basic/lstat_stat_basic.tmp");
                     86: rmdir("$file_path/lstat_stat_basic");
                     87: ?>
                     88: --EXPECTF--
                     89: *** Testing lstat() & stat() : basic functionality ***
                     90: *** Testing stat() and lstat() : validating the values stored in stat ***
                     91: bool(true)
                     92: bool(true)
                     93: bool(true)
                     94: bool(true)
                     95: bool(true)
                     96: *** Testing stat() and lstat() : comparing stats (recorded before and after file/link creation) ***
                     97: -- comparing difference in dir stats before and after creating file in it --
                     98: array(26) {
                     99:   [0]=>
                    100:   int(%i)
                    101:   [1]=>
                    102:   int(%i)
                    103:   [2]=>
                    104:   int(%i)
                    105:   [3]=>
                    106:   int(%i)
                    107:   [4]=>
                    108:   int(%i)
                    109:   [5]=>
                    110:   int(%i)
                    111:   [6]=>
                    112:   int(%i)
                    113:   [7]=>
                    114:   int(%i)
                    115:   [8]=>
                    116:   int(%i)
                    117:   [9]=>
                    118:   int(%i)
                    119:   [10]=>
                    120:   int(%i)
                    121:   [11]=>
                    122:   int(%i)
                    123:   [12]=>
                    124:   int(%i)
                    125:   ["dev"]=>
                    126:   int(%i)
                    127:   ["ino"]=>
                    128:   int(%i)
                    129:   ["mode"]=>
                    130:   int(%i)
                    131:   ["nlink"]=>
                    132:   int(%i)
                    133:   ["uid"]=>
                    134:   int(%i)
                    135:   ["gid"]=>
                    136:   int(%i)
                    137:   ["rdev"]=>
                    138:   int(%i)
                    139:   ["size"]=>
                    140:   int(%i)
                    141:   ["atime"]=>
                    142:   int(%i)
                    143:   ["mtime"]=>
                    144:   int(%i)
                    145:   ["ctime"]=>
                    146:   int(%i)
                    147:   ["blksize"]=>
                    148:   int(%i)
                    149:   ["blocks"]=>
                    150:   int(%i)
                    151: }
                    152: array(26) {
                    153:   [0]=>
                    154:   int(%i)
                    155:   [1]=>
                    156:   int(%i)
                    157:   [2]=>
                    158:   int(%i)
                    159:   [3]=>
                    160:   int(%i)
                    161:   [4]=>
                    162:   int(%i)
                    163:   [5]=>
                    164:   int(%i)
                    165:   [6]=>
                    166:   int(%i)
                    167:   [7]=>
                    168:   int(%i)
                    169:   [8]=>
                    170:   int(%i)
                    171:   [9]=>
                    172:   int(%i)
                    173:   [10]=>
                    174:   int(%i)
                    175:   [11]=>
                    176:   int(%i)
                    177:   [12]=>
                    178:   int(%i)
                    179:   ["dev"]=>
                    180:   int(%i)
                    181:   ["ino"]=>
                    182:   int(%i)
                    183:   ["mode"]=>
                    184:   int(%i)
                    185:   ["nlink"]=>
                    186:   int(%i)
                    187:   ["uid"]=>
                    188:   int(%i)
                    189:   ["gid"]=>
                    190:   int(%i)
                    191:   ["rdev"]=>
                    192:   int(%i)
                    193:   ["size"]=>
                    194:   int(%i)
                    195:   ["atime"]=>
                    196:   int(%i)
                    197:   ["mtime"]=>
                    198:   int(%i)
                    199:   ["ctime"]=>
                    200:   int(%i)
                    201:   ["blksize"]=>
                    202:   int(%i)
                    203:   ["blocks"]=>
                    204:   int(%i)
                    205: }
                    206: bool(true)
                    207: -- comparing difference in file stats before and after creating link to it --
                    208: array(26) {
                    209:   [0]=>
                    210:   int(%i)
                    211:   [1]=>
                    212:   int(%i)
                    213:   [2]=>
                    214:   int(%i)
                    215:   [3]=>
                    216:   int(%i)
                    217:   [4]=>
                    218:   int(%i)
                    219:   [5]=>
                    220:   int(%i)
                    221:   [6]=>
                    222:   int(%i)
                    223:   [7]=>
                    224:   int(%i)
                    225:   [8]=>
                    226:   int(%i)
                    227:   [9]=>
                    228:   int(%i)
                    229:   [10]=>
                    230:   int(%i)
                    231:   [11]=>
                    232:   int(%i)
                    233:   [12]=>
                    234:   int(%i)
                    235:   ["dev"]=>
                    236:   int(%i)
                    237:   ["ino"]=>
                    238:   int(%i)
                    239:   ["mode"]=>
                    240:   int(%i)
                    241:   ["nlink"]=>
                    242:   int(%i)
                    243:   ["uid"]=>
                    244:   int(%i)
                    245:   ["gid"]=>
                    246:   int(%i)
                    247:   ["rdev"]=>
                    248:   int(%i)
                    249:   ["size"]=>
                    250:   int(%i)
                    251:   ["atime"]=>
                    252:   int(%i)
                    253:   ["mtime"]=>
                    254:   int(%i)
                    255:   ["ctime"]=>
                    256:   int(%i)
                    257:   ["blksize"]=>
                    258:   int(%i)
                    259:   ["blocks"]=>
                    260:   int(%i)
                    261: }
                    262: array(26) {
                    263:   [0]=>
                    264:   int(%i)
                    265:   [1]=>
                    266:   int(%i)
                    267:   [2]=>
                    268:   int(%i)
                    269:   [3]=>
                    270:   int(%i)
                    271:   [4]=>
                    272:   int(%i)
                    273:   [5]=>
                    274:   int(%i)
                    275:   [6]=>
                    276:   int(%i)
                    277:   [7]=>
                    278:   int(%i)
                    279:   [8]=>
                    280:   int(%i)
                    281:   [9]=>
                    282:   int(%i)
                    283:   [10]=>
                    284:   int(%i)
                    285:   [11]=>
                    286:   int(%i)
                    287:   [12]=>
                    288:   int(%i)
                    289:   ["dev"]=>
                    290:   int(%i)
                    291:   ["ino"]=>
                    292:   int(%i)
                    293:   ["mode"]=>
                    294:   int(%i)
                    295:   ["nlink"]=>
                    296:   int(%i)
                    297:   ["uid"]=>
                    298:   int(%i)
                    299:   ["gid"]=>
                    300:   int(%i)
                    301:   ["rdev"]=>
                    302:   int(%i)
                    303:   ["size"]=>
                    304:   int(%i)
                    305:   ["atime"]=>
                    306:   int(%i)
                    307:   ["mtime"]=>
                    308:   int(%i)
                    309:   ["ctime"]=>
                    310:   int(%i)
                    311:   ["blksize"]=>
                    312:   int(%i)
                    313:   ["blocks"]=>
                    314:   int(%i)
                    315: }
                    316: bool(true)
                    317: Done

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>