2016-12-30 06:21:17 +01:00
|
|
|
<?php
|
2016-09-14 16:27:39 +02:00
|
|
|
|
|
|
|
namespace Amp\Postgres\Test;
|
|
|
|
|
2017-03-17 16:17:24 +01:00
|
|
|
use Amp\Loop;
|
2017-05-17 18:14:12 +02:00
|
|
|
use Amp\Postgres\{ Connection, function connect };
|
2017-05-26 17:47:44 +02:00
|
|
|
use PHPUnit\Framework\TestCase;
|
2016-09-14 16:27:39 +02:00
|
|
|
|
2017-05-26 17:47:44 +02:00
|
|
|
class FunctionsTest extends TestCase {
|
2016-09-20 07:47:16 +02:00
|
|
|
public function setUp() {
|
|
|
|
if (!\extension_loaded('pgsql') && !\extension_loaded('pq')) {
|
|
|
|
$this->markTestSkipped('This test requires either ext/pgsql or pecl/pq');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-14 16:27:39 +02:00
|
|
|
public function testConnect() {
|
2017-03-17 16:17:24 +01:00
|
|
|
Loop::run(function () {
|
2017-02-16 00:36:10 +01:00
|
|
|
$connection = yield connect('host=localhost user=postgres', 100);
|
2016-09-14 16:27:39 +02:00
|
|
|
$this->assertInstanceOf(Connection::class, $connection);
|
2017-03-17 16:17:24 +01:00
|
|
|
});
|
2016-09-14 16:27:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @expectedException \Amp\Postgres\FailureException
|
|
|
|
*/
|
|
|
|
public function testConnectInvalidUser() {
|
2017-03-17 16:17:24 +01:00
|
|
|
Loop::run(function () {
|
2017-02-16 00:36:10 +01:00
|
|
|
$connection = yield connect('host=localhost user=invalid', 100);
|
2017-03-17 16:17:24 +01:00
|
|
|
});
|
2016-09-14 16:27:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @expectedException \Amp\Postgres\FailureException
|
|
|
|
*/
|
|
|
|
public function testConnectInvalidConnectionString() {
|
2017-03-17 16:17:24 +01:00
|
|
|
Loop::run(function () {
|
2017-02-16 00:36:10 +01:00
|
|
|
$connection = yield connect('invalid connection string', 100);
|
2017-03-17 16:17:24 +01:00
|
|
|
});
|
2016-09-14 16:27:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @expectedException \Amp\Postgres\FailureException
|
|
|
|
*/
|
|
|
|
public function testConnectInvalidHost() {
|
2017-03-17 16:17:24 +01:00
|
|
|
Loop::run(function () {
|
2017-02-16 00:36:10 +01:00
|
|
|
$connection = yield connect('hostaddr=invalid.host user=postgres', 100);
|
2017-03-17 16:17:24 +01:00
|
|
|
});
|
2016-09-14 16:27:39 +02:00
|
|
|
}
|
|
|
|
}
|