Skip to content

Commit fc8597b

Browse files
authored
Better check for invalid config (#41)
* Better check for invalid config * Added changelog
1 parent 39612b7 commit fc8597b

File tree

4 files changed

+44
-2
lines changed

4 files changed

+44
-2
lines changed

Changelog.md

+7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# Changelog
22

3+
## 2.1.1
4+
5+
### Fixed
6+
7+
- Allow to only use "dsn" without configure "type".
8+
- Add better error message when both "dsn" and "type" is missing.
9+
310
## 2.1.0
411

512
### Added

DependencyInjection/Configuration.php

+8-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,14 @@ public function getConfigTreeBuilder()
6262
->validate()
6363
->ifTrue(function ($databases) {
6464
$valid = true;
65-
foreach ($databases as $d) {
65+
foreach ($databases as $name => $d) {
66+
if (isset($d['dsn'])) {
67+
// "Fake" "type" for now.
68+
$d['type'] = substr($d['dsn'], 0, strpos($d['dsn'], ':'));
69+
}
70+
if (!isset($d['type'])) {
71+
throw new InvalidConfigurationException(sprintf('You must define a "type" or "dsn" for database "%s"', $name));
72+
}
6673
if ($d['type'] !== 'mysql') {
6774
// If not "mysql" we have to make sure these parameter are set to default
6875
$valid = $valid && empty($d['ignoreTables']) && empty($d['ssl']) && empty($d['singleTransaction']);

Tests/Unit/DependencyInjection/BMBackupManagerExtensionTest.php

-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ public function testReplacementOfConfig()
3333
$this->assertContainerBuilderHasServiceDefinitionWithArgument('backup_manager.config_database', 0, $dbConfig);
3434
}
3535

36-
3736
public function testDsn()
3837
{
3938
$storageConfig = ['local'=>['type'=>'Local', 'root'=>'/foo']];

Tests/Unit/DependencyInjection/ConfigurationTest.php

+29
Original file line numberDiff line numberDiff line change
@@ -134,4 +134,33 @@ public function testSingleTransactionOnValid()
134134
)
135135
);
136136
}
137+
138+
public function testDsn()
139+
{
140+
$this->assertConfigurationIsInvalid(array(
141+
[
142+
'database'=>[
143+
'dev'=>[
144+
'dsn' => 'pgsql://root:[email protected]:5432/test_db',
145+
'singleTransaction' => true,
146+
],
147+
],
148+
]
149+
)
150+
);
151+
}
152+
public function testNoType()
153+
{
154+
$this->assertConfigurationIsInvalid(array(
155+
[
156+
'database'=>[
157+
'dev'=>[
158+
159+
],
160+
],
161+
]
162+
),
163+
'You must define a "type" or "dsn" for database "dev"'
164+
);
165+
}
137166
}

0 commit comments

Comments
 (0)