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