diff --git a/src/Phinx/Db/Adapter/PostgresAdapter.php b/src/Phinx/Db/Adapter/PostgresAdapter.php index 771b6e8d5..44a8886db 100644 --- a/src/Phinx/Db/Adapter/PostgresAdapter.php +++ b/src/Phinx/Db/Adapter/PostgresAdapter.php @@ -70,12 +70,12 @@ class PostgresAdapter extends PdoAdapter */ public function setOptions(array $options): AdapterInterface { - parent::setOptions($options); - if (!empty($options['schema'])) { $this->schema = $options['schema']; } + parent::setOptions($options); + return $this; } diff --git a/tests/Phinx/Db/Adapter/PostgresAdapterTest.php b/tests/Phinx/Db/Adapter/PostgresAdapterTest.php index f467c3f1e..a43039615 100644 --- a/tests/Phinx/Db/Adapter/PostgresAdapterTest.php +++ b/tests/Phinx/Db/Adapter/PostgresAdapterTest.php @@ -148,6 +148,21 @@ public function testConnectionWithSchema() $this->assertTrue($adapter->hasTable('foo.' . $adapter->getSchemaTableName())); } + public function testConnectionWithSchemaAndConnection() + { + $this->adapter->connect(); + $this->adapter->createSchema('foo'); + + $options = [ + 'schema' => 'foo', + 'connection' => $this->adapter->getConnection(), + 'name' => PGSQL_DB_CONFIG['name'], + ]; + $adapter = new PostgresAdapter($options, new ArrayInput([]), new NullOutput()); + $adapter->connect(); + $this->assertTrue($adapter->hasTable('foo.' . $adapter->getSchemaTableName())); + } + public function testCreatingTheSchemaTableOnConnect() { $this->adapter->connect();