Skip to content

Commit b0ef4d3

Browse files
committed
PdoPgsql::setNoticeCallback(): test
based on PDO::pgsqlSetNoticeCallback()'s one
1 parent 32fa1d8 commit b0ef4d3

File tree

2 files changed

+58
-2
lines changed

2 files changed

+58
-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: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
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+
class T { public function z($m) { echo $m."\n"; } public function _call($m, $p) { echo "bah $m\n"; } }
23+
$t = new T;
24+
$rounds = [
25+
'disp', // Correct.
26+
3, // Error, so the old callback is kept, and will be used in the call that follows the caught error.
27+
null, // No callback. Hopefully this clears everything.
28+
'wouldAnyoneNameAFunctionThatWay', // So this one will crash and *no output will follow*.
29+
];
30+
require __DIR__ . '/issue78621.inc';
31+
32+
?>
33+
--EXPECTF--
34+
NOTICE: I tampered your data, did you know?
35+
Caught TypeError: %s: Argument #1 ($callback) %s
36+
NOTICE: I tampered your data, did you know?
37+
Caught TypeError: %s: Argument #1 ($callback) %s
38+
array(1) {
39+
[0]=>
40+
array(1) {
41+
["a"]=>
42+
string(2) "oh"
43+
}
44+
}
45+
Done

0 commit comments

Comments
 (0)