Annotation of embedaddon/php/ext/standard/tests/dir/dir_variation1.phpt, revision 1.1.1.1

1.1       misho       1: --TEST--
                      2: Test dir() function : usage variations - unexpected value for 'dir' argument
                      3: --FILE--
                      4: <?php
                      5: /* 
                      6:  * Prototype  : object dir(string $directory[, resource $context])
                      7:  * Description: Directory class with properties, handle and class and methods read, rewind and close
                      8:  * Source code: ext/standard/dir.c
                      9:  */
                     10: 
                     11: /*
                     12:  * Passing non string values to 'directory' argument of dir() and see
                     13:  * that the function outputs proper warning messages wherever expected.
                     14:  */
                     15: 
                     16: echo "*** Testing dir() : unexpected values for \$directory argument ***\n";
                     17: 
                     18: // get an unset variable
                     19: $unset_var = 10;
                     20: unset($unset_var);
                     21: 
                     22: class A
                     23: {
                     24:   public $var;
                     25:   public function init() {
                     26:     $this->var = 10;
                     27:   }
                     28: }
                     29: 
                     30: // get a resource variable
                     31: $fp = fopen(__FILE__, "r"); // get a file handle 
                     32: $dfp = opendir( dirname(__FILE__) ); // get a dir handle
                     33: 
                     34: // unexpected values to be passed to $directory argument
                     35: $unexpected_values = array (
                     36: 
                     37:        // array data
                     38: /*1*/  array(),
                     39:        array(0),
                     40:        array(1),
                     41:        array(1, 2),
                     42:        array('color' => 'red', 'item' => 'pen'),
                     43: 
                     44:        // null data
                     45: /*6*/  NULL,
                     46:        null,
                     47: 
                     48:        // boolean data
                     49: /*8*/  true,
                     50:        false,
                     51:        TRUE,
                     52:        FALSE,
                     53: 
                     54:        // empty data
                     55: /*12*/ "",
                     56:        '',
                     57: 
                     58:        // undefined data
                     59: /*14*/ @$undefined_var,
                     60: 
                     61:        // unset data
                     62: /*15*/ @$unset_var,
                     63: 
                     64:        // resource variable(dir and file handle)
                     65: /*16*/ $fp,
                     66:        $dfp,
                     67: 
                     68:        // object data
                     69: /*18*/ new A()
                     70: );
                     71: 
                     72: // loop through various elements of $unexpected_values to check the behavior of dir()
                     73: $iterator = 1;
                     74: foreach( $unexpected_values as $unexpected_value ) {
                     75:   echo "\n-- Iteration $iterator --\n";
                     76:   var_dump( dir($unexpected_value) );
                     77:   $iterator++;
                     78: }
                     79: 
                     80: fclose($fp);
                     81: closedir($dfp);
                     82: echo "Done";
                     83: ?>
                     84: --EXPECTF--
                     85: *** Testing dir() : unexpected values for $directory argument ***
                     86: 
                     87: -- Iteration 1 --
                     88: 
                     89: Warning: dir() expects parameter 1 to be string, array given in %s on line %d
                     90: NULL
                     91: 
                     92: -- Iteration 2 --
                     93: 
                     94: Warning: dir() expects parameter 1 to be string, array given in %s on line %d
                     95: NULL
                     96: 
                     97: -- Iteration 3 --
                     98: 
                     99: Warning: dir() expects parameter 1 to be string, array given in %s on line %d
                    100: NULL
                    101: 
                    102: -- Iteration 4 --
                    103: 
                    104: Warning: dir() expects parameter 1 to be string, array given in %s on line %d
                    105: NULL
                    106: 
                    107: -- Iteration 5 --
                    108: 
                    109: Warning: dir() expects parameter 1 to be string, array given in %s on line %d
                    110: NULL
                    111: 
                    112: -- Iteration 6 --
                    113: bool(false)
                    114: 
                    115: -- Iteration 7 --
                    116: bool(false)
                    117: 
                    118: -- Iteration 8 --
                    119: 
                    120: Warning: dir(1): failed to open dir: %s in %s on line %d
                    121: bool(false)
                    122: 
                    123: -- Iteration 9 --
                    124: bool(false)
                    125: 
                    126: -- Iteration 10 --
                    127: 
                    128: Warning: dir(1): failed to open dir: %s in %s on line %d
                    129: bool(false)
                    130: 
                    131: -- Iteration 11 --
                    132: bool(false)
                    133: 
                    134: -- Iteration 12 --
                    135: bool(false)
                    136: 
                    137: -- Iteration 13 --
                    138: bool(false)
                    139: 
                    140: -- Iteration 14 --
                    141: bool(false)
                    142: 
                    143: -- Iteration 15 --
                    144: bool(false)
                    145: 
                    146: -- Iteration 16 --
                    147: 
                    148: Warning: dir() expects parameter 1 to be string, resource given in %s on line %d
                    149: NULL
                    150: 
                    151: -- Iteration 17 --
                    152: 
                    153: Warning: dir() expects parameter 1 to be string, resource given in %s on line %d
                    154: NULL
                    155: 
                    156: -- Iteration 18 --
                    157: 
                    158: Warning: dir() expects parameter 1 to be string, object given in %s on line %d
                    159: NULL
                    160: Done

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