1--TEST-- 2Test fgetcsv() function : error conditions 3--FILE-- 4<?php 5/* 6 Prototype: array fgetcsv ( resource $handle [, int $length [, string $delimiter [, string $enclosure [, string $escape]]]] ); 7 Description: Gets line from file pointer and parse for CSV fields 8*/ 9 10echo "*** Testing error conditions ***\n"; 11// zero argument 12echo "-- Testing fgetcsv() with zero argument --\n"; 13var_dump( fgetcsv() ); 14 15// more than expected no. of args 16echo "-- Testing fgetcsv() with more than expected number of arguments --\n"; 17$fp = fopen(__FILE__, "r"); 18$len = 1024; 19$delim = ";"; 20$enclosure ="\""; 21$escape = '"'; 22var_dump( fgetcsv($fp, $len, $delim, $enclosure, $escape, $fp) ); 23fclose($fp); 24 25// test invalid arguments : non-resources 26echo "-- Testing fgetcsv() 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 fgetcsv() with different invalid type of args */ 36for($loop_counter = 1; $loop_counter <= count($invalid_args); $loop_counter++) { 37 echo "-- Iteration $loop_counter --\n"; 38 var_dump( fgetcsv($invalid_args[$loop_counter - 1]) ); // with default args 39 var_dump( fgetcsv($invalid_args[$loop_counter - 1], $len, $delim, $enclosure, $escape) ); // all args specified 40} 41 42echo "Done\n"; 43--EXPECTF-- 44*** Testing error conditions *** 45-- Testing fgetcsv() with zero argument -- 46 47Warning: fgetcsv() expects at least 1 parameter, 0 given in %s on line %d 48NULL 49-- Testing fgetcsv() with more than expected number of arguments -- 50 51Warning: fgetcsv() expects at most 5 parameters, 6 given in %s on line %d 52NULL 53-- Testing fgetcsv() with invalid arguments -- 54-- Iteration 1 -- 55 56Warning: fgetcsv() expects parameter 1 to be resource, string given in %s on line %d 57NULL 58 59Warning: fgetcsv() expects parameter 1 to be resource, string given in %s on line %d 60NULL 61-- Iteration 2 -- 62 63Warning: fgetcsv() expects parameter 1 to be resource, int given in %s on line %d 64NULL 65 66Warning: fgetcsv() expects parameter 1 to be resource, int given in %s on line %d 67NULL 68-- Iteration 3 -- 69 70Warning: fgetcsv() expects parameter 1 to be resource, float given in %s on line %d 71NULL 72 73Warning: fgetcsv() expects parameter 1 to be resource, float given in %s on line %d 74NULL 75-- Iteration 4 -- 76 77Warning: fgetcsv() expects parameter 1 to be resource, bool given in %s on line %d 78NULL 79 80Warning: fgetcsv() expects parameter 1 to be resource, bool given in %s on line %d 81NULL 82-- Iteration 5 -- 83 84Warning: fgetcsv() expects parameter 1 to be resource, array given in %s on line %d 85NULL 86 87Warning: fgetcsv() expects parameter 1 to be resource, array given in %s on line %d 88NULL 89-- Iteration 6 -- 90 91Warning: fgetcsv() expects parameter 1 to be resource, object given in %s on line %d 92NULL 93 94Warning: fgetcsv() expects parameter 1 to be resource, object given in %s on line %d 95NULL 96Done 97