1
0
mirror of https://github.com/danog/ext-pq.git synced 2024-11-27 12:24:52 +01:00
This commit is contained in:
Michael Wallner 2013-01-21 17:44:37 +01:00
parent e7c7ee2497
commit 33f82236a1
4 changed files with 131 additions and 0 deletions

View File

@ -3,3 +3,5 @@ function _ext($ext) {
extension_loaded($ext) or die("skip $ext not loaded");
}
_ext("pq");
include "_setup.inc";
defined("PQ_DSN") or die("skip PG_DSN undefined");

48
tests/async001.phpt Normal file
View File

@ -0,0 +1,48 @@
--TEST--
async connect
--SKIPIF--
<?php include "_skipif.inc"; ?>
--FILE--
<?php
echo "Test\n";
include "_setup.inc";
$c = new pq\Connection(PQ_DSN, false);
$s = array($c->status);
echo "W";
$w = array($c->socket);
$r = $e = null;
stream_select($r, $w, $e, null);
while (true) {
$s[] = $c->status;
echo "P";
switch ($c->poll()) {
case pq\Connection::POLLING_READING:
echo "R";
$w = $e = null;
$r = array($c->socket);
stream_select($r, $w, $e, NULL);
break;
case pq\Connection::POLLING_WRITING:
echo "W";
$w = array($c->socket);
$r = $e = null;
stream_select($r, $w, $e, null);
break;
case pq\Connection::POLLING_FAILED:
echo "F";
break 2;
case pq\Connection::POLLING_OK:
echo "S";
break 2;
}
}
printf("\n%s\n", implode(",", $s));
?>
DONE
--EXPECTREGEX--
Test
(WP(RP)*)+S
3(,\d+),+4
DONE

60
tests/async002.phpt Normal file
View File

@ -0,0 +1,60 @@
--TEST--
async reset
--SKIPIF--
<?php include "_skipif.inc"; ?>
--FILE--
<?php
echo "Test\n";
include "_setup.inc";
$c = new pq\Connection(PQ_DSN, false);
function complete($c) {
$s = array($c->status);
echo "W";
$w = array($c->socket);
$r = $e = null;
stream_select($r, $w, $e, null);
while (true) {
$s[] = $c->status;
echo "P";
switch ($c->poll()) {
case pq\Connection::POLLING_READING:
echo "R";
$w = $e = null;
$r = array($c->socket);
stream_select($r, $w, $e, NULL);
break;
case pq\Connection::POLLING_WRITING:
echo "W";
$w = array($c->socket);
$r = $e = null;
stream_select($r, $w, $e, null);
break;
case pq\Connection::POLLING_FAILED:
echo "F";
break 2;
case pq\Connection::POLLING_OK:
echo "S";
break 2;
}
}
printf("\n%s\n", implode(",", $s));
}
complete($c);
if ($c->status == pq\Connection::OK) {
$c->reset();
complete($c);
}
?>
DONE
--EXPECTREGEX--
Test
(WP(RP)*)+S
3(,\d+),+4
(WP(RP)*)+S
3(,\d+),+4
DONE

21
tests/reset001.phpt Normal file
View File

@ -0,0 +1,21 @@
--TEST--
connection reset
--SKIPIF--
<?php include "_skipif.inc"; ?>
--FILE--
<?php
echo "Test\n";
include "_setup.inc";
$c = new pq\Connection(PQ_DSN);
var_dump($c->reset());
var_dump($c->reset());
?>
DONE
--EXPECT--
Test
bool(true)
bool(true)
DONE