Skip to content

Commit

Permalink
Merge pull request #1890 from MasterOdin/deprecated_notice
Browse files Browse the repository at this point in the history
trigger deprecation notice when using default_database
  • Loading branch information
dereuromark authored Sep 30, 2020
2 parents 59f18de + 2b47af4 commit efb0d4d
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/Phinx/Config/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'];
}

Expand Down
34 changes: 33 additions & 1 deletion tests/Phinx/Config/ConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,43 @@ 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());
}

/**
* @covers \Phinx\Config\Config::getDefaultEnvironment
*/
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';
$config = new Config($configArray);

$this->expectDeprecation();
$this->expectExceptionMessage('default_database in the config has been deprecated since 0.12, use default_environment instead.');
$config->getDefaultEnvironment();
}

/**
* @covers \Phinx\Config\Config::offsetGet
* @covers \Phinx\Config\Config::offsetSet
Expand Down
2 changes: 1 addition & 1 deletion tests/Phinx/Console/Command/MigrateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public function testExecuteWithDsn()
],
'environments' => [
'default_migration_table' => 'phinxlog',
'default_database' => 'development',
'default_environment' => 'development',
'development' => [
'dsn' => 'mysql://fakehost:3006/development',
],
Expand Down
2 changes: 1 addition & 1 deletion tests/Phinx/Console/Command/SeedRunTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public function testExecuteWithDsn()
],
'environments' => [
'default_migration_table' => 'phinxlog',
'default_database' => 'development',
'default_environment' => 'development',
'development' => [
'dsn' => 'mysql://fakehost:3006/development',
],
Expand Down
2 changes: 1 addition & 1 deletion tests/Phinx/Console/Command/StatusTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public function testExecuteWithDsn()
],
'environments' => [
'default_migration_table' => 'phinxlog',
'default_database' => 'development',
'default_environment' => 'development',
'development' => [
'dsn' => 'pgsql://fakehost:5433/development',
],
Expand Down

0 comments on commit efb0d4d

Please sign in to comment.