tests
authorMichael Wallner <mike@php.net>
Fri, 22 Feb 2013 16:16:12 +0000 (17:16 +0100)
committerMichael Wallner <mike@php.net>
Fri, 22 Feb 2013 16:16:12 +0000 (17:16 +0100)
tests/lob002.phpt [new file with mode: 0644]
tests/lob003.phpt [new file with mode: 0644]

diff --git a/tests/lob002.phpt b/tests/lob002.phpt
new file mode 100644 (file)
index 0000000..e2fd056
--- /dev/null
@@ -0,0 +1,48 @@
+--TEST--
+large object stream
+--SKIPIF--
+<?php include "_skipif.inc"; ?>
+--FILE--
+<?php
+echo "Test\n";
+
+include "_setup.inc";
+
+$c = new pq\Connection(PQ_DSN);
+$t = $c->startTransaction();
+
+$lob = $t->createLOB();
+fwrite($lob->stream, file_get_contents(__FILE__));
+var_dump(ftell($lob->stream));
+
+fseek($lob->stream, 0, SEEK_SET);
+$dat = fread($lob->stream, filesize(__FILE__));
+var_dump(hash("md5", $dat)==hash_file("md5", __FILE__));
+
+ftruncate($lob->stream, 5);
+
+$lob = new pq\Lob($t, $lob->oid);
+var_dump(fread($lob->stream, 123));
+
+$t->commit();
+$t->unlinkLOB($lob->oid);
+
+?>
+DONE
+--EXPECTF--
+Test
+int(503)
+bool(true)
+
+Warning: ftruncate(): Can't truncate this stream! in %s on line %d
+string(123) "<?php
+echo "Test\n";
+
+include "_setup.inc";
+
+$c = new pq\Connection(PQ_DSN);
+$t = $c->startTransaction();
+
+$lob = $t->creat"
+DONE
+
diff --git a/tests/lob003.phpt b/tests/lob003.phpt
new file mode 100644 (file)
index 0000000..f6d846e
--- /dev/null
@@ -0,0 +1,32 @@
+--TEST--
+large object closing stream 
+--SKIPIF--
+<?php include "_skipif.inc"; ?>
+--FILE--
+<?php
+echo "Test\n";
+
+include "_setup.inc";
+
+$c = new pq\Connection(PQ_DSN);
+$t = $c->startTransaction();
+
+$lob = $t->createLOB();
+var_dump($lob->stream);
+var_dump($lob->stream);
+fclose($lob->stream); // bad boy!
+var_dump($lob->stream);
+var_dump(fread($lob->stream, 5));
+$lob = null;
+?>
+DONE
+--EXPECTF--
+Test
+resource(%d) of type (stream)
+resource(%d) of type (stream)
+
+Warning: fclose(): %d is not a valid stream resource in %s on line %d
+resource(%d) of type (stream)
+string(0) ""
+DONE
+