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

1.1       misho       1: --TEST--
                      2: Test fopen() function : usage variation different datatypes for use_include_path
                      3: --CREDITS--
                      4: Dave Kelsey <d_kelsey@uk.ibm.com>
                      5: --FILE--
                      6: <?php
                      7: /* Prototype  : resource fopen(string filename, string mode [, bool use_include_path [, resource context]])
                      8:  * Description: Open a file or a URL and return a file pointer 
                      9:  * Source code: ext/standard/file.c
                     10:  * Alias to functions: 
                     11:  */
                     12: 
                     13: echo "*** Testing fopen() : usage variation ***\n";
                     14: 
                     15: // Define error handler
                     16: function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) {
                     17:        if (error_reporting() != 0) {
                     18:                // report non-silenced errors
                     19:                echo "Error: $err_no - $err_msg, $filename($linenum)\n";
                     20:        }
                     21: }
                     22: set_error_handler('test_error_handler');
                     23: 
                     24: // Initialise function arguments not being substituted (if any)
                     25: $filename = __FILE__;
                     26: $mode = 'r';
                     27: 
                     28: 
                     29: //get an unset variable
                     30: $unset_var = 10;
                     31: unset ($unset_var);
                     32: 
                     33: // define some classes
                     34: class classWithToString
                     35: {
                     36:        public function __toString() {
                     37:                return "Class A object";
                     38:        }
                     39: }
                     40: 
                     41: class classWithoutToString
                     42: {
                     43: }
                     44: 
                     45: // heredoc string
                     46: $heredoc = <<<EOT
                     47: hello world
                     48: EOT;
                     49: 
                     50: // add arrays
                     51: $index_array = array (1, 2, 3);
                     52: $assoc_array = array ('one' => 1, 'two' => 2);
                     53: 
                     54: //array of values to iterate over
                     55: $inputs = array(
                     56: 
                     57:       // int data
                     58:       'int 0' => 0,
                     59:       'int 1' => 1,
                     60:       'int 12345' => 12345,
                     61:       'int -12345' => -2345,
                     62: 
                     63:       // float data
                     64:       'float 10.5' => 10.5,
                     65:       'float -10.5' => -10.5,
                     66:       'float 12.3456789000e10' => 12.3456789000e10,
                     67:       'float -12.3456789000e10' => -12.3456789000e10,
                     68:       'float .5' => .5,
                     69: 
                     70:       // array data
                     71:       'empty array' => array(),
                     72:       'int indexed array' => $index_array,
                     73:       'associative array' => $assoc_array,
                     74:       'nested arrays' => array('foo', $index_array, $assoc_array),
                     75: 
                     76:       // null data
                     77:       'uppercase NULL' => NULL,
                     78:       'lowercase null' => null,
                     79: 
                     80:       // boolean data
                     81:       'lowercase true' => true,
                     82:       'lowercase false' =>false,
                     83:       'uppercase TRUE' =>TRUE,
                     84:       'uppercase FALSE' =>FALSE,
                     85: 
                     86:       // empty data
                     87:       'empty string DQ' => "",
                     88:       'empty string SQ' => '',
                     89: 
                     90:       // string data
                     91:       'string DQ' => "string",
                     92:       'string SQ' => 'string',
                     93:       'mixed case string' => "sTrInG",
                     94:       'heredoc' => $heredoc,
                     95: 
                     96:       // object data
                     97:       'instance of classWithToString' => new classWithToString(),
                     98:       'instance of classWithoutToString' => new classWithoutToString(),
                     99: 
                    100:       // undefined data
                    101:       'undefined var' => @$undefined_var,
                    102: 
                    103:       // unset data
                    104:       'unset var' => @$unset_var,
                    105: );
                    106: 
                    107: // loop through each element of the array for use_include_path
                    108: 
                    109: foreach($inputs as $key =>$value) {
                    110:       echo "\n--$key--\n";
                    111:       $h = fopen($filename, $mode, $value);
                    112:       if ($h !== false) {
                    113:          echo "ok\n";
                    114:          fclose($h);
                    115:       }
                    116:       else {
                    117:          var_dump($h);
                    118:       }
                    119: };
                    120: 
                    121: ?>
                    122: ===DONE===
                    123: --EXPECTF--
                    124: *** Testing fopen() : usage variation ***
                    125: 
                    126: --int 0--
                    127: ok
                    128: 
                    129: --int 1--
                    130: ok
                    131: 
                    132: --int 12345--
                    133: ok
                    134: 
                    135: --int -12345--
                    136: ok
                    137: 
                    138: --float 10.5--
                    139: ok
                    140: 
                    141: --float -10.5--
                    142: ok
                    143: 
                    144: --float 12.3456789000e10--
                    145: ok
                    146: 
                    147: --float -12.3456789000e10--
                    148: ok
                    149: 
                    150: --float .5--
                    151: ok
                    152: 
                    153: --empty array--
                    154: Error: 2 - fopen() expects parameter 3 to be boolean, array given, %s(%d)
                    155: bool(false)
                    156: 
                    157: --int indexed array--
                    158: Error: 2 - fopen() expects parameter 3 to be boolean, array given, %s(%d)
                    159: bool(false)
                    160: 
                    161: --associative array--
                    162: Error: 2 - fopen() expects parameter 3 to be boolean, array given, %s(%d)
                    163: bool(false)
                    164: 
                    165: --nested arrays--
                    166: Error: 2 - fopen() expects parameter 3 to be boolean, array given, %s(%d)
                    167: bool(false)
                    168: 
                    169: --uppercase NULL--
                    170: ok
                    171: 
                    172: --lowercase null--
                    173: ok
                    174: 
                    175: --lowercase true--
                    176: ok
                    177: 
                    178: --lowercase false--
                    179: ok
                    180: 
                    181: --uppercase TRUE--
                    182: ok
                    183: 
                    184: --uppercase FALSE--
                    185: ok
                    186: 
                    187: --empty string DQ--
                    188: ok
                    189: 
                    190: --empty string SQ--
                    191: ok
                    192: 
                    193: --string DQ--
                    194: ok
                    195: 
                    196: --string SQ--
                    197: ok
                    198: 
                    199: --mixed case string--
                    200: ok
                    201: 
                    202: --heredoc--
                    203: ok
                    204: 
                    205: --instance of classWithToString--
                    206: Error: 2 - fopen() expects parameter 3 to be boolean, object given, %s(%d)
                    207: bool(false)
                    208: 
                    209: --instance of classWithoutToString--
                    210: Error: 2 - fopen() expects parameter 3 to be boolean, object given, %s(%d)
                    211: bool(false)
                    212: 
                    213: --undefined var--
                    214: ok
                    215: 
                    216: --unset var--
                    217: ok
                    218: ===DONE===

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