Skip to content

Commit f5b8fb5

Browse files
authored
Adding support for ignoreTables (#25)
* Adding support for ignoreTables * Added tests * Remove config key if it was not set * Added docs * Fixed typo
1 parent e7962bd commit f5b8fb5

File tree

4 files changed

+83
-4
lines changed

4 files changed

+83
-4
lines changed

DependencyInjection/Configuration.php

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@ public function getConfigTreeBuilder()
2020
->children()
2121
->variableNode('storage')
2222
->validate()
23-
->always()
24-
->then(function ($storageConfig) {
23+
->always(function ($storageConfig) {
2524
foreach ($storageConfig as $name => $config) {
2625
if (!isset($config['type'])) {
2726
throw new InvalidConfigurationException(sprintf('You must define a "type" for storage "%s"', $name));
@@ -60,6 +59,27 @@ public function getConfigTreeBuilder()
6059
->end() // End storage
6160

6261
->arrayNode('database')->isRequired()
62+
->validate()
63+
->ifTrue(function ($databases) {
64+
$valid = true;
65+
foreach ($databases as $database) {
66+
$valid = $valid && (empty($database['ignoreTables']) || $database['type'] === 'mysql');
67+
}
68+
69+
return !$valid;
70+
})
71+
->thenInvalid('Key "ignoreTables" is only valid on MySQL databases.')
72+
->end()
73+
->validate()
74+
->always(function ($databases) {
75+
foreach ($databases as &$database) {
76+
if (empty($database['ignoreTables'])) {
77+
unset($database['ignoreTables']);
78+
}
79+
}
80+
return $databases;
81+
})
82+
->end()
6383
->prototype('array')
6484
->children()
6585
->scalarNode('type')->end()
@@ -68,6 +88,9 @@ public function getConfigTreeBuilder()
6888
->scalarNode('user')->end()
6989
->scalarNode('pass')->end()
7090
->scalarNode('database')->end()
91+
->arrayNode('ignoreTables')
92+
->scalarPrototype()->end()
93+
->end()
7194
->end()
7295
->end()
7396
->end()

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ bm_backup_manager:
7070
user: root
7171
pass: password
7272
database: test
73+
ignoreTables: ['foo', 'bar']
7374
production:
7475
type: postgresql
7576
host: localhost

Tests/Unit/DependencyInjection/BMBackupManagerExtensionTest.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
<?php
22

3-
43
namespace BM\BackupManagerBundle\Tests\Unit\DependencyInjection;
54

65
use BM\BackupManagerBundle\DependencyInjection\BMBackupManagerExtension;
@@ -22,7 +21,7 @@ protected function getContainerExtensions()
2221

2322
public function testReplacementOfConfig()
2423
{
25-
$storageConfig = ['local'=>['type'=>'local', 'root'=>'/foo']];
24+
$storageConfig = ['local'=>['type'=>'Local', 'root'=>'/foo']];
2625
$dbConfig = ['dev'=>['type'=>'mysql']];
2726

2827
$this->load([
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?php
2+
3+
namespace BM\BackupManagerBundle\Tests\Unit\DependencyInjection;
4+
5+
use BM\BackupManagerBundle\DependencyInjection\Configuration;
6+
use Matthias\SymfonyConfigTest\PhpUnit\ConfigurationTestCaseTrait;
7+
use PHPUnit\Framework\TestCase;
8+
9+
/**
10+
* @author Tobias Nyholm <[email protected]>
11+
*/
12+
class ConfigurationTest extends TestCase
13+
{
14+
use ConfigurationTestCaseTrait;
15+
16+
protected function getConfiguration()
17+
{
18+
return new Configuration();
19+
}
20+
21+
public function testIgnoreTablesGeneratesErrorWhenNotUsingMySQL()
22+
{
23+
$this->assertConfigurationIsInvalid(array(
24+
[
25+
'database'=>[
26+
'dev'=>[
27+
'type' => 'foo',
28+
'ignoreTables'=>['xx', 'yy']
29+
],
30+
'prod'=>[
31+
'type' => 'mysql',
32+
],
33+
],
34+
]
35+
),
36+
'Key "ignoreTables" is only valid on MySQL databases.'
37+
);
38+
}
39+
40+
public function testIgnoreTablesDoesNothingWhenOmitted()
41+
{
42+
$this->assertConfigurationIsValid(array(
43+
[
44+
'database'=>[
45+
'dev'=>[
46+
'type' => 'foo',
47+
],
48+
'prod'=>[
49+
'type' => 'mysql',
50+
],
51+
],
52+
]
53+
)
54+
);
55+
}
56+
}

0 commit comments

Comments
 (0)