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