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

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: 
1.1.1.2 ! misho     100: assert(mysqli_stmt_error_list($stmt) === $stmt->error_list);
        !           101: var_dump("stmt->error = ", $stmt->error_list);
        !           102: 
1.1       misho     103: assert(mysqli_stmt_field_count($stmt) === $stmt->field_count);
                    104: printf("stmt->field_count = '%s'\n", $stmt->field_count);
                    105: 
                    106: assert($stmt->id > 0);
                    107: printf("stmt->id = '%s'\n", $stmt->id);
                    108: 
                    109: assert(mysqli_stmt_insert_id($stmt) === $stmt->insert_id);
                    110: printf("stmt->insert_id = '%s'\n", $stmt->insert_id);
                    111: 
                    112: assert(mysqli_stmt_num_rows($stmt) === $stmt->num_rows);
                    113: printf("stmt->num_rows = '%s'\n", $stmt->num_rows);
                    114: 
                    115: assert(mysqli_stmt_param_count($stmt) === $stmt->param_count);
                    116: printf("stmt->param_count = '%s'\n", $stmt->param_count);
                    117: 
                    118: assert(mysqli_stmt_sqlstate($stmt) === $stmt->sqlstate);
                    119: printf("stmt->sqlstate = '%s'\n", $stmt->sqlstate);
                    120: 
                    121: printf("\nAccess to undefined properties:\n");
                    122: printf("stmt->unknown = '%s'\n", @$stmt->unknown);
                    123: @$stmt->unknown = 13;
                    124: printf("stmt->unknown = '%s'\n", @$stmt->unknown);
                    125: 
                    126: printf("\nPrepare using the constructor:\n");
                    127: $stmt = new mysqli_stmt($link, 'SELECT id FROM test ORDER BY id');
                    128: if (!$stmt->execute())
                    129: printf("[002] [%d] %s\n", $stmt->errno, $stmt->error);
                    130: $stmt->close();
                    131: 
                    132: $obj = new stdClass();
                    133: if (!is_object($stmt = new mysqli_stmt($link, $obj)))
                    134: printf("[003] Expecting NULL got %s/%s\n", gettype($stmt), $stmt);
                    135: 
                    136: print "done!";
                    137: ?>
                    138: --EXPECTF--
                    139: Parent class:
                    140: bool(false)
                    141: 
                    142: Methods:
                    143: ok
                    144: 
                    145: Class variables:
                    146: affected_rows
                    147: errno
                    148: error
1.1.1.2 ! misho     149: error_list
1.1       misho     150: field_count
                    151: id
                    152: insert_id
                    153: num_rows
                    154: param_count
                    155: sqlstate
                    156: 
                    157: Object variables:
                    158: affected_rows
                    159: insert_id
                    160: num_rows
                    161: param_count
                    162: field_count
                    163: errno
                    164: error
1.1.1.2 ! misho     165: error_list
1.1       misho     166: sqlstate
                    167: id
                    168: 
                    169: Magic, magic properties:
                    170: 
                    171: Warning: mysqli_stmt_affected_rows(): invalid object or resource mysqli_stmt
                    172:  in %s on line %d
                    173: 
                    174: Warning: main(): Property access is not allowed yet in %s on line %d
                    175: 
                    176: Warning: main(): Property access is not allowed yet in %s on line %d
                    177: stmt->affected_rows = ''
                    178: stmt->affected_rows = '1'
                    179: stmt->errno = '0'
                    180: stmt->error = ''
1.1.1.2 ! misho     181: string(14) "stmt->error = "
        !           182: array(0) {
        !           183: }
1.1       misho     184: stmt->field_count = '0'
                    185: stmt->id = '%d'
                    186: stmt->insert_id = '0'
                    187: stmt->num_rows = '0'
                    188: stmt->param_count = '0'
                    189: stmt->sqlstate = '00000'
                    190: 
                    191: Access to undefined properties:
                    192: stmt->unknown = ''
                    193: stmt->unknown = '13'
                    194: 
                    195: Prepare using the constructor:
                    196: 
                    197: Warning: mysqli_stmt::__construct() expects parameter 2 to be %binary_string_optional%, object given in %s on line %d
                    198: done!

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