Skip to content

Commit ca9cfd8

Browse files
committed
pgsqlSetNoticeCallback: test case
Add a test for a standard pgsqlSetNoticeCallback use.
1 parent 67e898d commit ca9cfd8

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

ext/pdo_pgsql/tests/issue78621.inc

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
require_once dirname(__FILE__) . '/../../../ext/pdo/tests/pdo_test.inc';
3+
require_once dirname(__FILE__) . '/config.inc';
4+
$db = PDOTest::test_factory(dirname(__FILE__) . '/common.phpt');
5+
6+
attach($db);
7+
8+
$db->beginTransaction();
9+
$db->exec("create temporary table t (a varchar(3))");
10+
$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");
11+
$db->exec("create trigger hop before insert on t for each row execute procedure hey()");
12+
$db->exec("insert into t values ('ah')");
13+
var_dump($db->query("select * from t")->fetchAll(PDO::FETCH_ASSOC));
14+
echo "Done\n";
15+
?>

ext/pdo_pgsql/tests/issue78621.phpt

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
--TEST--
2+
pgsqlSetNoticeCallback catches Postgres "raise notice".
3+
--SKIPIF--
4+
<?php
5+
if (!extension_loaded('pdo') || !extension_loaded('pdo_pgsql')) die('skip not loaded');
6+
require_once dirname(__FILE__) . '/../../../ext/pdo/tests/pdo_test.inc';
7+
require_once dirname(__FILE__) . '/config.inc';
8+
PDOTest::skip();
9+
?>
10+
--FILE--
11+
<?php
12+
function disp($message) { echo trim($message)."\n"; }
13+
function attach($db)
14+
{
15+
$db->pgsqlSetNoticeCallback('disp');
16+
}
17+
require dirname(__FILE__) . '/issue78621.inc';
18+
?>
19+
--EXPECT--
20+
NOTICE: I tampered your data, did you know?
21+
array(1) {
22+
[0]=>
23+
array(1) {
24+
["a"]=>
25+
string(2) "oh"
26+
}
27+
}
28+
Done

0 commit comments

Comments
 (0)