mirror of
https://github.com/danog/postgres.git
synced 2024-11-30 04:29:12 +01:00
Update for async-interop merge and other Amp changes
This commit is contained in:
parent
478835a486
commit
04a6463888
@ -22,8 +22,7 @@
|
||||
"amphp/amp": "dev-master as 2.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"amphp/loop": "dev-master",
|
||||
"phpunit/phpunit": "^5.0"
|
||||
"phpunit/phpunit": "^5"
|
||||
},
|
||||
"minimum-stability": "dev",
|
||||
"autoload": {
|
||||
|
@ -5,7 +5,7 @@ require dirname(__DIR__) . '/vendor/autoload.php';
|
||||
|
||||
use Amp\Postgres;
|
||||
|
||||
AsyncInterop\Loop::execute(Amp\wrap(function () {
|
||||
Amp\Loop::run(function () {
|
||||
$pool = Postgres\pool('host=localhost user=postgres');
|
||||
|
||||
/** @var \Amp\Postgres\Statement $statement */
|
||||
@ -18,4 +18,4 @@ AsyncInterop\Loop::execute(Amp\wrap(function () {
|
||||
$row = $result->getCurrent();
|
||||
\printf("%-35s = %s (%s)\n", $row['name'], $row['setting'], $row['description']);
|
||||
}
|
||||
}));
|
||||
});
|
||||
|
@ -4,15 +4,15 @@
|
||||
require dirname(__DIR__) . '/vendor/autoload.php';
|
||||
|
||||
use Amp\Postgres;
|
||||
use AsyncInterop\Loop;
|
||||
use Amp\Loop;
|
||||
|
||||
Loop::execute(Amp\wrap(function () {
|
||||
Loop::run(function () {
|
||||
$pool = Postgres\pool('host=localhost user=postgres');
|
||||
|
||||
$channel = "test";
|
||||
|
||||
/** @var \Amp\Postgres\Listener $listener */
|
||||
$listener = yield $pool->listen("test");
|
||||
$listener = yield $pool->listen($channel);
|
||||
|
||||
printf("Listening on channel '%s'\n", $listener->getChannel());
|
||||
|
||||
@ -39,4 +39,4 @@ Loop::execute(Amp\wrap(function () {
|
||||
$notification->payload
|
||||
);
|
||||
}
|
||||
}));
|
||||
});
|
||||
|
@ -2,8 +2,7 @@
|
||||
|
||||
namespace Amp\Postgres;
|
||||
|
||||
use Amp\{ CallableMaker, Coroutine, Deferred, function pipe };
|
||||
use AsyncInterop\Promise;
|
||||
use Amp\{ CallableMaker, Coroutine, Deferred, Promise };
|
||||
|
||||
abstract class AbstractConnection implements Connection {
|
||||
use CallableMaker;
|
||||
@ -21,7 +20,7 @@ abstract class AbstractConnection implements Connection {
|
||||
* @param string $connectionString
|
||||
* @param int $timeout Timeout until the connection attempt fails. 0 for no timeout.
|
||||
*
|
||||
* @return \AsyncInterop\Promise<\Amp\Postgres\Connection>
|
||||
* @return \Amp\Promise<\Amp\Postgres\Connection>
|
||||
*/
|
||||
abstract public static function connect(string $connectionString, int $timeout = 0): Promise;
|
||||
|
||||
@ -119,7 +118,7 @@ abstract class AbstractConnection implements Connection {
|
||||
throw new \Error("Invalid transaction type");
|
||||
}
|
||||
|
||||
return pipe($promise, function () use ($isolation): Transaction {
|
||||
return Promise\pipe($promise, function () use ($isolation): Transaction {
|
||||
$this->busy = new Deferred;
|
||||
$transaction = new Transaction($this->executor, $isolation);
|
||||
$transaction->onComplete($this->release);
|
||||
|
@ -2,8 +2,7 @@
|
||||
|
||||
namespace Amp\Postgres;
|
||||
|
||||
use Amp\{ Coroutine, Deferred };
|
||||
use AsyncInterop\Promise;
|
||||
use Amp\{ Coroutine, Deferred, Promise };
|
||||
|
||||
abstract class AbstractPool implements Pool {
|
||||
/** @var \SplQueue */
|
||||
@ -15,20 +14,20 @@ abstract class AbstractPool implements Pool {
|
||||
/** @var \SplObjectStorage */
|
||||
private $connections;
|
||||
|
||||
/** @var \AsyncInterop\Promise|null */
|
||||
/** @var \Amp\Promise|null */
|
||||
private $promise;
|
||||
|
||||
/** @var \Amp\Deferred|null */
|
||||
private $deferred;
|
||||
|
||||
/** @var \Amp\Postgres\Connection|\AsyncInterop\Promise|null Connection used for notification listening. */
|
||||
/** @var \Amp\Postgres\Connection|\Amp\Promise|null Connection used for notification listening. */
|
||||
private $listeningConnection;
|
||||
|
||||
/** @var int Number of listeners on listening connection. */
|
||||
private $listenerCount = 0;
|
||||
|
||||
/**
|
||||
* @return \AsyncInterop\Promise<\Amp\Postgres\Connection>
|
||||
* @return \Amp\Promise<\Amp\Postgres\Connection>
|
||||
*
|
||||
* @throws \Amp\Postgres\FailureException
|
||||
*/
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
namespace Amp\Postgres;
|
||||
|
||||
use AsyncInterop\Promise;
|
||||
use Amp\Promise;
|
||||
|
||||
class AggregatePool extends AbstractPool {
|
||||
/**
|
||||
|
@ -2,13 +2,13 @@
|
||||
|
||||
namespace Amp\Postgres;
|
||||
|
||||
use AsyncInterop\Promise;
|
||||
use Amp\Promise;
|
||||
|
||||
interface Connection extends Executor {
|
||||
/**
|
||||
* @param int $isolation
|
||||
*
|
||||
* @return \AsyncInterop\Promise<\Amp\Postgres\Transaction>
|
||||
* @return \Amp\Promise<\Amp\Postgres\Transaction>
|
||||
*
|
||||
* @throws \Amp\Postgres\FailureException
|
||||
*/
|
||||
@ -17,7 +17,7 @@ interface Connection extends Executor {
|
||||
/**
|
||||
* @param string $channel Channel name.
|
||||
*
|
||||
* @return \AsyncInterop\Promise<\Amp\Postgres\Listener>
|
||||
* @return \Amp\Promise<\Amp\Postgres\Listener>
|
||||
*
|
||||
* @throws \Amp\Postgres\FailureException
|
||||
*/
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
namespace Amp\Postgres;
|
||||
|
||||
use AsyncInterop\Promise;
|
||||
use Amp\Promise;
|
||||
|
||||
class ConnectionPool extends AbstractPool {
|
||||
const DEFAULT_MAX_CONNECTIONS = 100;
|
||||
|
@ -2,13 +2,13 @@
|
||||
|
||||
namespace Amp\Postgres;
|
||||
|
||||
use AsyncInterop\Promise;
|
||||
use Amp\Promise;
|
||||
|
||||
interface Executor {
|
||||
/**
|
||||
* @param string $sql
|
||||
*
|
||||
* @return \AsyncInterop\Promise<\Amp\Postgres\Result>
|
||||
* @return \Amp\Promise<\Amp\Postgres\Result>
|
||||
*
|
||||
* @throws \Amp\Postgres\FailureException
|
||||
*/
|
||||
@ -18,7 +18,7 @@ interface Executor {
|
||||
* @param string $sql
|
||||
* @param mixed ...$params
|
||||
*
|
||||
* @return \AsyncInterop\Promise<\Amp\Postgres\Result>
|
||||
* @return \Amp\Promise<\Amp\Postgres\Result>
|
||||
*
|
||||
* @throws \Amp\Postgres\FailureException
|
||||
*/
|
||||
@ -27,7 +27,7 @@ interface Executor {
|
||||
/**
|
||||
* @param string $sql
|
||||
*
|
||||
* @return \AsyncInterop\Promise<\Amp\Postgres\Statement>
|
||||
* @return \Amp\Promise<\Amp\Postgres\Statement>
|
||||
*
|
||||
* @throws \Amp\Postgres\FailureException
|
||||
*/
|
||||
@ -37,7 +37,7 @@ interface Executor {
|
||||
* @param string $channel Channel name.
|
||||
* @param string $payload Notification payload.
|
||||
*
|
||||
* @return \AsyncInterop\Promise<\Amp\Postgres\CommandResult>
|
||||
* @return \Amp\Promise<\Amp\Postgres\CommandResult>
|
||||
*/
|
||||
public function notify(string $channel, string $payload = ""): Promise;
|
||||
}
|
||||
|
@ -2,8 +2,7 @@
|
||||
|
||||
namespace Amp\Postgres;
|
||||
|
||||
use Amp\{ Listener as StreamListener, Stream };
|
||||
use AsyncInterop\Promise;
|
||||
use Amp\{ Listener as StreamListener, Promise, Stream };
|
||||
|
||||
class Listener extends StreamListener implements Operation {
|
||||
use Internal\Operation;
|
||||
@ -35,10 +34,10 @@ class Listener extends StreamListener implements Operation {
|
||||
/**
|
||||
* Unlistens from the channel. No more values will be emitted on theis channel.
|
||||
*
|
||||
* @return \AsyncInterop\Promise<\Amp\Postgres\CommandResult>
|
||||
* @return \Amp\Promise<\Amp\Postgres\CommandResult>
|
||||
*/
|
||||
public function unlisten(): Promise {
|
||||
/** @var \AsyncInterop\Promise $promise */
|
||||
/** @var \Amp\Promise $promise */
|
||||
$promise = ($this->unlisten)($this->channel);
|
||||
$promise->when(function () {
|
||||
$this->complete();
|
||||
|
@ -2,15 +2,14 @@
|
||||
|
||||
namespace Amp\Postgres;
|
||||
|
||||
use Amp\{ Deferred, Failure };
|
||||
use AsyncInterop\{ Loop, Promise };
|
||||
use Amp\{ Deferred, Failure, Loop, Promise };
|
||||
|
||||
class PgSqlConnection extends AbstractConnection {
|
||||
/**
|
||||
* @param string $connectionString
|
||||
* @param int $timeout
|
||||
*
|
||||
* @return \AsyncInterop\Promise<\Amp\Postgres\PgSqlConnection>
|
||||
* @return \Amp\Promise<\Amp\Postgres\PgSqlConnection>
|
||||
*/
|
||||
public static function connect(string $connectionString, int $timeout = 0): Promise {
|
||||
if (!$connection = @\pg_connect($connectionString, \PGSQL_CONNECT_ASYNC | \PGSQL_CONNECT_FORCE_NEW)) {
|
||||
@ -51,7 +50,7 @@ class PgSqlConnection extends AbstractConnection {
|
||||
$promise = $deferred->promise();
|
||||
|
||||
if ($timeout !== 0) {
|
||||
$promise = \Amp\timeout($promise, $timeout);
|
||||
$promise = Promise\timeout($promise, $timeout);
|
||||
}
|
||||
|
||||
$promise->when(function ($exception) use ($connection, $poll, $await) {
|
||||
|
@ -2,8 +2,7 @@
|
||||
|
||||
namespace Amp\Postgres;
|
||||
|
||||
use Amp\{ CallableMaker, Coroutine, Deferred, Emitter, function pipe };
|
||||
use AsyncInterop\{ Loop, Promise };
|
||||
use Amp\{ CallableMaker, Coroutine, Deferred, Emitter, Loop, Promise, function Promise\pipe };
|
||||
|
||||
class PgSqlExecutor implements Executor {
|
||||
use CallableMaker;
|
||||
@ -236,7 +235,7 @@ class PgSqlExecutor implements Executor {
|
||||
/**
|
||||
* @param string $channel
|
||||
*
|
||||
* @return \AsyncInterop\Promise
|
||||
* @return \Amp\Promise
|
||||
*
|
||||
* @throws \Error
|
||||
*/
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
namespace Amp\Postgres;
|
||||
|
||||
use AsyncInterop\Promise;
|
||||
use Amp\Promise;
|
||||
|
||||
class PgSqlStatement implements Statement {
|
||||
/** @var string */
|
||||
@ -30,7 +30,7 @@ class PgSqlStatement implements Statement {
|
||||
/**
|
||||
* @param mixed ...$params
|
||||
*
|
||||
* @return \AsyncInterop\Promise<\Amp\Postgres\Result>
|
||||
* @return \Amp\Promise<\Amp\Postgres\Result>
|
||||
*
|
||||
* @throws \Amp\Postgres\FailureException If executing the statement fails.
|
||||
*/
|
||||
|
@ -2,8 +2,7 @@
|
||||
|
||||
namespace Amp\Postgres;
|
||||
|
||||
use Amp\{ Deferred, Failure };
|
||||
use AsyncInterop\{ Loop, Promise };
|
||||
use Amp\{ Deferred, Failure, Loop, Promise };
|
||||
use pq;
|
||||
|
||||
class PqConnection extends AbstractConnection {
|
||||
@ -11,7 +10,7 @@ class PqConnection extends AbstractConnection {
|
||||
* @param string $connectionString
|
||||
* @param int $timeout
|
||||
*
|
||||
* @return \AsyncInterop\Promise<\Amp\Postgres\PgSqlConnection>
|
||||
* @return \Amp\Promise<\Amp\Postgres\PgSqlConnection>
|
||||
*/
|
||||
public static function connect(string $connectionString, int $timeout = 0): Promise {
|
||||
try {
|
||||
@ -50,7 +49,7 @@ class PqConnection extends AbstractConnection {
|
||||
$promise = $deferred->promise();
|
||||
|
||||
if ($timeout !== 0) {
|
||||
$promise = \Amp\timeout($promise, $timeout);
|
||||
$promise = Promise\timeout($promise, $timeout);
|
||||
}
|
||||
|
||||
$promise->when(function () use ($poll, $await) {
|
||||
|
@ -2,8 +2,7 @@
|
||||
|
||||
namespace Amp\Postgres;
|
||||
|
||||
use Amp\{ CallableMaker, Coroutine, Deferred, Emitter };
|
||||
use AsyncInterop\{ Loop, Promise };
|
||||
use Amp\{ CallableMaker, Coroutine, Deferred, Emitter, Loop, Promise };
|
||||
use pq;
|
||||
|
||||
class PqExecutor implements Executor {
|
||||
@ -248,7 +247,7 @@ class PqExecutor implements Executor {
|
||||
$emitter->emit($notification);
|
||||
}));
|
||||
|
||||
return \Amp\pipe($promise, function () use ($emitter, $channel): Listener {
|
||||
return Promise\pipe($promise, function () use ($emitter, $channel): Listener {
|
||||
$this->listeners[$channel] = $emitter;
|
||||
Loop::enable($this->poll);
|
||||
return new Listener($emitter->stream(), $channel, $this->unlisten);
|
||||
@ -258,7 +257,7 @@ class PqExecutor implements Executor {
|
||||
/**
|
||||
* @param string $channel
|
||||
*
|
||||
* @return \AsyncInterop\Promise
|
||||
* @return \Amp\Promise
|
||||
*
|
||||
* @throws \Error
|
||||
*/
|
||||
|
@ -2,8 +2,7 @@
|
||||
|
||||
namespace Amp\Postgres;
|
||||
|
||||
use Amp\{ Coroutine, function rethrow };
|
||||
use AsyncInterop\Promise;
|
||||
use Amp\{ Coroutine, Promise };
|
||||
use pq;
|
||||
|
||||
class PqStatement implements Statement {
|
||||
@ -23,7 +22,7 @@ class PqStatement implements Statement {
|
||||
}
|
||||
|
||||
public function __destruct() {
|
||||
rethrow(new Coroutine(($this->execute)([$this->statement, "deallocateAsync"])));
|
||||
Promise\rethrow(new Coroutine(($this->execute)([$this->statement, "deallocateAsync"])));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -36,7 +35,7 @@ class PqStatement implements Statement {
|
||||
/**
|
||||
* @param mixed ...$params
|
||||
*
|
||||
* @return \AsyncInterop\Promise<\Amp\Postgres\Result>
|
||||
* @return \Amp\Promise<\Amp\Postgres\Result>
|
||||
*
|
||||
* @throws \Amp\Postgres\FailureException If executing the statement fails.
|
||||
*/
|
||||
|
@ -14,7 +14,7 @@ class PqUnbufferedResult extends TupleResult implements Operation {
|
||||
private $numCols;
|
||||
|
||||
/**
|
||||
* @param callable(): \AsyncInterop\Promise $fetch Function to fetch next result row.
|
||||
* @param callable(): \Amp\Promise $fetch Function to fetch next result row.
|
||||
* @param \pq\Result $result PostgreSQL result object.
|
||||
*/
|
||||
public function __construct(callable $fetch, pq\Result $result) {
|
||||
|
@ -2,13 +2,13 @@
|
||||
|
||||
namespace Amp\Postgres;
|
||||
|
||||
use AsyncInterop\Promise;
|
||||
use Amp\Promise;
|
||||
|
||||
interface Statement {
|
||||
/**
|
||||
* @param mixed ...$params
|
||||
*
|
||||
* @return \AsyncInterop\Promise<\Amp\Postgres\Result>
|
||||
* @return \Amp\Promise<\Amp\Postgres\Result>
|
||||
*/
|
||||
public function execute(...$params): Promise;
|
||||
}
|
||||
|
@ -2,8 +2,7 @@
|
||||
|
||||
namespace Amp\Postgres;
|
||||
|
||||
use Amp\Coroutine;
|
||||
use AsyncInterop\Promise;
|
||||
use Amp\{ Coroutine, Promise };
|
||||
|
||||
class Transaction implements Executor, Operation {
|
||||
use Internal\Operation;
|
||||
@ -103,7 +102,7 @@ class Transaction implements Executor, Operation {
|
||||
/**
|
||||
* Commits the transaction and makes it inactive.
|
||||
*
|
||||
* @return \AsyncInterop\Promise<\Amp\Postgres\CommandResult>
|
||||
* @return \Amp\Promise<\Amp\Postgres\CommandResult>
|
||||
*
|
||||
* @throws \Amp\Postgres\TransactionError
|
||||
*/
|
||||
@ -131,7 +130,7 @@ class Transaction implements Executor, Operation {
|
||||
/**
|
||||
* Rolls back the transaction and makes it inactive.
|
||||
*
|
||||
* @return \AsyncInterop\Promise<\Amp\Postgres\CommandResult>
|
||||
* @return \Amp\Promise<\Amp\Postgres\CommandResult>
|
||||
*
|
||||
* @throws \Amp\Postgres\TransactionError
|
||||
*/
|
||||
@ -161,7 +160,7 @@ class Transaction implements Executor, Operation {
|
||||
*
|
||||
* @param string $identifier Savepoint identifier.
|
||||
*
|
||||
* @return \AsyncInterop\Promise<\Amp\Postgres\CommandResult>
|
||||
* @return \Amp\Promise<\Amp\Postgres\CommandResult>
|
||||
*
|
||||
* @throws \Amp\Postgres\TransactionError
|
||||
*/
|
||||
@ -175,7 +174,7 @@ class Transaction implements Executor, Operation {
|
||||
*
|
||||
* @param string $identifier Savepoint identifier.
|
||||
*
|
||||
* @return \AsyncInterop\Promise<\Amp\Postgres\CommandResult>
|
||||
* @return \Amp\Promise<\Amp\Postgres\CommandResult>
|
||||
*
|
||||
* @throws \Amp\Postgres\TransactionError
|
||||
*/
|
||||
@ -189,7 +188,7 @@ class Transaction implements Executor, Operation {
|
||||
*
|
||||
* @param string $identifier Savepoint identifier.
|
||||
*
|
||||
* @return \AsyncInterop\Promise<\Amp\Postgres\CommandResult>
|
||||
* @return \Amp\Promise<\Amp\Postgres\CommandResult>
|
||||
*
|
||||
* @throws \Amp\Postgres\TransactionError
|
||||
*/
|
||||
|
@ -2,13 +2,13 @@
|
||||
|
||||
namespace Amp\Postgres;
|
||||
|
||||
use AsyncInterop\Promise;
|
||||
use Amp\Promise;
|
||||
|
||||
/**
|
||||
* @param string $connectionString
|
||||
* @param int $timeout
|
||||
*
|
||||
* @return \AsyncInterop\Promise<\Amp\Postgres\Connection>
|
||||
* @return \Amp\Promise<\Amp\Postgres\Connection>
|
||||
*
|
||||
* @throws \Amp\Postgres\FailureException If connecting fails.
|
||||
* @throws \Error If neither ext-pgsql or pecl-pq is loaded.
|
||||
|
@ -2,9 +2,8 @@
|
||||
|
||||
namespace Amp\Postgres\Test;
|
||||
|
||||
use Amp\{ Coroutine, Pause };
|
||||
use Amp\{ Coroutine, Loop, Pause };
|
||||
use Amp\Postgres\{ CommandResult, Connection, QueryError, Transaction, TransactionError, TupleResult };
|
||||
use AsyncInterop\Loop;
|
||||
|
||||
abstract class AbstractConnectionTest extends \PHPUnit_Framework_TestCase {
|
||||
/** @var \Amp\Postgres\Connection */
|
||||
@ -31,7 +30,7 @@ abstract class AbstractConnectionTest extends \PHPUnit_Framework_TestCase {
|
||||
}
|
||||
|
||||
public function testQueryWithTupleResult() {
|
||||
Loop::execute(\Amp\wrap(function () {
|
||||
Loop::run(function () {
|
||||
/** @var \Amp\Postgres\TupleResult $result */
|
||||
$result = yield $this->connection->query("SELECT * FROM test");
|
||||
|
||||
@ -46,41 +45,41 @@ abstract class AbstractConnectionTest extends \PHPUnit_Framework_TestCase {
|
||||
$this->assertSame($data[$i][0], $row['domain']);
|
||||
$this->assertSame($data[$i][1], $row['tld']);
|
||||
}
|
||||
}), Loop::get());
|
||||
});
|
||||
}
|
||||
|
||||
public function testQueryWithCommandResult() {
|
||||
Loop::execute(\Amp\wrap(function () {
|
||||
Loop::run(function () {
|
||||
/** @var \Amp\Postgres\CommandResult $result */
|
||||
$result = yield $this->connection->query("INSERT INTO test VALUES ('canon', 'jp')");
|
||||
|
||||
$this->assertInstanceOf(CommandResult::class, $result);
|
||||
$this->assertSame(1, $result->affectedRows());
|
||||
}), Loop::get());
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Amp\Postgres\QueryError
|
||||
*/
|
||||
public function testQueryWithEmptyQuery() {
|
||||
Loop::execute(\Amp\wrap(function () {
|
||||
Loop::run(function () {
|
||||
/** @var \Amp\Postgres\CommandResult $result */
|
||||
$result = yield $this->connection->query('');
|
||||
}), Loop::get());
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Amp\Postgres\QueryError
|
||||
*/
|
||||
public function testQueryWithSyntaxError() {
|
||||
Loop::execute(\Amp\wrap(function () {
|
||||
Loop::run(function () {
|
||||
/** @var \Amp\Postgres\CommandResult $result */
|
||||
$result = yield $this->connection->query("SELECT & FROM test");
|
||||
}), Loop::get());
|
||||
});
|
||||
}
|
||||
|
||||
public function testPrepare() {
|
||||
Loop::execute(\Amp\wrap(function () {
|
||||
Loop::run(function () {
|
||||
$query = "SELECT * FROM test WHERE domain=\$1";
|
||||
|
||||
/** @var \Amp\Postgres\Statement $statement */
|
||||
@ -102,11 +101,11 @@ abstract class AbstractConnectionTest extends \PHPUnit_Framework_TestCase {
|
||||
$this->assertSame($data[0], $row['domain']);
|
||||
$this->assertSame($data[1], $row['tld']);
|
||||
}
|
||||
}), Loop::get());
|
||||
});
|
||||
}
|
||||
|
||||
public function testExecute() {
|
||||
Loop::execute(\Amp\wrap(function () {
|
||||
Loop::run(function () {
|
||||
$data = $this->getData()[0];
|
||||
|
||||
/** @var \Amp\Postgres\TupleResult $result */
|
||||
@ -121,7 +120,7 @@ abstract class AbstractConnectionTest extends \PHPUnit_Framework_TestCase {
|
||||
$this->assertSame($data[0], $row['domain']);
|
||||
$this->assertSame($data[1], $row['tld']);
|
||||
}
|
||||
}), Loop::get());
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
@ -142,9 +141,9 @@ abstract class AbstractConnectionTest extends \PHPUnit_Framework_TestCase {
|
||||
}
|
||||
});
|
||||
|
||||
Loop::execute(\Amp\wrap(function () use ($callback) {
|
||||
yield \Amp\all([$callback(0), $callback(1)]);
|
||||
}), Loop::get());
|
||||
Loop::run(function () use ($callback) {
|
||||
yield \Amp\Promise\all([$callback(0), $callback(1)]);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
@ -165,13 +164,13 @@ abstract class AbstractConnectionTest extends \PHPUnit_Framework_TestCase {
|
||||
});
|
||||
|
||||
try {
|
||||
Loop::execute(\Amp\wrap(function () use ($callback) {
|
||||
Loop::run(function () use ($callback) {
|
||||
$failing = $callback("SELECT & FROM test");
|
||||
$successful = $callback("SELECT * FROM test");
|
||||
|
||||
yield $successful;
|
||||
yield $failing;
|
||||
}), Loop::get());
|
||||
});
|
||||
} catch (QueryError $exception) {
|
||||
return;
|
||||
}
|
||||
@ -210,9 +209,9 @@ abstract class AbstractConnectionTest extends \PHPUnit_Framework_TestCase {
|
||||
}
|
||||
})());
|
||||
|
||||
Loop::execute(\Amp\wrap(function () use ($promises) {
|
||||
yield \Amp\all($promises);
|
||||
}), Loop::get());
|
||||
Loop::run(function () use ($promises) {
|
||||
yield \Amp\Promise\all($promises);
|
||||
});
|
||||
}
|
||||
|
||||
public function testSimultaneousPrepareAndExecute() {
|
||||
@ -245,13 +244,13 @@ abstract class AbstractConnectionTest extends \PHPUnit_Framework_TestCase {
|
||||
}
|
||||
})());
|
||||
|
||||
Loop::execute(\Amp\wrap(function () use ($promises) {
|
||||
yield \Amp\all($promises);
|
||||
}), Loop::get());
|
||||
Loop::run(function () use ($promises) {
|
||||
yield \Amp\Promise\all($promises);
|
||||
});
|
||||
}
|
||||
|
||||
public function testTransaction() {
|
||||
Loop::execute(\Amp\wrap(function () {
|
||||
Loop::run(function () {
|
||||
$isolation = Transaction::COMMITTED;
|
||||
|
||||
/** @var \Amp\Postgres\Transaction $transaction */
|
||||
@ -280,44 +279,44 @@ abstract class AbstractConnectionTest extends \PHPUnit_Framework_TestCase {
|
||||
} catch (TransactionError $exception) {
|
||||
// Exception expected.
|
||||
}
|
||||
}), Loop::get());
|
||||
});
|
||||
}
|
||||
|
||||
public function testConnect() {
|
||||
Loop::execute(\Amp\wrap(function () {
|
||||
Loop::run(function () {
|
||||
$connect = $this->getConnectCallable();
|
||||
$connection = yield $connect('host=localhost user=postgres');
|
||||
$this->assertInstanceOf(Connection::class, $connection);
|
||||
}));
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Amp\Postgres\FailureException
|
||||
*/
|
||||
public function testConnectInvalidUser() {
|
||||
Loop::execute(\Amp\wrap(function () {
|
||||
Loop::run(function () {
|
||||
$connect = $this->getConnectCallable();
|
||||
$connection = yield $connect('host=localhost user=invalid', 100);
|
||||
}));
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Amp\Postgres\FailureException
|
||||
*/
|
||||
public function testConnectInvalidConnectionString() {
|
||||
Loop::execute(\Amp\wrap(function () {
|
||||
Loop::run(function () {
|
||||
$connect = $this->getConnectCallable();
|
||||
$connection = yield $connect('invalid connection string', 100);
|
||||
}));
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Amp\Postgres\FailureException
|
||||
*/
|
||||
public function testConnectInvalidHost() {
|
||||
Loop::execute(\Amp\wrap(function () {
|
||||
Loop::run(function () {
|
||||
$connect = $this->getConnectCallable();
|
||||
$connection = yield $connect('hostaddr=invalid.host user=postgres', 100);
|
||||
}));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -2,9 +2,8 @@
|
||||
|
||||
namespace Amp\Postgres\Test;
|
||||
|
||||
use Amp\{ Loop, Promise, Success };
|
||||
use Amp\Postgres\{ CommandResult, Connection, Statement, Transaction, TupleResult };
|
||||
use Amp\Success;
|
||||
use AsyncInterop\Loop;
|
||||
|
||||
abstract class AbstractPoolTest extends \PHPUnit_Framework_TestCase {
|
||||
/**
|
||||
@ -71,11 +70,11 @@ abstract class AbstractPoolTest extends \PHPUnit_Framework_TestCase {
|
||||
|
||||
$pool = $this->createPool($connections);
|
||||
|
||||
Loop::execute(\Amp\wrap(function () use ($method, $pool, $params, $result) {
|
||||
Loop::run(function () use ($method, $pool, $params, $result) {
|
||||
$return = yield $pool->{$method}(...$params);
|
||||
|
||||
$this->assertSame($result, $return);
|
||||
}));
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
@ -103,13 +102,13 @@ abstract class AbstractPoolTest extends \PHPUnit_Framework_TestCase {
|
||||
$pool = $this->createPool($connections);
|
||||
|
||||
|
||||
Loop::execute(\Amp\wrap(function () Use ($count, $rounds, $pool, $method, $params) {
|
||||
Loop::run(function () Use ($count, $rounds, $pool, $method, $params) {
|
||||
$promises = [];
|
||||
|
||||
for ($i = 0; $i < $count * $rounds; ++$i) {
|
||||
$promises[] = $pool->{$method}(...$params);
|
||||
}
|
||||
}));
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
@ -139,11 +138,11 @@ abstract class AbstractPoolTest extends \PHPUnit_Framework_TestCase {
|
||||
|
||||
$pool = $this->createPool($connections);
|
||||
|
||||
Loop::execute(\Amp\wrap(function () use ($pool, $result) {
|
||||
Loop::run(function () use ($pool, $result) {
|
||||
$return = yield $pool->transaction(Transaction::COMMITTED);
|
||||
$this->assertInstanceOf(Transaction::class, $return);
|
||||
yield $return->rollback();
|
||||
}));
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
@ -169,15 +168,15 @@ abstract class AbstractPoolTest extends \PHPUnit_Framework_TestCase {
|
||||
|
||||
$pool = $this->createPool($connections);
|
||||
|
||||
Loop::execute(\Amp\wrap(function () use ($count, $rounds, $pool) {
|
||||
Loop::run(function () use ($count, $rounds, $pool) {
|
||||
$promises = [];
|
||||
for ($i = 0; $i < $count * $rounds; ++$i) {
|
||||
$promises[] = $pool->transaction(Transaction::COMMITTED);
|
||||
}
|
||||
|
||||
yield \Amp\all(\Amp\map(function (Transaction $transaction) {
|
||||
yield Promise\all(Promise\map(function (Transaction $transaction) {
|
||||
return $transaction->rollback();
|
||||
}, $promises));
|
||||
}));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -2,9 +2,8 @@
|
||||
|
||||
namespace Amp\Postgres\Test;
|
||||
|
||||
use Amp\{ Promise, Success };
|
||||
use Amp\Postgres\ConnectionPool;
|
||||
use Amp\Success;
|
||||
use AsyncInterop\Promise;
|
||||
|
||||
class ConnectionPoolTest extends AbstractPoolTest {
|
||||
/**
|
||||
|
@ -2,8 +2,8 @@
|
||||
|
||||
namespace Amp\Postgres\Test;
|
||||
|
||||
use Amp\Loop;
|
||||
use Amp\Postgres\{ Connection, function connect };
|
||||
use AsyncInterop\Loop;
|
||||
|
||||
class FunctionsTest extends \PHPUnit_Framework_TestCase {
|
||||
public function setUp() {
|
||||
@ -13,36 +13,36 @@ class FunctionsTest extends \PHPUnit_Framework_TestCase {
|
||||
}
|
||||
|
||||
public function testConnect() {
|
||||
Loop::execute(\Amp\wrap(function () {
|
||||
Loop::run(function () {
|
||||
$connection = yield connect('host=localhost user=postgres', 100);
|
||||
$this->assertInstanceOf(Connection::class, $connection);
|
||||
}));
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Amp\Postgres\FailureException
|
||||
*/
|
||||
public function testConnectInvalidUser() {
|
||||
Loop::execute(\Amp\wrap(function () {
|
||||
Loop::run(function () {
|
||||
$connection = yield connect('host=localhost user=invalid', 100);
|
||||
}));
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Amp\Postgres\FailureException
|
||||
*/
|
||||
public function testConnectInvalidConnectionString() {
|
||||
Loop::execute(\Amp\wrap(function () {
|
||||
Loop::run(function () {
|
||||
$connection = yield connect('invalid connection string', 100);
|
||||
}));
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Amp\Postgres\FailureException
|
||||
*/
|
||||
public function testConnectInvalidHost() {
|
||||
Loop::execute(\Amp\wrap(function () {
|
||||
Loop::run(function () {
|
||||
$connection = yield connect('hostaddr=invalid.host user=postgres', 100);
|
||||
}));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user