Skip to content

Commit f4c3402

Browse files
committed
PdoPgsql::setNoticeCallback(): test
based on PDO::pgsqlSetNoticeCallback()'s one
1 parent 961d212 commit f4c3402

File tree

2 files changed

+56
-2
lines changed

2 files changed

+56
-2
lines changed

ext/pdo_pgsql/tests/issue78621.inc

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,30 @@
11
<?php
22
require_once dirname(__FILE__) . '/../../../ext/pdo/tests/pdo_test.inc';
33
require_once dirname(__FILE__) . '/config.inc';
4+
if (!isset($db)) {
45
$db = PDOTest::test_factory(dirname(__FILE__) . '/common.phpt');
6+
}
7+
if (!isset($rounds) || empty($rounds)) {
8+
$rounds = [ null, 'Re' ];
9+
}
510

6-
attach($db);
11+
attach($db, array_shift($rounds));
712

813
$db->beginTransaction();
914
$db->exec("set client_min_messages to notice");
1015
$db->exec("create temporary table t (a varchar(3))");
1116
$db->exec("create function hey() returns trigger as \$\$ begin new.a := 'oh'; raise notice 'I tampered your data, did you know?'; return new; end; \$\$ language plpgsql");
1217
$db->exec("create trigger hop before insert on t for each row execute procedure hey()");
1318
$db->exec("insert into t values ('ah')");
14-
attach($db, 'Re');
19+
while (count($rounds)) {
20+
try {
21+
attach($db, array_shift($rounds));
22+
} catch (TypeError $err) {
23+
echo "Caught TypeError: ".$err->getMessage()."\n";
24+
}
1525
$db->exec("delete from t");
1626
$db->exec("insert into t values ('ah')");
27+
}
1728
$db->pgsqlSetNoticeCallback(null);
1829
$db->exec("delete from t");
1930
$db->exec("insert into t values ('ah')");
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
--TEST--
2+
PdoPgsql::setNoticeCallback()
3+
--EXTENSIONS--
4+
pdo
5+
pdo_pgsql
6+
--SKIPIF--
7+
<?php
8+
require __DIR__ . '/config.inc';
9+
require dirname(__DIR__, 2) . '/pdo/tests/pdo_test.inc';
10+
PDOTest::skip();
11+
?>
12+
--FILE--
13+
<?php
14+
15+
require_once __DIR__ . "/config.inc";
16+
17+
$db = new PdoPgsql($config['ENV']['PDOTEST_DSN']);
18+
19+
function disp($message) { echo trim($message)."\n"; }
20+
function attach($db, $callback) { $db->setNoticeCallback($callback); }
21+
22+
$rounds = [
23+
'disp', // Correct.
24+
3, // Error, so the old callback is kept, and will be used in the call that follows the caught error.
25+
null, // No callback. Hopefully this clears everything.
26+
'wouldAnyoneNameAFunctionThatWay', // So this one will crash and *no output will follow*.
27+
];
28+
require __DIR__ . '/issue78621.inc';
29+
30+
?>
31+
--EXPECTF--
32+
NOTICE: I tampered your data, did you know?
33+
Caught TypeError: %s: Argument #1 ($callback) %s
34+
NOTICE: I tampered your data, did you know?
35+
Caught TypeError: %s: Argument #1 ($callback) %s
36+
array(1) {
37+
[0]=>
38+
array(1) {
39+
["a"]=>
40+
string(2) "oh"
41+
}
42+
}
43+
Done

0 commit comments

Comments
 (0)