Skip to content

Commit

Permalink
Fix dbname key.
Browse files Browse the repository at this point in the history
  • Loading branch information
roquie committed May 5, 2020
1 parent 09832df commit 3637ad6
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 18 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ $config = new Reader([
]
]);
$config->addPacker('pgsql', new KeyValue\Amp\Postgres());
$config->addPacker('pgsql', new KeyValue\Postgres());
$config->getConnectionString($connectionName = 'default');
# host=127.0.0.1,127.0.0.2 port=5432,6432 user=roquie password=secret db=roquie schema=roquie connect_timeout=10 target_session_attrs=any sslmode=require
# host=127.0.0.1,127.0.0.2 port=5432,6432 user=roquie password=secret dbname=roquie schema=roquie connect_timeout=10 target_session_attrs=any sslmode=require
```

Note: Amphp connection string to mysql and postgres clients does not support multiple hosts connection (05-05-2020).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace Spacetab\DbConfig\Packer\KeyValue\Amp;
namespace Spacetab\DbConfig\Packer\KeyValue;

use Spacetab\DbConfig\Packer\AbstractPacker;

Expand All @@ -18,7 +18,7 @@ final class Postgres extends AbstractPacker
public function __invoke(string $connectionName, ?array $config = null): string
{
if (is_null($config)) {
return 'host=127.0.0.1 port=5432 user=postgres db=postgres';
return 'host=127.0.0.1 port=5432 user=postgres dbname=postgres';
}

$name = isset($config['name']) ? $this->validateName($connectionName, $config) : 'postgres';
Expand All @@ -30,10 +30,10 @@ public function __invoke(string $connectionName, ?array $config = null): string
$options = isset($config['options']) ? $this->validateOptions($connectionName, $config) : [];

$chunks = [
'host=' . join(',', $hosts),
'port=' . join(',', $ports),
'user=' . $user,
'db=' . $name
'host=' . join(',', $hosts),
'port=' . join(',', $ports),
'user=' . $user,
'dbname=' . $name
];

if (!is_null($pass)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace Spacetab\Tests\DbConfig\Packer\KeyValue\Amp;
namespace Spacetab\Tests\DbConfig\Packer\KeyValue;

use PHPUnit\Framework\TestCase;
use Spacetab\DbConfig\Packer\KeyValue;
Expand All @@ -11,10 +11,10 @@ class PostgresTest extends TestCase
{
public function testPackerReturnsDefaultConnStringIfConfigIsNull()
{
$packer = new KeyValue\Amp\Postgres();
$packer = new KeyValue\Postgres();
$string = $packer('default', null);

$this->assertSame('host=127.0.0.1 port=5432 user=postgres db=postgres', $string);
$this->assertSame('host=127.0.0.1 port=5432 user=postgres dbname=postgres', $string);
}

public function invalidValuesProvider()
Expand All @@ -39,7 +39,7 @@ public function invalidValuesProvider()
*/
public function testPackerThrowsAnExceptionIfProvidedInvalidValues(array $values)
{
$packer = new KeyValue\Amp\Postgres();
$packer = new KeyValue\Postgres();

$this->expectException(\InvalidArgumentException::class);

Expand All @@ -48,7 +48,7 @@ public function testPackerThrowsAnExceptionIfProvidedInvalidValues(array $values

public function testMultiServerConfiguration()
{
$packer = new KeyValue\Amp\Postgres();
$packer = new KeyValue\Postgres();
$string = $packer('default', [
'host' => ['127.0.0.1', '127.0.0.2'],
'port' => [5432, 6432],
Expand All @@ -61,7 +61,7 @@ public function testMultiServerConfiguration()
],
]);

$valid = 'host=127.0.0.1,127.0.0.2 port=5432,6432 user=roquie db=postgres password=secret schema=postgres sslmode=require connect_timeout=10';
$valid = 'host=127.0.0.1,127.0.0.2 port=5432,6432 user=roquie dbname=postgres password=secret schema=postgres sslmode=require connect_timeout=10';
$this->assertSame($valid, $string);
}
}
8 changes: 4 additions & 4 deletions tests/ReaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ public function testUnusedConnectionName()
public function testWhereItReturnsConnectionStringIfPackerExistsButOptionsNot()
{
$reader = new Reader();
$reader->addPacker('pgsql', new KeyValue\Amp\Postgres());
$reader->addPacker('pgsql', new KeyValue\Postgres());

$this->assertSame('host=127.0.0.1 port=5432 user=postgres db=postgres', $reader->getConnectionString());
$this->assertSame('host=127.0.0.1 port=5432 user=postgres dbname=postgres', $reader->getConnectionString());
}

public function testWhereItReturnsConnectionStringIfPackerExistsWithOptions()
Expand All @@ -53,8 +53,8 @@ public function testWhereItReturnsConnectionStringIfPackerExistsWithOptions()
'type' => 'pgsql',
]
]);
$reader->addPacker('pgsql', new KeyValue\Amp\Postgres());
$reader->addPacker('pgsql', new KeyValue\Postgres());

$this->assertSame('host=127.0.0.1 port=5432 user=postgres db=postgres', $reader->getConnectionString());
$this->assertSame('host=127.0.0.1 port=5432 user=postgres dbname=postgres', $reader->getConnectionString());
}
}

0 comments on commit 3637ad6

Please sign in to comment.