summaryrefslogtreecommitdiff
path: root/ext/pdo_pgsql/tests
diff options
context:
space:
mode:
Diffstat (limited to 'ext/pdo_pgsql/tests')
-rw-r--r--ext/pdo_pgsql/tests/copy_from.phpt31
-rw-r--r--ext/pdo_pgsql/tests/copy_to.phpt30
-rw-r--r--ext/pdo_pgsql/tests/getnotify.phpt109
3 files changed, 150 insertions, 20 deletions
diff --git a/ext/pdo_pgsql/tests/copy_from.phpt b/ext/pdo_pgsql/tests/copy_from.phpt
index 10967b0fe9..de1140dfea 100644
--- a/ext/pdo_pgsql/tests/copy_from.phpt
+++ b/ext/pdo_pgsql/tests/copy_from.phpt
@@ -16,8 +16,6 @@ $db->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, false);
$db->exec('CREATE TABLE test (a integer not null primary key, b text, c integer)');
-try {
-
echo "Preparing test file and array for CopyFrom tests\n";
$tableRows = array();
@@ -68,10 +66,13 @@ $db->rollback();
echo "Testing pgsqlCopyFromArray() with error\n";
$db->beginTransaction();
-var_dump($db->pgsqlCopyFromArray('test_error',$tableRowsWithDifferentNullValuesAndSelectedFields,";","NULL",'a,c'));
+try {
+ var_dump($db->pgsqlCopyFromArray('test_error',$tableRowsWithDifferentNullValuesAndSelectedFields,";","NULL",'a,c'));
+} catch (Exception $e) {
+ echo "Exception: {$e->getMessage()}\n";
+}
$db->rollback();
-
echo "Testing pgsqlCopyFromFile() with default parameters\n";
$db->beginTransaction();
var_dump($db->pgsqlCopyFromFile('test',$filename));
@@ -102,14 +103,21 @@ $db->rollback();
echo "Testing pgsqlCopyFromFile() with error\n";
$db->beginTransaction();
-var_dump($db->pgsqlCopyFromFile('test_error',$filenameWithDifferentNullValuesAndSelectedFields,";","NULL",'a,c'));
+try {
+ var_dump($db->pgsqlCopyFromFile('test_error',$filenameWithDifferentNullValuesAndSelectedFields,";","NULL",'a,c'));
+} catch (Exception $e) {
+ echo "Exception: {$e->getMessage()}\n";
+}
$db->rollback();
+echo "Testing pgsqlCopyFromFile() with non existing file\n";
+$db->beginTransaction();
+try {
+ var_dump($db->pgsqlCopyFromFile('test',"nonexisting/foo.csv",";","NULL",'a,c'));
} catch (Exception $e) {
- /* catch exceptions so that we can show the relative error */
- echo "Exception! at line ", $e->getLine(), "\n";
- var_dump($e->getMessage());
+ echo "Exception: {$e->getMessage()}\n";
}
+$db->rollback();
// Clean up
foreach (array($filename, $filenameWithDifferentNullValues, $filenameWithDifferentNullValuesAndSelectedFields) as $f) {
@@ -251,7 +259,7 @@ array(6) {
NULL
}
Testing pgsqlCopyFromArray() with error
-bool(false)
+Exception: SQLSTATE[42P01]: Undefined table: 7 ERROR: relation "test_error" does not exist
Testing pgsqlCopyFromFile() with default parameters
bool(true)
array(6) {
@@ -385,4 +393,7 @@ array(6) {
NULL
}
Testing pgsqlCopyFromFile() with error
-bool(false)
+Exception: SQLSTATE[42P01]: Undefined table: 7 ERROR: relation "test_error" does not exist
+Testing pgsqlCopyFromFile() with non existing file
+Exception: SQLSTATE[HY000]: General error: 7 Unable to open the file
+
diff --git a/ext/pdo_pgsql/tests/copy_to.phpt b/ext/pdo_pgsql/tests/copy_to.phpt
index 1dc7d1de33..7bc46c6e0b 100644
--- a/ext/pdo_pgsql/tests/copy_to.phpt
+++ b/ext/pdo_pgsql/tests/copy_to.phpt
@@ -17,7 +17,6 @@ $db->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, false);
$db->exec('CREATE TABLE test (a integer not null primary key, b text, c integer)');
$db->beginTransaction();
-try {
echo "Preparing test table for CopyTo tests\n";
$stmt = $db->prepare("INSERT INTO test (a, b, c) values (?, ?, ?)");
@@ -42,8 +41,11 @@ echo "Testing pgsqlCopyToArray() with only selected fields\n";
var_dump($db->pgsqlCopyToArray('test',";","NULL",'a,c'));
echo "Testing pgsqlCopyToArray() with error\n";
-var_dump($db->pgsqlCopyToArray('test_error'));
-
+try {
+ var_dump($db->pgsqlCopyToArray('test_error'));
+} catch (Exception $e) {
+ echo "Exception: {$e->getMessage()}\n";
+}
echo "Testing pgsqlCopyToFile() with default parameters\n";
@@ -58,14 +60,19 @@ var_dump($db->pgsqlCopyToFile('test',$filename,";","NULL",'a,c'));
echo file_get_contents($filename);
echo "Testing pgsqlCopyToFile() with error\n";
-var_dump($db->pgsqlCopyToFile('test_error',$filename));
-
+try {
+ var_dump($db->pgsqlCopyToFile('test_error',$filename));
+} catch (Exception $e) {
+ echo "Exception: {$e->getMessage()}\n";
+}
+echo "Testing pgsqlCopyToFile() to unwritable file\n";
+try {
+ var_dump($db->pgsqlCopyToFile('test', 'nonexistent/foo.csv'));
} catch (Exception $e) {
- /* catch exceptions so that we can show the relative error */
- echo "Exception! at line ", $e->getLine(), "\n";
- var_dump($e->getMessage());
+ echo "Exception: {$e->getMessage()}\n";
}
+
if(isset($filename)) {
@unlink($filename);
}
@@ -109,7 +116,7 @@ array(3) {
"
}
Testing pgsqlCopyToArray() with error
-bool(false)
+Exception: SQLSTATE[42P01]: Undefined table: 7 ERROR: relation "test_error" does not exist
Testing pgsqlCopyToFile() with default parameters
bool(true)
0 test insert 0 \N
@@ -126,4 +133,7 @@ bool(true)
1;NULL
2;NULL
Testing pgsqlCopyToFile() with error
-bool(false) \ No newline at end of file
+Exception: SQLSTATE[42P01]: Undefined table: 7 ERROR: relation "test_error" does not exist
+Testing pgsqlCopyToFile() to unwritable file
+Exception: SQLSTATE[HY000]: General error: 7 Unable to open the file for writing
+
diff --git a/ext/pdo_pgsql/tests/getnotify.phpt b/ext/pdo_pgsql/tests/getnotify.phpt
new file mode 100644
index 0000000000..c093e0357a
--- /dev/null
+++ b/ext/pdo_pgsql/tests/getnotify.phpt
@@ -0,0 +1,109 @@
+--TEST--
+PDO PgSQL LISTEN/NOTIFY support
+--SKIPIF--
+<?php # vim:se ft=php:
+if (!extension_loaded('pdo') || !extension_loaded('pdo_pgsql')) die('skip not loaded');
+require dirname(__FILE__) . '/config.inc';
+require dirname(__FILE__) . '/../../../ext/pdo/tests/pdo_test.inc';
+PDOTest::skip();
+?>
+--FILE--
+<?php
+require dirname(__FILE__) . '/../../../ext/pdo/tests/pdo_test.inc';
+$db = PDOTest::test_factory(dirname(__FILE__) . '/common.phpt');
+$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
+
+// pgsqlGetPid should return something meaningful
+$pid = $db->pgsqlGetPid();
+var_dump($pid > 0);
+
+// No listen, no notifies
+var_dump($db->pgsqlGetNotify());
+
+// Listen started, no notifies
+$db->exec("LISTEN notifies_phpt");
+var_dump($db->pgsqlGetNotify());
+
+// No parameters, use default PDO::FETCH_NUM
+$db->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_NUM);
+$db->exec("NOTIFY notifies_phpt");
+$notify = $db->pgsqlGetNotify();
+var_dump(count($notify));
+var_dump($notify[0]);
+var_dump($notify[1] == $pid);
+
+// No parameters, use default PDO::FETCH_ASSOC
+$db->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
+$db->exec("NOTIFY notifies_phpt");
+$notify = $db->pgsqlGetNotify();
+var_dump(count($notify));
+var_dump($notify['message']);
+var_dump($notify['pid'] == $pid);
+
+// Test PDO::FETCH_NUM as parameter
+$db->exec("NOTIFY notifies_phpt");
+$notify = $db->pgsqlGetNotify(PDO::FETCH_NUM);
+var_dump(count($notify));
+var_dump($notify[0]);
+var_dump($notify[1] == $pid);
+
+// Test PDO::FETCH_ASSOC as parameter
+$db->exec("NOTIFY notifies_phpt");
+$notify = $db->pgsqlGetNotify(PDO::FETCH_ASSOC);
+var_dump(count($notify));
+var_dump($notify['message']);
+var_dump($notify['pid'] == $pid);
+
+// Test PDO::FETCH_BOTH as parameter
+$db->exec("NOTIFY notifies_phpt");
+$notify = $db->pgsqlGetNotify(PDO::FETCH_BOTH);
+var_dump(count($notify));
+var_dump($notify['message']);
+var_dump($notify['pid'] == $pid);
+var_dump($notify[0]);
+var_dump($notify[1] == $pid);
+
+// Verify that there are no notifies queued
+var_dump($db->pgsqlGetNotify());
+
+
+// Test second parameter, should wait 2 seconds because no notify is queued
+$t = microtime(1);
+$notify = $db->pgsqlGetNotify(PDO::FETCH_ASSOC, 1000);
+var_dump((microtime(1) - $t) >= 1);
+var_dump($notify);
+
+// Test second parameter, should return immediately because a notify is queued
+$db->exec("NOTIFY notifies_phpt");
+$t = microtime(1);
+$notify = $db->pgsqlGetNotify(PDO::FETCH_ASSOC, 5000);
+var_dump((microtime(1) - $t) < 1);
+var_dump(count($notify));
+
+?>
+--EXPECT--
+bool(true)
+bool(false)
+bool(false)
+int(2)
+string(13) "notifies_phpt"
+bool(true)
+int(2)
+string(13) "notifies_phpt"
+bool(true)
+int(2)
+string(13) "notifies_phpt"
+bool(true)
+int(2)
+string(13) "notifies_phpt"
+bool(true)
+int(4)
+string(13) "notifies_phpt"
+bool(true)
+string(13) "notifies_phpt"
+bool(true)
+bool(false)
+bool(true)
+bool(false)
+bool(true)
+int(2)