diff options
author | George Peter Banyard <girgias@php.net> | 2020-07-03 13:43:29 +0200 |
---|---|---|
committer | George Peter Banyard <girgias@php.net> | 2020-09-15 19:12:02 +0200 |
commit | 7a95e943d642e05532979a06221c476183eac7e4 (patch) | |
tree | ded828cad622e5e55e06ec70c9e044e834fffc94 /ext/mysqli/tests/mysqli_stmt_attr_set.phpt | |
parent | 7e61c2edd8456ff502e17e14d517da409f1e6193 (diff) | |
download | php-git-7a95e943d642e05532979a06221c476183eac7e4.tar.gz |
Promote warnings to Error in MySQLi extension
Closes GH-5803
Diffstat (limited to 'ext/mysqli/tests/mysqli_stmt_attr_set.phpt')
-rw-r--r-- | ext/mysqli/tests/mysqli_stmt_attr_set.phpt | 68 |
1 files changed, 32 insertions, 36 deletions
diff --git a/ext/mysqli/tests/mysqli_stmt_attr_set.phpt b/ext/mysqli/tests/mysqli_stmt_attr_set.phpt index 4fad53cba2..870960e602 100644 --- a/ext/mysqli/tests/mysqli_stmt_attr_set.phpt +++ b/ext/mysqli/tests/mysqli_stmt_attr_set.phpt @@ -28,38 +28,28 @@ require_once("connect.inc"); $stmt = mysqli_stmt_init($link); try { mysqli_stmt_attr_set($stmt, 0, 0); - } catch (Error $exception) { - echo $exception->getMessage() . "\n"; + } catch (\Throwable $e) { + echo get_class($e) . ': ' . $e->getMessage() . PHP_EOL; } $stmt->prepare("SELECT * FROM test"); - - mt_srand(microtime(true)); - - for ($i = -100; $i < 1000; $i++) { - if (in_array($i, $valid_attr)) - continue; - $invalid_attr = $i; - if (false !== ($tmp = @mysqli_stmt_attr_set($stmt, $invalid_attr, 0))) { - printf("[006a] Expecting boolean/false for attribute %d, got %s/%s\n", $invalid_attr, gettype($tmp), $tmp); - } + // Invalid Attribute (2nd argument) + try { + mysqli_stmt_attr_set($stmt, -1, 0); + } catch (\ValueError $e) { + echo $e->getMessage() . \PHP_EOL; } - - for ($i = 0; $i < 2; $i++) { - do { - $invalid_attr = mt_rand(-1 * (min(4294967296, PHP_INT_MAX) + 1), min(4294967296, PHP_INT_MAX)); - } while (in_array($invalid_attr, $valid_attr)); - if (false !== ($tmp = @mysqli_stmt_attr_set($stmt, $invalid_attr, 0))) { - printf("[006b] Expecting boolean/false for attribute %d, got %s/%s\n", $invalid_attr, gettype($tmp), $tmp); - } + // Invalid mode for MYSQLI_STMT_ATTR_UPDATE_MAX_LENGTH + try { + $stmt->attr_set(MYSQLI_STMT_ATTR_UPDATE_MAX_LENGTH, -1); + } catch (\ValueError $e) { + echo $e->getMessage() . \PHP_EOL; } $stmt->close(); // // MYSQLI_STMT_ATTR_UPDATE_MAX_LENGTH // - - // expecting max_length not to be set and be 0 in all cases $stmt = mysqli_stmt_init($link); $stmt->prepare("SELECT label FROM test"); @@ -79,7 +69,7 @@ require_once("connect.inc"); // expecting max_length to _be_ set $stmt = mysqli_stmt_init($link); $stmt->prepare("SELECT label FROM test"); - $stmt->attr_set(MYSQLI_STMT_ATTR_UPDATE_MAX_LENGTH, 1); + var_dump($stmt->attr_set(MYSQLI_STMT_ATTR_UPDATE_MAX_LENGTH, 1)); $res = $stmt->attr_get(MYSQLI_STMT_ATTR_UPDATE_MAX_LENGTH); if ($res !== 1) printf("[007.1] max_length should be 1, got %s\n", $res); @@ -122,21 +112,15 @@ require_once("connect.inc"); if (mysqli_get_client_version() > 50003) { - $cursor_types = array( - MYSQLI_CURSOR_TYPE_NO_CURSOR, - MYSQLI_CURSOR_TYPE_READ_ONLY, - MYSQLI_CURSOR_TYPE_FOR_UPDATE, - MYSQLI_CURSOR_TYPE_SCROLLABLE - ); - do { - $invalid_cursor_type = mt_rand(-1000, 1000); - } while (in_array($invalid_cursor_type, $cursor_types)); - $stmt = mysqli_stmt_init($link); $stmt->prepare("SELECT id, label FROM test"); - if (false !== ($tmp = @$stmt->attr_set(MYSQLI_STMT_ATTR_CURSOR_TYPE, $invalid_cursor_type))) - printf("[010] Expecting boolean/false, got %s/%s\n", gettype($tmp), $tmp); + // Invalid cursor type + try { + $stmt->attr_set(MYSQLI_STMT_ATTR_CURSOR_TYPE, -1); + } catch (\ValueError $e) { + echo $e->getMessage() . \PHP_EOL; + } if (false !== ($tmp = $stmt->attr_set(MYSQLI_STMT_ATTR_CURSOR_TYPE, MYSQLI_CURSOR_TYPE_FOR_UPDATE))) printf("[011] Expecting boolean/false, got %s/%s\n", gettype($tmp), $tmp); @@ -209,6 +193,13 @@ require_once("connect.inc"); $stmt = mysqli_stmt_init($link); $stmt->prepare("SELECT id, label FROM test"); + // Invalid prefetch value + try { + $stmt->attr_set(MYSQLI_STMT_ATTR_PREFETCH_ROWS, 0); + } catch (\ValueError $e) { + echo $e->getMessage() . \PHP_EOL; + } + if (true !== ($tmp = $stmt->attr_set(MYSQLI_STMT_ATTR_PREFETCH_ROWS, 1))) printf("[020] Expecting boolean/true, got %s/%s\n", gettype($tmp), $tmp); $stmt->execute(); @@ -262,5 +253,10 @@ require_once("connect.inc"); require_once("clean_table.inc"); ?> --EXPECT-- -mysqli_stmt object is not fully initialized +Error: mysqli_stmt object is not fully initialized +mysqli_stmt_attr_set(): Argument #2 ($attr) must be one of MYSQLI_STMT_ATTR_UPDATE_MAX_LENGTH, MYSQLI_STMT_ATTR_PREFETCH_ROWS, or STMT_ATTR_CURSOR_TYPE +mysqli_stmt::attr_set(): Argument #2 ($mode_in) must be 0 or 1 for attribute MYSQLI_STMT_ATTR_UPDATE_MAX_LENGTH +bool(true) +mysqli_stmt::attr_set(): Argument #2 ($mode_in) must be one of MYSQLI_CURSOR_TYPE_NO_CURSOR, MYSQLI_CURSOR_TYPE_READ_ONLY, MYSQLI_CURSOR_TYPE_FOR_UPDATE, or MYSQLI_CURSOR_TYPE_SCROLLABLE for attribute MYSQLI_STMT_ATTR_CURSOR_TYPE +mysqli_stmt::attr_set(): Argument #2 ($mode_in) must be greater than 0 for attribute MYSQLI_STMT_ATTR_PREFETCH_ROWS done! |