Skip to content
This repository has been archived by the owner on Jan 29, 2020. It is now read-only.

Commit

Permalink
Merge pull request #36 from weierophinney/hotfix/skip-unseeded-plugin…
Browse files Browse the repository at this point in the history
…-managers

Do not raise an exception if a given plugin manager is not defined.
  • Loading branch information
weierophinney committed Jul 11, 2017
2 parents 77e20c0 + a4247e1 commit d930333
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 4 deletions.
6 changes: 2 additions & 4 deletions src/Listener/ServiceListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -199,10 +199,8 @@ public function onLoadModulesPost(ModuleEvent $e)

if (! $sm['service_manager'] instanceof ServiceManager) {
if (! $this->defaultServiceManager->has($sm['service_manager'])) {
throw new Exception\RuntimeException(sprintf(
'Could not find a valid ServiceManager for %s',
$sm['service_manager']
));
// No plugin manager registered by that name; nothing to configure.
continue;
}

$instance = $this->defaultServiceManager->get($sm['service_manager']);
Expand Down
29 changes: 29 additions & 0 deletions test/Listener/ServiceListenerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -398,4 +398,33 @@ public function testListenerCanOverrideServicesInServiceManagers()
$this->assertEquals(['foo' => 'bar'], $services->get('config'), 'Config service was not overridden');
$this->assertInstanceOf(stdClass::class, $services->get('foo'), 'Foo service was not overridden');
}

public function testOnLoadModulesPostShouldNotRaiseExceptionIfNamedServiceManagerDoesNotExist()
{
$services = new ServiceManager();
$services->setService('config', []);
$listener = new ServiceListener($services);
$listener->addServiceManager(
'UndefinedPluginManager',
'undefined',
TestAsset\UndefinedProviderInterface::class,
'getUndefinedConfig'
);

$module = new TestAsset\ServiceProviderModule([]);

$event = new ModuleEvent();
$configListener = new ConfigListener();
$event->setConfigListener($configListener);

$event->setModule($module);
$listener->onLoadModule($event);

try {
$listener->onLoadModulesPost($event);
$this->assertFalse($services->has('UndefinedPluginManager'));
} catch (\Exception $e) {
$this->fail('Exception should not be raised when encountering unknown plugin manager services');
}
}
}
13 changes: 13 additions & 0 deletions test/Listener/TestAsset/UndefinedProviderInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php
/**
* @link http://github.com/zendframework/zend-modulemanager for the canonical source repository
* @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/

namespace ZendTest\ModuleManager\Listener\TestAsset;

interface UndefinedProviderInterface
{
public function getUndefinedConfig();
}

0 comments on commit d930333

Please sign in to comment.