xref: /PHP-8.2/ext/pdo_pgsql/tests/bug68199.phpt (revision 39131219)
1--TEST--
2Bug #68199 (PDO::pgsqlGetNotify doesn't support NOTIFY payloads)
3--EXTENSIONS--
4pdo
5pdo_pgsql
6--SKIPIF--
7<?php
8require __DIR__ . '/config.inc';
9require __DIR__ . '/../../../ext/pdo/tests/pdo_test.inc';
10PDOTest::skip();
11
12$db = PDOTest::factory();
13if (version_compare($db->getAttribute(PDO::ATTR_SERVER_VERSION), '9.0.0') < 0) {
14    die("skip Requires 9.0+");
15}
16
17?>
18--FILE--
19<?php
20require __DIR__ . '/../../../ext/pdo/tests/pdo_test.inc';
21$db = PDOTest::test_factory(__DIR__ . '/common.phpt');
22$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
23
24// pgsqlGetPid should return something meaningful
25$pid = $db->pgsqlGetPid();
26var_dump($pid > 0);
27
28// No listen, no notifies
29var_dump($db->pgsqlGetNotify());
30
31// Listen started, no notifies
32$db->exec("LISTEN notifies_phpt");
33var_dump($db->pgsqlGetNotify());
34
35// No parameters with payload, use default PDO::FETCH_NUM
36$db->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_NUM);
37$db->exec("NOTIFY notifies_phpt, 'payload'");
38$notify = $db->pgsqlGetNotify();
39var_dump(count($notify));
40var_dump($notify[0]);
41var_dump($notify[1] == $pid);
42var_dump($notify[2]);
43
44// No parameters with payload, use default PDO::FETCH_ASSOC
45$db->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
46$db->exec("NOTIFY notifies_phpt, 'payload'");
47$notify = $db->pgsqlGetNotify();
48var_dump(count($notify));
49var_dump($notify['message']);
50var_dump($notify['pid'] == $pid);
51var_dump($notify['payload']);
52
53// Test PDO::FETCH_NUM as parameter with payload
54$db->exec("NOTIFY notifies_phpt, 'payload'");
55$notify = $db->pgsqlGetNotify(PDO::FETCH_NUM);
56var_dump(count($notify));
57var_dump($notify[0]);
58var_dump($notify[1] == $pid);
59var_dump($notify[2]);
60
61// Test PDO::FETCH_ASSOC as parameter with payload
62$db->exec("NOTIFY notifies_phpt, 'payload'");
63$notify = $db->pgsqlGetNotify(PDO::FETCH_ASSOC);
64var_dump(count($notify));
65var_dump($notify['message']);
66var_dump($notify['pid'] == $pid);
67var_dump($notify['payload']);
68
69// Test PDO::FETCH_BOTH as parameter with payload
70$db->exec("NOTIFY notifies_phpt, 'payload'");
71$notify = $db->pgsqlGetNotify(PDO::FETCH_BOTH);
72var_dump(count($notify));
73var_dump($notify['message']);
74var_dump($notify['pid'] == $pid);
75var_dump($notify['payload']);
76var_dump($notify[0]);
77var_dump($notify[1] == $pid);
78var_dump($notify[2]);
79
80// Verify that there are no notifies queued
81var_dump($db->pgsqlGetNotify());
82
83?>
84--EXPECT--
85bool(true)
86bool(false)
87bool(false)
88int(3)
89string(13) "notifies_phpt"
90bool(true)
91string(7) "payload"
92int(3)
93string(13) "notifies_phpt"
94bool(true)
95string(7) "payload"
96int(3)
97string(13) "notifies_phpt"
98bool(true)
99string(7) "payload"
100int(3)
101string(13) "notifies_phpt"
102bool(true)
103string(7) "payload"
104int(6)
105string(13) "notifies_phpt"
106bool(true)
107string(7) "payload"
108string(13) "notifies_phpt"
109bool(true)
110string(7) "payload"
111bool(false)
112