Annotation of embedaddon/php/ext/mysqli/tests/mysqli_class_mysqli_stmt_interface.phpt, revision 1.1

1.1     ! misho       1: --TEST--
        !             2: Interface of the class mysqli_stmt
        !             3: --SKIPIF--
        !             4: <?php
        !             5:        require_once('skipif.inc');
        !             6:        require_once('skipifemb.inc');
        !             7:        require_once('skipifconnectfailure.inc');
        !             8: ?>
        !             9: --FILE--
        !            10: <?php
        !            11:        require('connect.inc');
        !            12:        require('table.inc');
        !            13: 
        !            14:        $link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket);
        !            15:        $stmt = new mysqli_stmt($link);
        !            16: 
        !            17:        printf("Parent class:\n");
        !            18:        var_dump(get_parent_class($stmt));
        !            19: 
        !            20:        printf("\nMethods:\n");
        !            21: 
        !            22:        $methods = get_class_methods($stmt);
        !            23:        $expected_methods = array(
        !            24:                '__construct'       => true,
        !            25:                'attr_get'          => true,
        !            26:                'attr_set'          => true,
        !            27:                'bind_param'        => true,
        !            28:                'bind_result'       => true,
        !            29:                'close'             => true,
        !            30:                'data_seek'         => true,
        !            31:                'execute'           => true,
        !            32:                'fetch'             => true,
        !            33:                'free_result'       => true,
        !            34:                'get_warnings'      => true,
        !            35:                'num_rows'          => true,
        !            36:                'prepare'           => true,
        !            37:                'reset'             => true,
        !            38:                'result_metadata'   => true,
        !            39:                'send_long_data'    => true,
        !            40:                'store_result'      => true,
        !            41:        );
        !            42: 
        !            43:        if ($IS_MYSQLND) {
        !            44:                $expected_methods['get_result'] = true;
        !            45:                $expected_methods['more_results'] = true;
        !            46:                $expected_methods['next_result'] = true;
        !            47:        }
        !            48: 
        !            49:        foreach ($methods as $k => $method) {
        !            50:        if (isset($expected_methods[$method])) {
        !            51:                unset($methods[$k]);
        !            52:                unset($expected_methods[$method]);
        !            53:        }
        !            54:                if ($method == 'mysqli_stmt') {
        !            55:                        // get_class_method reports different constructor names
        !            56:                        unset($expected_methods['__construct']);
        !            57:                        unset($methods[$k]);
        !            58:                }
        !            59:        }
        !            60:        if (!empty($methods)) {
        !            61:                printf("More methods found than indicated. Dumping list of unexpected methods.\n");
        !            62:                var_dump($methods);
        !            63:        }
        !            64:        if (!empty($expected_methods)) {
        !            65:                printf("Some methods are missing. Dumping list of missing methods.\n");
        !            66:                var_dump($expected_methods);
        !            67:        }
        !            68:        if (empty($methods) && empty($expected_methods))
        !            69:                printf("ok\n");
        !            70: 
        !            71:        printf("\nClass variables:\n");
        !            72:        $variables = array_keys(get_class_vars(get_class($stmt)));
        !            73:        sort($variables);
        !            74:        foreach ($variables as $k => $var)
        !            75:                printf("%s\n", $var);
        !            76: 
        !            77:        printf("\nObject variables:\n");
        !            78:        $variables = array_keys(get_object_vars($stmt));
        !            79:        foreach ($variables as $k => $var)
        !            80:                printf("%s\n", $var);
        !            81: 
        !            82: printf("\nMagic, magic properties:\n");
        !            83: 
        !            84: assert(mysqli_stmt_affected_rows($stmt) === $stmt->affected_rows);
        !            85: printf("stmt->affected_rows = '%s'\n", $stmt->affected_rows);
        !            86: 
        !            87: if (!$stmt->prepare("INSERT INTO test(id, label) VALUES (100, 'z')") ||
        !            88: !$stmt->execute())
        !            89: printf("[001] [%d] %s\n", $stmt->errno, $stmt->error);
        !            90: 
        !            91: assert(mysqli_stmt_affected_rows($stmt) === $stmt->affected_rows);
        !            92: printf("stmt->affected_rows = '%s'\n", $stmt->affected_rows);
        !            93: 
        !            94: assert(mysqli_stmt_errno($stmt) === $stmt->errno);
        !            95: printf("stmt->errno = '%s'\n", $stmt->errno);
        !            96: 
        !            97: assert(mysqli_stmt_error($stmt) === $stmt->error);
        !            98: printf("stmt->error = '%s'\n", $stmt->error);
        !            99: 
        !           100: assert(mysqli_stmt_field_count($stmt) === $stmt->field_count);
        !           101: printf("stmt->field_count = '%s'\n", $stmt->field_count);
        !           102: 
        !           103: assert($stmt->id > 0);
        !           104: printf("stmt->id = '%s'\n", $stmt->id);
        !           105: 
        !           106: assert(mysqli_stmt_insert_id($stmt) === $stmt->insert_id);
        !           107: printf("stmt->insert_id = '%s'\n", $stmt->insert_id);
        !           108: 
        !           109: assert(mysqli_stmt_num_rows($stmt) === $stmt->num_rows);
        !           110: printf("stmt->num_rows = '%s'\n", $stmt->num_rows);
        !           111: 
        !           112: assert(mysqli_stmt_param_count($stmt) === $stmt->param_count);
        !           113: printf("stmt->param_count = '%s'\n", $stmt->param_count);
        !           114: 
        !           115: assert(mysqli_stmt_sqlstate($stmt) === $stmt->sqlstate);
        !           116: printf("stmt->sqlstate = '%s'\n", $stmt->sqlstate);
        !           117: 
        !           118: printf("\nAccess to undefined properties:\n");
        !           119: printf("stmt->unknown = '%s'\n", @$stmt->unknown);
        !           120: @$stmt->unknown = 13;
        !           121: printf("stmt->unknown = '%s'\n", @$stmt->unknown);
        !           122: 
        !           123: printf("\nPrepare using the constructor:\n");
        !           124: $stmt = new mysqli_stmt($link, 'SELECT id FROM test ORDER BY id');
        !           125: if (!$stmt->execute())
        !           126: printf("[002] [%d] %s\n", $stmt->errno, $stmt->error);
        !           127: $stmt->close();
        !           128: 
        !           129: $obj = new stdClass();
        !           130: if (!is_object($stmt = new mysqli_stmt($link, $obj)))
        !           131: printf("[003] Expecting NULL got %s/%s\n", gettype($stmt), $stmt);
        !           132: 
        !           133: print "done!";
        !           134: ?>
        !           135: --EXPECTF--
        !           136: Parent class:
        !           137: bool(false)
        !           138: 
        !           139: Methods:
        !           140: ok
        !           141: 
        !           142: Class variables:
        !           143: affected_rows
        !           144: errno
        !           145: error
        !           146: field_count
        !           147: id
        !           148: insert_id
        !           149: num_rows
        !           150: param_count
        !           151: sqlstate
        !           152: 
        !           153: Object variables:
        !           154: affected_rows
        !           155: insert_id
        !           156: num_rows
        !           157: param_count
        !           158: field_count
        !           159: errno
        !           160: error
        !           161: sqlstate
        !           162: id
        !           163: 
        !           164: Magic, magic properties:
        !           165: 
        !           166: Warning: mysqli_stmt_affected_rows(): invalid object or resource mysqli_stmt
        !           167:  in %s on line %d
        !           168: 
        !           169: Warning: main(): Property access is not allowed yet in %s on line %d
        !           170: 
        !           171: Warning: main(): Property access is not allowed yet in %s on line %d
        !           172: stmt->affected_rows = ''
        !           173: stmt->affected_rows = '1'
        !           174: stmt->errno = '0'
        !           175: stmt->error = ''
        !           176: stmt->field_count = '0'
        !           177: stmt->id = '%d'
        !           178: stmt->insert_id = '0'
        !           179: stmt->num_rows = '0'
        !           180: stmt->param_count = '0'
        !           181: stmt->sqlstate = '00000'
        !           182: 
        !           183: Access to undefined properties:
        !           184: stmt->unknown = ''
        !           185: stmt->unknown = '13'
        !           186: 
        !           187: Prepare using the constructor:
        !           188: 
        !           189: Warning: mysqli_stmt::__construct() expects parameter 2 to be %binary_string_optional%, object given in %s on line %d
        !           190: done!

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