summaryrefslogtreecommitdiff
path: root/ext/pdo/tests/bug_44159.phpt
blob: d80311ad2210381ec86b951684e502963828b78d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
--TEST--
PDO Common: Bug #44159 (Crash: $pdo->setAttribute(PDO::STATEMENT_ATTR_CLASS, NULL))
--SKIPIF--
<?php
if (!extension_loaded('pdo')) die('skip');
$dir = getenv('REDIR_TEST_DIR');
if (false == $dir) die('skip no driver');
require_once $dir . 'pdo_test.inc';
PDOTest::skip();
?>
--FILE--
<?php
if (getenv('REDIR_TEST_DIR') === false) putenv('REDIR_TEST_DIR='.__DIR__ . '/../../pdo/tests/');
require_once getenv('REDIR_TEST_DIR') . 'pdo_test.inc';
$pdo = PDOTest::factory();
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);

$attrs = array(PDO::ATTR_STATEMENT_CLASS, PDO::ATTR_STRINGIFY_FETCHES);

foreach ($attrs as $attr) {
    try {
        var_dump($pdo->setAttribute($attr, NULL));
    } catch (\Error $e) {
        echo  get_class($e), ': ', $e->getMessage(), \PHP_EOL;
    }
    try {
        var_dump($pdo->setAttribute($attr, 1));
    } catch (\Error $e) {
        echo  get_class($e), ': ', $e->getMessage(), \PHP_EOL;
    }
    try {
        var_dump($pdo->setAttribute($attr, 'nonsense'));
    } catch (\Error $e) {
        echo  get_class($e), ': ', $e->getMessage(), \PHP_EOL;
    }
}

@unlink(__DIR__."/foo.db");

?>
--EXPECT--
TypeError: PDO::ATTR_STATEMENT_CLASS value must be of type array, null given
TypeError: PDO::ATTR_STATEMENT_CLASS value must be of type array, int given
TypeError: PDO::ATTR_STATEMENT_CLASS value must be of type array, string given
TypeError: Attribute value must be of type bool for selected attribute, null given
bool(true)
TypeError: Attribute value must be of type bool for selected attribute, string given