1
0
mirror of https://github.com/danog/postgres.git synced 2024-12-02 17:37:57 +01:00
postgres/test/FunctionsTest.php

49 lines
1.4 KiB
PHP
Raw Normal View History

2016-12-30 06:21:17 +01:00
<?php
2016-09-14 16:27:39 +02:00
namespace Amp\Postgres\Test;
use Amp\Postgres\{ Connection, function connect };
use AsyncInterop\Loop;
2016-09-14 16:27:39 +02:00
2016-09-20 07:47:16 +02:00
class FunctionsTest extends \PHPUnit_Framework_TestCase {
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() {
Loop::execute(\Amp\wrap(function () {
2016-09-14 16:27:39 +02:00
$connection = yield connect('host=localhost user=postgres', 1);
$this->assertInstanceOf(Connection::class, $connection);
}));
2016-09-14 16:27:39 +02:00
}
/**
* @expectedException \Amp\Postgres\FailureException
*/
public function testConnectInvalidUser() {
Loop::execute(\Amp\wrap(function () {
2016-09-14 16:27:39 +02:00
$connection = yield connect('host=localhost user=invalid', 1);
}));
2016-09-14 16:27:39 +02:00
}
/**
* @expectedException \Amp\Postgres\FailureException
*/
public function testConnectInvalidConnectionString() {
Loop::execute(\Amp\wrap(function () {
2016-09-14 16:27:39 +02:00
$connection = yield connect('invalid connection string', 1);
}));
2016-09-14 16:27:39 +02:00
}
/**
* @expectedException \Amp\Postgres\FailureException
*/
public function testConnectInvalidHost() {
Loop::execute(\Amp\wrap(function () {
2016-09-14 16:27:39 +02:00
$connection = yield connect('hostaddr=invalid.host user=postgres', 1);
}));
2016-09-14 16:27:39 +02:00
}
}