tests
authorMichael Wallner <mike@php.net>
Mon, 21 Jan 2013 11:13:04 +0000 (12:13 +0100)
committerMichael Wallner <mike@php.net>
Mon, 21 Jan 2013 11:13:04 +0000 (12:13 +0100)
tests/_setup.inc [new file with mode: 0644]
tests/_skipif.inc [new file with mode: 0644]
tests/basic001.phpt [new file with mode: 0644]
tests/basic002.phpt [new file with mode: 0644]
tests/stm_desc001.phpt [new file with mode: 0644]

diff --git a/tests/_setup.inc b/tests/_setup.inc
new file mode 100644 (file)
index 0000000..0af687a
--- /dev/null
@@ -0,0 +1,2 @@
+<?php
+define("PQ_DSN", "dbname=mike");
diff --git a/tests/_skipif.inc b/tests/_skipif.inc
new file mode 100644 (file)
index 0000000..93ac8ae
--- /dev/null
@@ -0,0 +1,5 @@
+<?php
+function _ext($ext) {
+       extension_loaded($ext) or die("skip $ext not loaded");
+}
+_ext("pq");
diff --git a/tests/basic001.phpt b/tests/basic001.phpt
new file mode 100644 (file)
index 0000000..8712cb9
--- /dev/null
@@ -0,0 +1,51 @@
+--TEST--
+basic functionality
+--SKIPIF--
+<?php include "_skipif.inc"; ?>
+--FILE--
+<?php
+echo "Test\n";
+
+include "_setup.inc";
+
+$con = new pq\Connection(PQ_DSN);
+$res = $con->exec("SELECT 1 as one, 2 as two from generate_series(1,2)");
+
+var_dump($res->status == pq\Result::TUPLES_OK);
+var_dump($res->numRows);
+var_dump($res->numCols);
+
+foreach ($res as $rowNum => $rowData) {
+       printf("%d.0 => %d\n", $rowNum, $rowData[0]);
+       printf("%d.1 => %d\n", $rowNum, $rowData[1]);
+}
+$res->fetchType = pq\Result::FETCH_ASSOC;
+foreach ($res as $rowNum => $rowData) {
+       printf("%d.0 => %d\n", $rowNum, $rowData["one"]);
+       printf("%d.1 => %d\n", $rowNum, $rowData["two"]);
+}
+$res->fetchType = pq\Result::FETCH_OBJECT;
+foreach ($res as $rowNum => $rowData) {
+       printf("%d.0 => %d\n", $rowNum, $rowData->one);
+       printf("%d.1 => %d\n", $rowNum, $rowData->two);
+}
+?>
+DONE
+--EXPECT--
+Test
+bool(true)
+int(2)
+int(2)
+0.0 => 1
+0.1 => 2
+1.0 => 1
+1.1 => 2
+0.0 => 1
+0.1 => 2
+1.0 => 1
+1.1 => 2
+0.0 => 1
+0.1 => 2
+1.0 => 1
+1.1 => 2
+DONE
diff --git a/tests/basic002.phpt b/tests/basic002.phpt
new file mode 100644 (file)
index 0000000..ce3b6c9
--- /dev/null
@@ -0,0 +1,22 @@
+--TEST--
+basic functionality
+--SKIPIF--
+<?php include "_skipif.inc"; ?>
+--FILE--
+<?php
+echo "Test\n";
+include "_setup.inc";
+
+$c = new pq\Connection(PQ_DSN);
+$s = $c->prepare("test1", "SELECT \$1",array($c->types->byName->text->oid));
+$r = $s->exec(array("fooo"));
+
+printf("%s\n", $r->errorMessage);
+printf("%s\n", $r->fetchCol());
+?>
+DONE
+--EXPECT--
+Test
+
+fooo
+DONE
diff --git a/tests/stm_desc001.phpt b/tests/stm_desc001.phpt
new file mode 100644 (file)
index 0000000..ae3e51a
--- /dev/null
@@ -0,0 +1,22 @@
+--TEST--
+pq\Statment::desc()
+--SKIPIF--
+<?php include "_skipif.inc"; ?>
+--FILE--
+<?php
+echo "Test\n";
+include "_setup.inc";
+
+$c = new pq\Connection(PQ_DSN);
+$s = $c->prepare("test1", "SELECT NOW() - \$1");
+$r = $s->exec(array("2012-12-12 12:12:12"));
+$d = $s->desc();
+
+printf("%s\n", $c->types->byOid->{$d[0]}->typname);
+
+?>
+DONE
+--EXPECT--
+Test
+timestamptz
+DONE