From 04a6463888e4060469cf3a29fd1805b22c5dfbc3 Mon Sep 17 00:00:00 2001 From: Aaron Piotrowski Date: Fri, 17 Mar 2017 10:17:24 -0500 Subject: [PATCH] Update for async-interop merge and other Amp changes --- composer.json | 3 +- example/basic.php | 4 +- example/listen.php | 8 ++-- lib/AbstractConnection.php | 7 ++-- lib/AbstractPool.php | 9 ++--- lib/AggregatePool.php | 2 +- lib/Connection.php | 6 +-- lib/ConnectionPool.php | 2 +- lib/Executor.php | 10 ++--- lib/Listener.php | 7 ++-- lib/PgSqlConnection.php | 7 ++-- lib/PgSqlExecutor.php | 5 +-- lib/PgSqlStatement.php | 4 +- lib/PqConnection.php | 7 ++-- lib/PqExecutor.php | 7 ++-- lib/PqStatement.php | 7 ++-- lib/PqUnbufferedResult.php | 2 +- lib/Statement.php | 4 +- lib/Transaction.php | 13 +++---- lib/functions.php | 4 +- test/AbstractConnectionTest.php | 69 ++++++++++++++++----------------- test/AbstractPoolTest.php | 21 +++++----- test/ConnectionPoolTest.php | 3 +- test/FunctionsTest.php | 18 ++++----- 24 files changed, 108 insertions(+), 121 deletions(-) diff --git a/composer.json b/composer.json index 688ae9a..fb805ee 100644 --- a/composer.json +++ b/composer.json @@ -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": { diff --git a/example/basic.php b/example/basic.php index 8be444c..b631a48 100644 --- a/example/basic.php +++ b/example/basic.php @@ -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']); } -})); +}); diff --git a/example/listen.php b/example/listen.php index 0f1ea9f..01528ed 100644 --- a/example/listen.php +++ b/example/listen.php @@ -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 ); } -})); +}); diff --git a/lib/AbstractConnection.php b/lib/AbstractConnection.php index f5c6cb2..a18ea98 100644 --- a/lib/AbstractConnection.php +++ b/lib/AbstractConnection.php @@ -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); diff --git a/lib/AbstractPool.php b/lib/AbstractPool.php index 5f9b6f1..b736489 100644 --- a/lib/AbstractPool.php +++ b/lib/AbstractPool.php @@ -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 */ diff --git a/lib/AggregatePool.php b/lib/AggregatePool.php index a4197ff..19fca6a 100644 --- a/lib/AggregatePool.php +++ b/lib/AggregatePool.php @@ -2,7 +2,7 @@ namespace Amp\Postgres; -use AsyncInterop\Promise; +use Amp\Promise; class AggregatePool extends AbstractPool { /** diff --git a/lib/Connection.php b/lib/Connection.php index dc9cdeb..550ab7e 100644 --- a/lib/Connection.php +++ b/lib/Connection.php @@ -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 */ diff --git a/lib/ConnectionPool.php b/lib/ConnectionPool.php index 0d2d389..10c2b3b 100644 --- a/lib/ConnectionPool.php +++ b/lib/ConnectionPool.php @@ -2,7 +2,7 @@ namespace Amp\Postgres; -use AsyncInterop\Promise; +use Amp\Promise; class ConnectionPool extends AbstractPool { const DEFAULT_MAX_CONNECTIONS = 100; diff --git a/lib/Executor.php b/lib/Executor.php index d62324a..1d168f7 100644 --- a/lib/Executor.php +++ b/lib/Executor.php @@ -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; } diff --git a/lib/Listener.php b/lib/Listener.php index 4f360de..3334bc5 100644 --- a/lib/Listener.php +++ b/lib/Listener.php @@ -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(); diff --git a/lib/PgSqlConnection.php b/lib/PgSqlConnection.php index 9b524a4..c3be2c6 100644 --- a/lib/PgSqlConnection.php +++ b/lib/PgSqlConnection.php @@ -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) { diff --git a/lib/PgSqlExecutor.php b/lib/PgSqlExecutor.php index c4b6539..59fd2f3 100644 --- a/lib/PgSqlExecutor.php +++ b/lib/PgSqlExecutor.php @@ -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 */ diff --git a/lib/PgSqlStatement.php b/lib/PgSqlStatement.php index e7b3f8c..f7730df 100644 --- a/lib/PgSqlStatement.php +++ b/lib/PgSqlStatement.php @@ -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. */ diff --git a/lib/PqConnection.php b/lib/PqConnection.php index 35ee5ed..dd55c21 100644 --- a/lib/PqConnection.php +++ b/lib/PqConnection.php @@ -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) { diff --git a/lib/PqExecutor.php b/lib/PqExecutor.php index 2effca0..0fb190d 100644 --- a/lib/PqExecutor.php +++ b/lib/PqExecutor.php @@ -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 */ diff --git a/lib/PqStatement.php b/lib/PqStatement.php index 65b2930..7047927 100644 --- a/lib/PqStatement.php +++ b/lib/PqStatement.php @@ -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. */ diff --git a/lib/PqUnbufferedResult.php b/lib/PqUnbufferedResult.php index d694534..11c67b5 100644 --- a/lib/PqUnbufferedResult.php +++ b/lib/PqUnbufferedResult.php @@ -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) { diff --git a/lib/Statement.php b/lib/Statement.php index 47dc553..0a755df 100644 --- a/lib/Statement.php +++ b/lib/Statement.php @@ -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; } diff --git a/lib/Transaction.php b/lib/Transaction.php index 841f189..3d2a1b5 100644 --- a/lib/Transaction.php +++ b/lib/Transaction.php @@ -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 */ diff --git a/lib/functions.php b/lib/functions.php index 0aa6bc1..56196e0 100644 --- a/lib/functions.php +++ b/lib/functions.php @@ -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. diff --git a/test/AbstractConnectionTest.php b/test/AbstractConnectionTest.php index ad29dc4..20e598d 100644 --- a/test/AbstractConnectionTest.php +++ b/test/AbstractConnectionTest.php @@ -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); - })); + }); } } diff --git a/test/AbstractPoolTest.php b/test/AbstractPoolTest.php index d6cafb7..906d1bf 100644 --- a/test/AbstractPoolTest.php +++ b/test/AbstractPoolTest.php @@ -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)); - })); + }); } } diff --git a/test/ConnectionPoolTest.php b/test/ConnectionPoolTest.php index d2a989d..8fa7d66 100644 --- a/test/ConnectionPoolTest.php +++ b/test/ConnectionPoolTest.php @@ -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 { /** diff --git a/test/FunctionsTest.php b/test/FunctionsTest.php index 3f823e9..bbb7550 100644 --- a/test/FunctionsTest.php +++ b/test/FunctionsTest.php @@ -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); - })); + }); } }