Skip to content

Commit 5b12816

Browse files
committed
pgsqlSetNoticeCallback: more tests
see #6764 (review)
1 parent c757d02 commit 5b12816

File tree

3 files changed

+62
-4
lines changed

3 files changed

+62
-4
lines changed

ext/pdo_pgsql/tests/issue78621.inc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,5 @@ $db->exec("delete from t");
1919
$db->exec("insert into t values ('ah')");
2020
var_dump($db->query("select * from t")->fetchAll(PDO::FETCH_ASSOC));
2121
echo "Done\n";
22+
$db->rollback();
2223
?>

ext/pdo_pgsql/tests/issue78621_closure.phpt

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,29 @@ PDOTest::skip();
1212
function disp($message) { echo trim($message)."\n"; }
1313
function attach($db, $prefix = '')
1414
{
15-
$db->pgsqlSetNoticeCallback(function($message) use($prefix) { echo $prefix.trim($message)."\n"; });
16-
// https://github.com/php/php-src/pull/4823#pullrequestreview-335623806
17-
$eraseCallbackMemoryHere = (object)[1];
15+
global $flavor;
16+
switch($flavor)
17+
{
18+
case 0:
19+
$db->pgsqlSetNoticeCallback(function($message) use($prefix) { echo $prefix.trim($message)."\n"; });
20+
// https://github.com/php/php-src/pull/4823#pullrequestreview-335623806
21+
$eraseCallbackMemoryHere = (object)[1];
22+
break;
23+
case 1:
24+
$closure = function($message) use($prefix) { echo $prefix.'('.get_class($this).')'.trim($message)."\n"; };
25+
$db->pgsqlSetNoticeCallback($closure->bindTo(new \stdClass));
26+
break;
27+
}
1828
}
29+
echo "Testing with a simple inline closure:\n";
30+
$flavor = 0;
31+
require dirname(__FILE__) . '/issue78621.inc';
32+
echo "Testing with a postbound closure object:\n";
33+
++$flavor;
1934
require dirname(__FILE__) . '/issue78621.inc';
2035
?>
2136
--EXPECT--
37+
Testing with a simple inline closure:
2238
NOTICE: I tampered your data, did you know?
2339
ReNOTICE: I tampered your data, did you know?
2440
array(1) {
@@ -29,3 +45,14 @@ array(1) {
2945
}
3046
}
3147
Done
48+
Testing with a postbound closure object:
49+
(stdClass)NOTICE: I tampered your data, did you know?
50+
Re(stdClass)NOTICE: I tampered your data, did you know?
51+
array(1) {
52+
[0]=>
53+
array(1) {
54+
["a"]=>
55+
string(2) "oh"
56+
}
57+
}
58+
Done

ext/pdo_pgsql/tests/issue78621_method.phpt

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,47 @@ class Logger
1313
{
1414
public function disp($message) { echo trim($message)."\n"; }
1515
public function dispRe($message) { echo "Re".trim($message)."\n"; }
16+
public function __call(string $method, array $args)
17+
{
18+
$realMethod = strtr($method, [ 'whatever' => 'disp' ]);
19+
echo "$method trampoline for $realMethod\n";
20+
return call_user_func_array([ $this, $realMethod ], $args);
21+
}
1622
}
1723
$logger = new Logger();
1824
function attach($db, $prefix = '')
1925
{
2026
global $logger;
21-
$db->pgsqlSetNoticeCallback(array($logger, 'disp'.$prefix));
27+
global $flavor;
28+
switch($flavor)
29+
{
30+
case 0: $db->pgsqlSetNoticeCallback([ $logger, 'disp'.$prefix ]); break;
31+
case 1: $db->pgsqlSetNoticeCallback([ $logger, 'whatever'.$prefix ]); break;
32+
}
2233
}
34+
echo "Testing with method explicitely plugged:\n";
35+
$flavor = 0;
36+
require dirname(__FILE__) . '/issue78621.inc';
37+
echo "Testing with a bit of magic:\n";
38+
++$flavor;
2339
require dirname(__FILE__) . '/issue78621.inc';
2440
?>
2541
--EXPECT--
42+
Testing with method explicitely plugged:
43+
NOTICE: I tampered your data, did you know?
44+
ReNOTICE: I tampered your data, did you know?
45+
array(1) {
46+
[0]=>
47+
array(1) {
48+
["a"]=>
49+
string(2) "oh"
50+
}
51+
}
52+
Done
53+
Testing with a bit of magic:
54+
whatever trampoline for disp
2655
NOTICE: I tampered your data, did you know?
56+
whateverRe trampoline for dispRe
2757
ReNOTICE: I tampered your data, did you know?
2858
array(1) {
2959
[0]=>

0 commit comments

Comments
 (0)