From fc67c056114ba0b018b60151e0be9c1d5505cbd2 Mon Sep 17 00:00:00 2001 From: Matthew Peveler Date: Thu, 3 Oct 2024 17:27:09 +0200 Subject: [PATCH] Fix using schema option with connection option --- src/Phinx/Db/Adapter/PostgresAdapter.php | 4 ++-- tests/Phinx/Db/Adapter/PostgresAdapterTest.php | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) 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();