Annotation of embedaddon/php/ext/standard/tests/file/fgets_error.phpt, revision 1.1

1.1     ! misho       1: --TEST--
        !             2: Test fgets() function : error conditions
        !             3: --FILE--
        !             4: <?php
        !             5: /*
        !             6:  Prototype: string fgets ( resource $handle [, int $length] );
        !             7:  Description: Gets line from file pointer
        !             8: */
        !             9: 
        !            10: echo "*** Testing error conditions ***\n";
        !            11: // zero argument
        !            12: echo "-- Testing fgets() with zero argument --\n";
        !            13: var_dump( fgets() );
        !            14: 
        !            15: // more than expected no. of args
        !            16: echo "-- Testing fgets() with more than expected number of arguments --\n";
        !            17: $fp = fopen(__FILE__, "r");
        !            18: var_dump( fgets($fp, 10, $fp) );
        !            19: 
        !            20: // invalid length argument 
        !            21: echo "-- Testing fgets() with invalid length arguments --\n";
        !            22: $len = 0; 
        !            23: var_dump( fgets($fp, $len) );
        !            24: $len = -10;
        !            25: var_dump( fgets($fp, $len) );
        !            26: $len = 1; 
        !            27: var_dump( fgets($fp, $len) ); // return length - 1 always, expect false
        !            28: 
        !            29: 
        !            30: // test invalid arguments : non-resources
        !            31: echo "-- Testing fgets() with invalid arguments --\n";
        !            32: $invalid_args = array (
        !            33:   "string",
        !            34:   10,
        !            35:   10.5,
        !            36:   true,
        !            37:   array(1,2,3),
        !            38:   new stdclass,
        !            39: );
        !            40: /* loop to test fgets() with different invalid type of args */
        !            41: for($loop_counter = 1; $loop_counter <= count($invalid_args); $loop_counter++) {
        !            42:   echo "-- Iteration $loop_counter --\n";
        !            43:   var_dump( fgets($invalid_args[$loop_counter - 1], 10) );
        !            44: }
        !            45: 
        !            46: // fgets() on a file handle which is already closed
        !            47: echo "-- Testing fgets() with closed/unset file handle --";
        !            48: fclose($fp);
        !            49: var_dump(fgets($fp,10));
        !            50: 
        !            51: // fgets() on a file handle which is unset
        !            52: $file_handle = fopen(__FILE__, "r");
        !            53: unset($file_handle); //unset file handle
        !            54: var_dump( fgets(@$file_handle,10));
        !            55: 
        !            56: echo "Done\n";
        !            57: ?>
        !            58: --EXPECTF--
        !            59: *** Testing error conditions ***
        !            60: -- Testing fgets() with zero argument --
        !            61: 
        !            62: Warning: fgets() expects at least 1 parameter, 0 given in %s on line %d
        !            63: bool(false)
        !            64: -- Testing fgets() with more than expected number of arguments --
        !            65: 
        !            66: Warning: fgets() expects at most 2 parameters, 3 given in %s on line %d
        !            67: bool(false)
        !            68: -- Testing fgets() with invalid length arguments --
        !            69: 
        !            70: Warning: fgets(): Length parameter must be greater than 0 in %s on line %d
        !            71: bool(false)
        !            72: 
        !            73: Warning: fgets(): Length parameter must be greater than 0 in %s on line %d
        !            74: bool(false)
        !            75: bool(false)
        !            76: -- Testing fgets() with invalid arguments --
        !            77: -- Iteration 1 --
        !            78: 
        !            79: Warning: fgets() expects parameter 1 to be resource, string given in %s on line %d
        !            80: bool(false)
        !            81: -- Iteration 2 --
        !            82: 
        !            83: Warning: fgets() expects parameter 1 to be resource, integer given in %s on line %d
        !            84: bool(false)
        !            85: -- Iteration 3 --
        !            86: 
        !            87: Warning: fgets() expects parameter 1 to be resource, double given in %s on line %d
        !            88: bool(false)
        !            89: -- Iteration 4 --
        !            90: 
        !            91: Warning: fgets() expects parameter 1 to be resource, boolean given in %s on line %d
        !            92: bool(false)
        !            93: -- Iteration 5 --
        !            94: 
        !            95: Warning: fgets() expects parameter 1 to be resource, array given in %s on line %d
        !            96: bool(false)
        !            97: -- Iteration 6 --
        !            98: 
        !            99: Warning: fgets() expects parameter 1 to be resource, object given in %s on line %d
        !           100: bool(false)
        !           101: -- Testing fgets() with closed/unset file handle --
        !           102: Warning: fgets(): %d is not a valid stream resource in %s on line %d
        !           103: bool(false)
        !           104: 
        !           105: Warning: fgets() expects parameter 1 to be resource, null given in %s on line %d
        !           106: bool(false)
        !           107: Done
        !           108: 

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