mirror of
https://github.com/danog/postgres.git
synced 2024-12-12 09:29:57 +01:00
46 lines
1.5 KiB
PHP
46 lines
1.5 KiB
PHP
|
<?php
|
||
|
|
||
|
namespace Amp\Postgres\Test;
|
||
|
|
||
|
use Amp\PHPUnit\TestCase;
|
||
|
use Amp\Postgres\ConnectionConfig;
|
||
|
|
||
|
class ConnectionConfigTest extends TestCase
|
||
|
{
|
||
|
public function testBasicSyntax()
|
||
|
{
|
||
|
$config = ConnectionConfig::fromString("host=localhost port=5434 user=postgres password=test db=test");
|
||
|
|
||
|
$this->assertSame($config->getHost(), "localhost");
|
||
|
$this->assertSame($config->getPort(), 5434);
|
||
|
$this->assertSame($config->getUser(), "postgres");
|
||
|
$this->assertSame($config->getPassword(), "test");
|
||
|
$this->assertSame($config->getDatabase(), "test");
|
||
|
}
|
||
|
|
||
|
public function testAlternativeSyntax()
|
||
|
{
|
||
|
$config = ConnectionConfig::fromString("host=localhost;port=5434;user=postgres;password=test;db=test");
|
||
|
|
||
|
$this->assertSame($config->getHost(), "localhost");
|
||
|
$this->assertSame($config->getPort(), 5434);
|
||
|
$this->assertSame($config->getUser(), "postgres");
|
||
|
$this->assertSame($config->getPassword(), "test");
|
||
|
$this->assertSame($config->getDatabase(), "test");
|
||
|
}
|
||
|
|
||
|
public function testNoHost()
|
||
|
{
|
||
|
$this->expectException(\Error::class);
|
||
|
$this->expectExceptionMessage("Host must be provided in connection string");
|
||
|
$config = ConnectionConfig::fromString("user=postgres");
|
||
|
}
|
||
|
|
||
|
public function testInvalidString()
|
||
|
{
|
||
|
$this->expectException(\Error::class);
|
||
|
$this->expectExceptionMessage("Host must be provided in connection string");
|
||
|
$config = ConnectionConfig::fromString("invalid connection string");
|
||
|
}
|
||
|
}
|