Annotation of embedaddon/php/ext/standard/tests/file/007_error.phpt, revision 1.1
1.1 ! misho 1: --TEST--
! 2: Test fopen, fclose() & feof() functions: error conditions
! 3: --CREDITS--
! 4: Dave Kelsey <d_kelsey@uk.ibm.com>
! 5: --FILE--
! 6: <?php
! 7: /*
! 8: Prototype: resource fopen(string $filename, string $mode
! 9: [, bool $use_include_path [, resource $context]] );
! 10: Description: Opens file or URL.
! 11:
! 12: Prototype: bool fclose ( resource $handle );
! 13: Description: Closes an open file pointer
! 14:
! 15: Prototype: bool feof ( resource $handle )
! 16: Description: Returns TRUE if the file pointer is at EOF or an error occurs
! 17: (including socket timeout); otherwise returns FALSE.
! 18: */
! 19:
! 20: echo "*** Testing error conditions for fopen(), fclsoe() & feof() ***\n";
! 21: /* Arguments less than minimum no.of args */
! 22:
! 23: // fopen ()
! 24: var_dump(fopen(__FILE__)); // one valid argument
! 25: var_dump(fopen()); // zero argument
! 26:
! 27: // fclose()
! 28: $fp = fopen(__FILE__, "r");
! 29: fclose($fp);
! 30: var_dump( fclose($fp) ); // closed handle
! 31: var_dump( fclose(__FILE__) ); // invalid handle
! 32: var_dump( fclose() ); // zero argument
! 33:
! 34: //feof()
! 35: var_dump( feof($fp) ); // closed handle
! 36: var_dump( feof(__FILE__) ); // invalid handle
! 37: var_dump( feof() ); //zero argument
! 38:
! 39: /* Arguments greater than maximum no.of ags */
! 40: var_dump(fopen(__FILE__, "r", TRUE, "www.example.com", 100));
! 41:
! 42: $fp = fopen(__FILE__, "r");
! 43: var_dump( fclose($fp, "handle") );
! 44:
! 45: var_dump( feof($fp, "handle"));
! 46: fclose($fp);
! 47:
! 48: /* test invalid arguments : non-resources */
! 49: echo "-- Testing fopen(), fclose() & feof() with invalid arguments --\n";
! 50: $invalid_args = array (
! 51: "string",
! 52: 10,
! 53: 10.5,
! 54: true,
! 55: array(1,2,3),
! 56: new stdclass,
! 57: NULL,
! 58: ""
! 59: );
! 60:
! 61: /* loop to test fclose with different invalid type of args */
! 62: for($loop_counter = 1; $loop_counter <= count($invalid_args); $loop_counter++) {
! 63: echo "-- Iteration $loop_counter --\n";
! 64: var_dump( fopen($invalid_args[$loop_counter - 1], "r") );
! 65: var_dump( fclose($invalid_args[$loop_counter - 1]) );
! 66: var_dump( feof($invalid_args[$loop_counter - 1]) );
! 67: }
! 68:
! 69: ?>
! 70: --EXPECTF--
! 71: *** Testing error conditions for fopen(), fclsoe() & feof() ***
! 72:
! 73: Warning: fopen() expects at least 2 parameters, 1 given in %s on line %d
! 74: bool(false)
! 75:
! 76: Warning: fopen() expects at least 2 parameters, 0 given in %s on line %d
! 77: bool(false)
! 78:
! 79: Warning: fclose(): 5 is not a valid stream resource in %s on line %d
! 80: bool(false)
! 81:
! 82: Warning: fclose() expects parameter 1 to be resource, string given in %s on line %d
! 83: bool(false)
! 84:
! 85: Warning: fclose() expects exactly 1 parameter, 0 given in %s on line %d
! 86: bool(false)
! 87:
! 88: Warning: feof(): 5 is not a valid stream resource in %s on line %d
! 89: bool(false)
! 90:
! 91: Warning: feof() expects parameter 1 to be resource, string given in %s on line %d
! 92: bool(false)
! 93:
! 94: Warning: feof() expects exactly 1 parameter, 0 given in %s on line %d
! 95: bool(false)
! 96:
! 97: Warning: fopen() expects at most 4 parameters, 5 given in %s on line %d
! 98: bool(false)
! 99:
! 100: Warning: fclose() expects exactly 1 parameter, 2 given in %s on line %d
! 101: bool(false)
! 102:
! 103: Warning: feof() expects exactly 1 parameter, 2 given in %s on line %d
! 104: bool(false)
! 105: -- Testing fopen(), fclose() & feof() with invalid arguments --
! 106: -- Iteration 1 --
! 107:
! 108: Warning: fopen(string): failed to open stream: No such file or directory in %s on line %d
! 109: bool(false)
! 110:
! 111: Warning: fclose() expects parameter 1 to be resource, string given in %s on line %d
! 112: bool(false)
! 113:
! 114: Warning: feof() expects parameter 1 to be resource, string given in %s on line %d
! 115: bool(false)
! 116: -- Iteration 2 --
! 117:
! 118: Warning: fopen(10): failed to open stream: No such file or directory in %s on line %d
! 119: bool(false)
! 120:
! 121: Warning: fclose() expects parameter 1 to be resource, integer given in %s on line %d
! 122: bool(false)
! 123:
! 124: Warning: feof() expects parameter 1 to be resource, integer given in %s on line %d
! 125: bool(false)
! 126: -- Iteration 3 --
! 127:
! 128: Warning: fopen(10.5): failed to open stream: No such file or directory in %s on line %d
! 129: bool(false)
! 130:
! 131: Warning: fclose() expects parameter 1 to be resource, double given in %s on line %d
! 132: bool(false)
! 133:
! 134: Warning: feof() expects parameter 1 to be resource, double given in %s on line %d
! 135: bool(false)
! 136: -- Iteration 4 --
! 137:
! 138: Warning: fopen(1): failed to open stream: No such file or directory in %s on line %d
! 139: bool(false)
! 140:
! 141: Warning: fclose() expects parameter 1 to be resource, boolean given in %s on line %d
! 142: bool(false)
! 143:
! 144: Warning: feof() expects parameter 1 to be resource, boolean given in %s on line %d
! 145: bool(false)
! 146: -- Iteration 5 --
! 147:
! 148: Warning: fopen() expects parameter 1 to be string, array given in %s on line %d
! 149: bool(false)
! 150:
! 151: Warning: fclose() expects parameter 1 to be resource, array given in %s on line %d
! 152: bool(false)
! 153:
! 154: Warning: feof() expects parameter 1 to be resource, array given in %s on line %d
! 155: bool(false)
! 156: -- Iteration 6 --
! 157:
! 158: Warning: fopen() expects parameter 1 to be string, object given in %s on line %d
! 159: bool(false)
! 160:
! 161: Warning: fclose() expects parameter 1 to be resource, object given in %s on line %d
! 162: bool(false)
! 163:
! 164: Warning: feof() expects parameter 1 to be resource, object given in %s on line %d
! 165: bool(false)
! 166: -- Iteration 7 --
! 167:
! 168: Warning: fopen(): Filename cannot be empty in %s on line %d
! 169: bool(false)
! 170:
! 171: Warning: fclose() expects parameter 1 to be resource, null given in %s on line %d
! 172: bool(false)
! 173:
! 174: Warning: feof() expects parameter 1 to be resource, null given in %s on line %d
! 175: bool(false)
! 176: -- Iteration 8 --
! 177:
! 178: Warning: fopen(): Filename cannot be empty in %s on line %d
! 179: bool(false)
! 180:
! 181: Warning: fclose() expects parameter 1 to be resource, string given in %s on line %d
! 182: bool(false)
! 183:
! 184: Warning: feof() expects parameter 1 to be resource, string given in %s on line %d
! 185: bool(false)
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>