Skip to content

Commit 6801d53

Browse files
authored
Make sure we can use the bundle with no config. (#37)
This will fix #34
1 parent 130ebc3 commit 6801d53

File tree

5 files changed

+29
-11
lines changed

5 files changed

+29
-11
lines changed

DependencyInjection/BMBackupManagerExtension.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ public function load(array $configs, ContainerBuilder $container)
2727

2828
$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
2929
$loader->load('services.yml');
30+
$config['storage'] = isset($config['storage']) ? $config['storage'] : [];
31+
$config['database'] = isset($config['database']) ? $config['database'] : [];
3032
$this->validateStorage($config['storage']);
3133

3234
$managerIdMap = [

DependencyInjection/Configuration.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public function getConfigTreeBuilder()
5858

5959
->end() // End storage
6060

61-
->arrayNode('database')->isRequired()
61+
->arrayNode('database')
6262
->validate()
6363
->ifTrue(function ($databases) {
6464
$valid = true;

Tests/Functional/BundleInitializationTest.php

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use BackupManager\Manager;
66
use BM\BackupManagerBundle\BMBackupManagerBundle;
77
use Nyholm\BundleTest\BaseBundleTestCase;
8+
use Nyholm\BundleTest\CompilerPass\PublicServicePass;
89

910
class BundleInitializationTest extends BaseBundleTestCase
1011
{
@@ -13,14 +14,20 @@ protected function getBundleClass()
1314
return BMBackupManagerBundle::class;
1415
}
1516

17+
protected function setUp()
18+
{
19+
$this->addCompilerPass(new PublicServicePass('|backup_manager.*|'));
20+
$this->addCompilerPass(new PublicServicePass('|backup_manager|'));
21+
}
22+
23+
1624
public function testInitBundle()
1725
{
1826
// Create a new Kernel
1927
$kernel = $this->createKernel();
2028

2129
// Add some configuration
2230
$kernel->addConfigFile(__DIR__.'/config/minimal.yml');
23-
$kernel->addConfigFile(__DIR__.'/config/public_services.yml');
2431

2532
// Boot the kernel.
2633
$this->bootKernel();
@@ -29,8 +36,22 @@ public function testInitBundle()
2936
$container = $this->getContainer();
3037

3138
// Test if you services exists
32-
$this->assertTrue($container->has('test.backup_manager'));
33-
$service = $container->get('test.backup_manager');
39+
$this->assertTrue($container->has('backup_manager'));
40+
$service = $container->get('backup_manager');
41+
$this->assertInstanceOf(Manager::class, $service);
42+
}
43+
44+
public function testNoConfig()
45+
{
46+
// Boot the kernel.
47+
$this->bootKernel();
48+
49+
// Get the container
50+
$container = $this->getContainer();
51+
52+
// Test if you services exists
53+
$this->assertTrue($container->has('backup_manager'));
54+
$service = $container->get('backup_manager');
3455
$this->assertInstanceOf(Manager::class, $service);
3556
}
3657

@@ -43,12 +64,11 @@ public function testNoDependencies()
4364

4465
// Add some configuration
4566
$kernel->addConfigFile(__DIR__.'/config/rackspace.yml');
46-
$kernel->addConfigFile(__DIR__.'/config/public_services.yml');
4767

4868
// Boot the kernel.
4969
$this->bootKernel();
5070

5171
// Get the container
5272
$container = $this->getContainer();
5373
}
54-
}
74+
}

Tests/Functional/config/public_services.yml

Lines changed: 0 additions & 4 deletions
This file was deleted.

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"require-dev": {
2525
"matthiasnoback/symfony-dependency-injection-test": "^1.2 || ^2.3",
2626
"matthiasnoback/symfony-config-test": "^2.2 || ^3.1",
27-
"nyholm/symfony-bundle-test": "^1.2",
27+
"nyholm/symfony-bundle-test": "^1.3.1",
2828
"symfony/phpunit-bridge": "^3.4 || ^4.0"
2929
},
3030
"suggest": {

0 commit comments

Comments
 (0)