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

Commit

Permalink
Merge branch 'hotfix/5146'
Browse files Browse the repository at this point in the history
  • Loading branch information
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/Listener/LocatorRegistrationListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,12 @@ public function onLoadModules(Event $e)
// Shared instance for module manager
$events->attach('Zend\Mvc\Application', MvcEvent::EVENT_BOOTSTRAP, function ($e) use ($moduleManager) {
$moduleClassName = get_class($moduleManager);
$moduleClassNameArray = explode('\\', $moduleClassName);
$moduleClassNameAlias = end($moduleClassNameArray);
$application = $e->getApplication();
$services = $application->getServiceManager();
if (!$services->has($moduleClassName)) {
$services->setService($moduleClassName, $moduleManager);
$services->setAlias($moduleClassName, $moduleClassNameAlias);
}
}, 1000);

Expand Down
19 changes: 19 additions & 0 deletions test/Listener/LocatorRegistrationListenerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,4 +121,23 @@ public function testModuleClassIsRegisteredWithDiAndInjectedWithSharedInstances(
$this->assertInstanceOf('Zend\ModuleManager\ModuleManager', $sharedInstance2);
$this->assertSame($this->moduleManager, $locator->get('Foo\Bar')->moduleManager);
}

public function testNoDuplicateServicesAreDefinedForModuleManager()
{
$locatorRegistrationListener = new LocatorRegistrationListener;
$this->moduleManager->getEventManager()->attachAggregate($locatorRegistrationListener);

$this->moduleManager->loadModules();
$this->application->bootstrap();
$registeredServices = $this->application->getServiceManager()->getRegisteredServices();

$aliases = $registeredServices['aliases'];
$instances = $registeredServices['instances'];

$this->assertContains('zendmodulemanagermodulemanager', $aliases);
$this->assertFalse(in_array('modulemanager', $aliases));

$this->assertContains('modulemanager', $instances);
$this->assertFalse(in_array('zendmodulemanagermodulemanager', $instances));
}
}

0 comments on commit 1b4822b

Please sign in to comment.