Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Adds an alias for ModuleManager and removes the duplicate service defini... #5146

Closed
wants to merge 2 commits into from

2 participants

Percy Hatcherson Matthew Weier O'Phinney
This page is out of date. Refresh to see the latest.
4 library/Zend/ModuleManager/Listener/LocatorRegistrationListener.php
View
@@ -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);
19 tests/ZendTest/ModuleManager/Listener/LocatorRegistrationListenerTest.php
View
@@ -122,4 +122,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));
+ }
}
Something went wrong with that request. Please try again.