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

1.1       misho       1: --TEST--
                      2: Test fwrite() function : error conditions
                      3: --FILE--
                      4: <?php
                      5: /*
                      6:  Prototype: int fwrite ( resource $handle,string string, [, int $length] );
                      7:  Description: fwrite() writes the contents of string to the file stream pointed to by handle.
                      8:               If the length arquement is given,writing will stop after length bytes have been
                      9:               written or the end of string reached, whichever comes first.
                     10:               fwrite() returns the number of bytes written or FALSE on error
                     11: */
                     12: 
                     13: // include the file.inc for Function: function delete_file($filename)
                     14: include ("file.inc");
                     15: 
                     16: echo "*** Testing fwrite() : error conditions ***\n";
                     17: 
                     18: $filename = dirname(__FILE__)."/fwrite_error.tmp";
                     19: 
                     20: echo "-- Testing fwrite() with less than expected number of arguments --\n";
                     21: // zero argument
                     22: var_dump( fwrite() ); 
                     23: // less than expected, 1 arg
                     24: $file_handle  = fopen ( $filename, "w");
                     25: var_dump( fwrite($file_handle) );
                     26: 
                     27: // more than expected no. of args
                     28: echo "-- Testing fwrite() with more than expected number of arguments --\n";
                     29: $data = "data";
                     30: var_dump( fwrite($file_handle, $data, strlen($data), 10) );
                     31: 
                     32: // invalid length argument
                     33: echo "-- Testing fwrite() with invalid length arguments --\n";
                     34: $len = 0;
                     35: var_dump( fwrite($file_handle, $data, $len) );
                     36: $len = -10;
                     37: var_dump( fwrite($file_handle, $data, $len) );
                     38: 
                     39: // test invalid arguments : non-resources
                     40: echo "-- Testing fwrite() with invalid arguments --\n";
                     41: $invalid_args = array (
                     42:   "string",
                     43:   10,
                     44:   10.5,
                     45:   true,
                     46:   array(1,2,3),
                     47:   new stdclass,
                     48: );
                     49: /* loop to test fwrite() with different invalid type of args */
                     50: for($loop_counter = 1; $loop_counter <= count($invalid_args); $loop_counter++) {
                     51:   echo "-- Iteration $loop_counter --\n";
                     52:   var_dump( fwrite($invalid_args[$loop_counter - 1], 10) );
                     53: }
                     54: 
                     55: // fwrite() on a file handle which is already closed 
                     56: echo "-- Testing fwrite() with closed/unset file handle --\n";
                     57: fclose($file_handle);
                     58: var_dump(fwrite($file_handle,"data"));
                     59: 
                     60: // fwrite on a file handle which is unset 
                     61: $fp = fopen($filename, "w");
                     62: unset($fp); //unset file handle 
                     63: var_dump( fwrite(@$fp,"data"));
                     64: 
                     65: echo "Done\n";
                     66: ?>
                     67: --CLEAN--
                     68: <?php
                     69: $filename = dirname(__FILE__)."/fwrite_error.tmp";
                     70: unlink( $filename );
                     71: ?>
                     72: --EXPECTF--
                     73: *** Testing fwrite() : error conditions ***
                     74: -- Testing fwrite() with less than expected number of arguments --
                     75: 
                     76: Warning: fwrite() expects at least 2 parameters, 0 given in %s on line %d
                     77: bool(false)
                     78: 
                     79: Warning: fwrite() expects at least 2 parameters, 1 given in %s on line %d
                     80: bool(false)
                     81: -- Testing fwrite() with more than expected number of arguments --
                     82: 
                     83: Warning: fwrite() expects at most 3 parameters, 4 given in %s on line %d
                     84: bool(false)
                     85: -- Testing fwrite() with invalid length arguments --
                     86: int(0)
                     87: int(0)
                     88: -- Testing fwrite() with invalid arguments --
                     89: -- Iteration 1 --
                     90: 
                     91: Warning: fwrite() expects parameter 1 to be resource, string given in %s on line %d
                     92: bool(false)
                     93: -- Iteration 2 --
                     94: 
                     95: Warning: fwrite() expects parameter 1 to be resource, integer given in %s on line %d
                     96: bool(false)
                     97: -- Iteration 3 --
                     98: 
                     99: Warning: fwrite() expects parameter 1 to be resource, double given in %s on line %d
                    100: bool(false)
                    101: -- Iteration 4 --
                    102: 
                    103: Warning: fwrite() expects parameter 1 to be resource, boolean given in %s on line %d
                    104: bool(false)
                    105: -- Iteration 5 --
                    106: 
                    107: Warning: fwrite() expects parameter 1 to be resource, array given in %s on line %d
                    108: bool(false)
                    109: -- Iteration 6 --
                    110: 
                    111: Warning: fwrite() expects parameter 1 to be resource, object given in %s on line %d
                    112: bool(false)
                    113: -- Testing fwrite() with closed/unset file handle --
                    114: 
                    115: Warning: fwrite(): %d is not a valid stream resource in %s on line %d
                    116: bool(false)
                    117: 
                    118: Warning: fwrite() expects parameter 1 to be resource, null given in %s on line %d
                    119: bool(false)
                    120: Done
                    121: 

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