Annotation of embedaddon/php/ext/standard/tests/file/readfile_variation5.phpt, revision 1.1

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

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