Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions core/DB/PgSQL.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,18 @@ public function connect()
.($this->basename ? " dbname={$this->basename}" : null)
.($this->port ? " port={$this->port}" : null);

if ($this->persistent)
$this->link = pg_pconnect($conn);
else
$this->link = pg_connect($conn);

if (!$this->link)
try {
if ($this->persistent)
$this->link = pg_pconnect($conn);
else
$this->link = pg_connect($conn);
} catch (Exception $e) {
throw new DatabaseException(
'can not connect to PostgreSQL server: '.pg_errormessage()
'can not connect to PostgreSQL server: '.$e->getMessage(),
$e->getCode(),
$e
);
}

if ($this->encoding)
$this->setDbEncoding();
Expand Down
30 changes: 30 additions & 0 deletions test/core/DbConnectionTest.class.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

final class DbConnectionTest extends TestCase
{
public function setUp()
{
DBPool::me()->
addLink(
'badLink',
DB::spawn('PinbedPgSQL', 'postgres', '', 'localhost', 'wrongDatabase')
);
}

public function testPostgresql()
{
try {
$link = DBPool::me()->getLink('badLink');
$this->assertFalse(true, 'Unreachable code');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

<?php
$this->fail('Unreachable code');

капельку наглядней должно быть

} catch(Exception $e) {
$this->assertInstanceOf('DatabaseException', $e);
}
}

public function tearDown()
{
DBPool::me()->dropLink('badLink');
}
}

?>