connect( PostgresConnectionConfig::fromString('host=localhost user=postgres'), new TimeoutCancellationToken(100) ); $this->assertInstanceOf(Connection::class, $connection); }); } /** * @depends testConnect * @expectedException \Amp\CancelledException */ public function testConnectCancellationBeforeConnect() { Loop::run(function () { $source = new CancellationTokenSource; $token = $source->getToken(); $source->cancel(); $connection = yield $this->connect(PostgresConnectionConfig::fromString('host=localhost user=postgres'), $token); }); } /** * @depends testConnectCancellationBeforeConnect */ public function testConnectCancellationAfterConnect() { Loop::run(function () { $source = new CancellationTokenSource; $token = $source->getToken(); $connection = yield $this->connect(PostgresConnectionConfig::fromString('host=localhost user=postgres'), $token); $this->assertInstanceOf(Connection::class, $connection); $source->cancel(); }); } /** * @depends testConnectCancellationBeforeConnect * @expectedException \Amp\Sql\FailureException */ public function testConnectInvalidUser() { Loop::run(function () { $connection = yield $this->connect(PostgresConnectionConfig::fromString('host=localhost user=invalid'), new TimeoutCancellationToken(100)); }); } }