Annotation of embedaddon/php/ext/standard/tests/file/fputcsv_error.phpt, revision 1.1
1.1 ! misho 1: --TEST--
! 2: Test fputcsv() function : error conditions
! 3: --FILE--
! 4: <?php
! 5: /*
! 6: Prototype: int fputcsv ( resource $handle [, array $fields [, string $delimiter [, string $enclosure]]] );
! 7: Description:fputcsv() formats a line (passed as a fields array) as CSV and write it to the specified file
! 8: handle. Returns the length of the written string, or FALSE on failure.
! 9: */
! 10:
! 11: echo "*** Testing error conditions ***\n";
! 12: // zero argument
! 13: echo "-- Testing fputcsv() with zero argument --\n";
! 14: var_dump( fputcsv() );
! 15:
! 16: // more than expected no. of args
! 17: echo "-- Testing fputcsv() with more than expected number of arguments --\n";
! 18: $fp = fopen(__FILE__, "r");
! 19: $fields = array("fld1", "fld2");
! 20: $delim = ";";
! 21: $enclosure ="\"";
! 22: var_dump( fputcsv($fp, $fields, $delim, $enclosure, $fp) );
! 23: fclose($fp);
! 24:
! 25: // test invalid arguments : non-resources
! 26: echo "-- Testing fputcsv() with invalid arguments --\n";
! 27: $invalid_args = array (
! 28: "string",
! 29: 10,
! 30: 10.5,
! 31: true,
! 32: array(1,2,3),
! 33: new stdclass,
! 34: );
! 35: /* loop to test fputcsv() with different invalid type of args */
! 36: for($loop_counter = 1; $loop_counter <= count($invalid_args); $loop_counter++) {
! 37: echo "-- Iteration $loop_counter --\n";
! 38: var_dump( fputcsv($invalid_args[$loop_counter - 1]) ); // with default args
! 39: var_dump( fputcsv($invalid_args[$loop_counter - 1], $fields, $delim, $enclosure) ); // all args specified
! 40: }
! 41:
! 42: echo "Done\n";
! 43: --EXPECTF--
! 44: *** Testing error conditions ***
! 45: -- Testing fputcsv() with zero argument --
! 46:
! 47: Warning: fputcsv() expects at least 2 parameters, 0 given in %s on line %d
! 48: NULL
! 49: -- Testing fputcsv() with more than expected number of arguments --
! 50:
! 51: Warning: fputcsv() expects at most 4 parameters, 5 given in %s on line %d
! 52: NULL
! 53: -- Testing fputcsv() with invalid arguments --
! 54: -- Iteration 1 --
! 55:
! 56: Warning: fputcsv() expects at least 2 parameters, 1 given in %s on line %d
! 57: NULL
! 58:
! 59: Warning: fputcsv() expects parameter 1 to be resource, string given in %s on line %d
! 60: NULL
! 61: -- Iteration 2 --
! 62:
! 63: Warning: fputcsv() expects at least 2 parameters, 1 given in %s on line %d
! 64: NULL
! 65:
! 66: Warning: fputcsv() expects parameter 1 to be resource, integer given in %s on line %d
! 67: NULL
! 68: -- Iteration 3 --
! 69:
! 70: Warning: fputcsv() expects at least 2 parameters, 1 given in %s on line %d
! 71: NULL
! 72:
! 73: Warning: fputcsv() expects parameter 1 to be resource, double given in %s on line %d
! 74: NULL
! 75: -- Iteration 4 --
! 76:
! 77: Warning: fputcsv() expects at least 2 parameters, 1 given in %s on line %d
! 78: NULL
! 79:
! 80: Warning: fputcsv() expects parameter 1 to be resource, boolean given in %s on line %d
! 81: NULL
! 82: -- Iteration 5 --
! 83:
! 84: Warning: fputcsv() expects at least 2 parameters, 1 given in %s on line %d
! 85: NULL
! 86:
! 87: Warning: fputcsv() expects parameter 1 to be resource, array given in %s on line %d
! 88: NULL
! 89: -- Iteration 6 --
! 90:
! 91: Warning: fputcsv() expects at least 2 parameters, 1 given in %s on line %d
! 92: NULL
! 93:
! 94: Warning: fputcsv() expects parameter 1 to be resource, object given in %s on line %d
! 95: NULL
! 96: Done
! 97:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>