public function testModuleClassIsRegisteredWithDiAndInjectedWithSharedInstances() { $locatorRegistrationListener = new LocatorRegistrationListener(); $this->moduleManager->events()->attachAggregate($locatorRegistrationListener); $test = $this; $this->moduleManager->events()->attach('loadModule', function ($e) use($test) { $test->module = $e->getModule(); }, -1000); $this->moduleManager->loadModules(); $bootstrap = new Bootstrap(new Config(array('di' => array()))); $application = new Application(); $bootstrap->bootstrap($application); $locator = $application->getLocator(); $sharedInstance1 = $locator->instanceManager()->getSharedInstance('ListenerTestModule\\Module'); $sharedInstance2 = $locator->instanceManager()->getSharedInstance('Zend\\Module\\Manager'); $this->assertInstanceOf('ListenerTestModule\\Module', $sharedInstance1); $this->assertSame($this->module, $locator->get('Foo\\Bar')->module); $this->assertInstanceOf('Zend\\Module\\Manager', $sharedInstance2); $this->assertSame($this->moduleManager, $locator->get('Foo\\Bar')->moduleManager); }
<?php use Zend\Loader\AutoloaderFactory, Zend\Config\Config, Zend\Loader\ModuleAutoloader, Zend\Module\Manager as ModuleManager, Zend\Module\ManagerOptions, Zend\Mvc\Bootstrap, Zend\Mvc\Application, Doctrine\ORM\Tools\Console\ConsoleRunner, Symfony\Component\Console\Helper\HelperSet, Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper; ini_set('display_errors', true); error_reporting(-1); // Define application environment defined('APPLICATION_ENV') || define('APPLICATION_ENV', getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'production'); // Ensure library/ is on include_path set_include_path(implode(PATH_SEPARATOR, array(realpath(__DIR__ . '/../library'), realpath(__DIR__ . '/../library/ZendFramework/library'), get_include_path()))); require_once 'Zend/Loader/AutoloaderFactory.php'; AutoloaderFactory::factory(array('Zend\\Loader\\StandardAutoloader' => array())); $appConfig = new Config(include __DIR__ . '/../configs/application.config.php'); $moduleLoader = new ModuleAutoloader($appConfig['module_paths']); $moduleLoader->register(); $moduleManager = new ModuleManager($appConfig['modules'], new ManagerOptions($appConfig['module_manager_options'])); $bootstrap = new Bootstrap($moduleManager); $application = new Application(); $bootstrap->bootstrap($application); $locator = $application->getLocator(); ConsoleRunner::run(new HelperSet(array('em' => new EntityManagerHelper($locator->get('doctrine')->getEntityManager()))));