xref: /php-src/ext/pdo/tests/bug_44173.phpt (revision f4a5db3e)
1--TEST--
2PDO Common: Bug #44173 (PDO->query() parameter parsing/checking needs an update)
3--EXTENSIONS--
4pdo
5--SKIPIF--
6<?php
7$dir = getenv('REDIR_TEST_DIR');
8if (false == $dir) die('skip no driver');
9require_once $dir . 'pdo_test.inc';
10PDOTest::skip();
11?>
12--FILE--
13<?php
14if (getenv('REDIR_TEST_DIR') === false) putenv('REDIR_TEST_DIR='.__DIR__ . '/../../pdo/tests/');
15require getenv('REDIR_TEST_DIR') . 'pdo_test.inc';
16$db = PDOTest::factory();
17
18$db->exec("CREATE TABLE test44173 (x int)");
19$db->exec("INSERT INTO test44173 VALUES (1)");
20
21
22// Bug entry [2] -- 1 is PDO::FETCH_LAZY
23try {
24    $stmt = $db->query("SELECT * FROM test44173", PDO::FETCH_LAZY, 0, []);
25    var_dump($stmt);
26} catch (\TypeError $e) {
27    echo $e->getMessage(), \PHP_EOL;
28}
29
30
31// Bug entry [3]
32try {
33    $stmt = $db->query("SELECT * FROM test44173", 'abc');
34} catch (TypeError $e) {
35    echo $e->getMessage(), "\n";
36}
37
38// Bug entry [4]
39try {
40    $stmt = $db->query("SELECT * FROM test44173", PDO::FETCH_CLASS, 0, 0, 0);
41    var_dump($stmt);
42} catch (\ArgumentCountError $e) {
43    echo $e->getMessage(), \PHP_EOL;
44}
45
46
47// Bug entry [5]
48try {
49    $stmt = $db->query("SELECT * FROM test44173", PDO::FETCH_INTO);
50    var_dump($stmt);
51} catch (\ArgumentCountError $e) {
52    echo $e->getMessage(), \PHP_EOL;
53}
54
55
56// Bug entry [6]
57try {
58    $stmt = $db->query("SELECT * FROM test44173", PDO::FETCH_COLUMN);
59    var_dump($stmt);
60} catch (\ArgumentCountError $e) {
61    echo $e->getMessage(), \PHP_EOL;
62}
63
64
65// Bug entry [7]
66try {
67    $stmt = $db->query("SELECT * FROM test44173", PDO::FETCH_CLASS);
68    var_dump($stmt);
69} catch (\ArgumentCountError $e) {
70    echo $e->getMessage(), \PHP_EOL;
71}
72
73
74?>
75--CLEAN--
76<?php
77require_once getenv('REDIR_TEST_DIR') . 'pdo_test.inc';
78$db = PDOTest::factory();
79PDOTest::dropTableIfExists($db, "test44173");
80?>
81--EXPECT--
82PDO::query() expects exactly 2 arguments for the fetch mode provided, 4 given
83PDO::query(): Argument #2 ($fetchMode) must be of type ?int, string given
84PDO::query() expects at most 4 arguments for the fetch mode provided, 5 given
85PDO::query() expects exactly 3 arguments for the fetch mode provided, 2 given
86PDO::query() expects exactly 3 arguments for the fetch mode provided, 2 given
87PDO::query() expects at least 3 arguments for the fetch mode provided, 2 given
88