From 493eae2a42ea5f910d79a4ada95fbc7f477c7144 Mon Sep 17 00:00:00 2001 From: Matthew Peveler Date: Tue, 29 Sep 2020 22:23:06 +0000 Subject: [PATCH 1/3] trigger deprecation notice when using default_database Signed-off-by: Matthew Peveler --- src/Phinx/Config/Config.php | 1 + tests/Phinx/Config/ConfigTest.php | 14 ++++++++++++++ 2 files changed, 15 insertions(+) diff --git a/src/Phinx/Config/Config.php b/src/Phinx/Config/Config.php index 6ab4b8917..b73cf5516 100644 --- a/src/Phinx/Config/Config.php +++ b/src/Phinx/Config/Config.php @@ -214,6 +214,7 @@ public function getDefaultEnvironment() // deprecated: to be removed 0.13 if (isset($this->values['environments']['default_database'])) { + trigger_error('default_database in the config has been deprecated since 0.12, use default_environment instead.', E_USER_DEPRECATED); $this->values['environments']['default_environment'] = $this->values['environments']['default_database']; } diff --git a/tests/Phinx/Config/ConfigTest.php b/tests/Phinx/Config/ConfigTest.php index 1f3022e9d..c6a6f21fe 100644 --- a/tests/Phinx/Config/ConfigTest.php +++ b/tests/Phinx/Config/ConfigTest.php @@ -102,6 +102,20 @@ public function testGetDefaultEnvironmentUsingDatabaseKey() $this->assertEquals('production', $config->getDefaultEnvironment()); } + /** + * @covers \Phinx\Config\Config::getDefaultEnvironment + */ + public function testDeprecatedDefaultDatabase() + { + $configArray = $this->getConfigArray(); + $configArray['environments']['default_database'] = 'production'; + $config = new Config($configArray); + + $this->expectDeprecation(); + $this->expectExceptionMessage('default_database in the config has been deprecated since 0.12, use default_environment instead.'); + $this->assertEquals('production', $config->getDefaultEnvironment()); + } + /** * @covers \Phinx\Config\Config::offsetGet * @covers \Phinx\Config\Config::offsetSet From 7472aee61c36989163b56721e781da63b63ecbe8 Mon Sep 17 00:00:00 2001 From: Matthew Peveler Date: Tue, 29 Sep 2020 22:27:46 +0000 Subject: [PATCH 2/3] replace remaining instances of default_database Signed-off-by: Matthew Peveler --- tests/Phinx/Config/ConfigTest.php | 2 +- tests/Phinx/Console/Command/MigrateTest.php | 2 +- tests/Phinx/Console/Command/SeedRunTest.php | 2 +- tests/Phinx/Console/Command/StatusTest.php | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/Phinx/Config/ConfigTest.php b/tests/Phinx/Config/ConfigTest.php index c6a6f21fe..cafe3f6ef 100644 --- a/tests/Phinx/Config/ConfigTest.php +++ b/tests/Phinx/Config/ConfigTest.php @@ -97,7 +97,7 @@ public function testReturnsEmptyArrayWithEmptyDataDomain() public function testGetDefaultEnvironmentUsingDatabaseKey() { $configArray = $this->getConfigArray(); - $configArray['environments']['default_database'] = 'production'; + $configArray['environments']['default_environment'] = 'production'; $config = new Config($configArray); $this->assertEquals('production', $config->getDefaultEnvironment()); } diff --git a/tests/Phinx/Console/Command/MigrateTest.php b/tests/Phinx/Console/Command/MigrateTest.php index f26615163..8d13dc9db 100644 --- a/tests/Phinx/Console/Command/MigrateTest.php +++ b/tests/Phinx/Console/Command/MigrateTest.php @@ -98,7 +98,7 @@ public function testExecuteWithDsn() ], 'environments' => [ 'default_migration_table' => 'phinxlog', - 'default_database' => 'development', + 'default_environment' => 'development', 'development' => [ 'dsn' => 'mysql://fakehost:3006/development', ], diff --git a/tests/Phinx/Console/Command/SeedRunTest.php b/tests/Phinx/Console/Command/SeedRunTest.php index f3b389f66..a9f37d6c5 100644 --- a/tests/Phinx/Console/Command/SeedRunTest.php +++ b/tests/Phinx/Console/Command/SeedRunTest.php @@ -97,7 +97,7 @@ public function testExecuteWithDsn() ], 'environments' => [ 'default_migration_table' => 'phinxlog', - 'default_database' => 'development', + 'default_environment' => 'development', 'development' => [ 'dsn' => 'mysql://fakehost:3006/development', ], diff --git a/tests/Phinx/Console/Command/StatusTest.php b/tests/Phinx/Console/Command/StatusTest.php index 7cdc65414..4911f9f0b 100644 --- a/tests/Phinx/Console/Command/StatusTest.php +++ b/tests/Phinx/Console/Command/StatusTest.php @@ -111,7 +111,7 @@ public function testExecuteWithDsn() ], 'environments' => [ 'default_migration_table' => 'phinxlog', - 'default_database' => 'development', + 'default_environment' => 'development', 'development' => [ 'dsn' => 'pgsql://fakehost:5433/development', ], From 2b47af4658f66535d3426168afbeac6cc8681530 Mon Sep 17 00:00:00 2001 From: Matthew Peveler Date: Wed, 30 Sep 2020 21:30:54 +0000 Subject: [PATCH 3/3] add additional testcase --- tests/Phinx/Config/ConfigTest.php | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/tests/Phinx/Config/ConfigTest.php b/tests/Phinx/Config/ConfigTest.php index cafe3f6ef..435c7b5ff 100644 --- a/tests/Phinx/Config/ConfigTest.php +++ b/tests/Phinx/Config/ConfigTest.php @@ -105,7 +105,25 @@ public function testGetDefaultEnvironmentUsingDatabaseKey() /** * @covers \Phinx\Config\Config::getDefaultEnvironment */ - public function testDeprecatedDefaultDatabase() + public function testGetDefaultEnvironmentUsingDefaultDatabase() + { + $configArray = $this->getConfigArray(); + $configArray['environments']['default_database'] = 'production'; + $config = new Config($configArray); + + $errorReporting = error_reporting(); + try { + error_reporting(E_ALL ^ E_USER_DEPRECATED); + $this->assertEquals('production', $config->getDefaultEnvironment()); + } finally { + error_reporting($errorReporting); + } + } + + /** + * @covers \Phinx\Config\Config::getDefaultEnvironment + */ + public function testDefaultDatabaseThrowsDeprecatedNotice() { $configArray = $this->getConfigArray(); $configArray['environments']['default_database'] = 'production'; @@ -113,7 +131,7 @@ public function testDeprecatedDefaultDatabase() $this->expectDeprecation(); $this->expectExceptionMessage('default_database in the config has been deprecated since 0.12, use default_environment instead.'); - $this->assertEquals('production', $config->getDefaultEnvironment()); + $config->getDefaultEnvironment(); } /**