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

Do not raise an exception if a given plugin manager is not defined. #36

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
}