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