Skip to content

Commit

Permalink
Merge pull request #127 from daniel-de-wit/main
Browse files Browse the repository at this point in the history
Support connect_via_database
  • Loading branch information
freekmurze authored Oct 19, 2022
2 parents 48ed4e7 + 74c25bf commit ef33182
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/DbDumperFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,11 @@ public static function createForConnection(string $connectionName): DbDumper
$fallback
);

$dbName = $dbConfig['connect_via_database'] ?? $dbConfig['database'];

$dbDumper = static::forDriver($dbConfig['driver'])
->setHost($dbHost ?? '')
->setDbName($dbConfig['database'])
->setDbName($dbName)
->setUserName($dbConfig['username'] ?? '')
->setPassword($dbConfig['password'] ?? '');

Expand Down
19 changes: 19 additions & 0 deletions tests/DbDumperFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,25 @@ public function it_will_use_the_read_db_when_one_is_defined()
$this->assertEquals('localhost-read', $dumper->getHost());
}

/** @test */
public function it_will_use_connect_via_database_when_one_is_defined()
{
$dbConfig = [
'driver' => 'pgsql',
'connect_via_database' => 'connection_pool',
'username' => 'root',
'password' => 'myPassword',
'database' => 'myDb',
'dump' => ['add_extra_option' => '--extra-option=value'],
];

$this->app['config']->set('database.connections.pgsql', $dbConfig);

$dumper = DbDumperFactory::createForConnection('pgsql');

$this->assertEquals('connection_pool', $dumper->getDbName());
}

/** @test */
public function it_will_throw_an_exception_when_creating_an_unknown_type_of_dumper()
{
Expand Down

0 comments on commit ef33182

Please sign in to comment.