/**
  * @dataProvider getServiceOfVariousTypes
  *
  * @param $service
  */
 public function testFactoriesCanReturnAnyTypeButNull($service)
 {
     $factory = function () use($service) {
         return $service;
     };
     $this->serviceManager->setFactory('something', $factory);
     if ($service === null) {
         try {
             $this->serviceManager->get('something');
             $this->fail('ServiceManager::get() successfully returned null');
         } catch (\Exception $e) {
             $this->assertInstanceOf('Zend\\ServiceManager\\Exception\\ServiceNotCreatedException', $e);
         }
     } else {
         $this->assertSame($service, $this->serviceManager->get('something'));
     }
 }
示例#2
0
 /**
  * Run the boot process, load our modules and their dependencies.
  *
  * This method is automatically called by dispatch(), but you can use it
  * to build all services when not handling a request.
  *
  * @return $this
  */
 public function boot()
 {
     if (true === $this->booted) {
         return $this;
     }
     $this->serviceManager = $this->buildServiceManager();
     $this->log('debug', sprintf('Booting %s ...', $this->name));
     // Loading our Modules
     $this->getModuleManager()->loadModules();
     if ($this->debug) {
         $modules = $this->getModuleManager()->getModules();
         $this->log('debug', sprintf('All modules online (%d): "%s"', count($modules), implode('", "', $modules)));
     }
     // Lets get all the services our of our modules and start setting them in the ServiceManager
     $moduleServices = $this->serviceManager->get('ModuleDefaultListener')->getServices();
     foreach ($moduleServices as $key => $service) {
         $this->serviceManager->setFactory($key, $service);
     }
     $this->booted = true;
     if ($this->debug) {
         $this->log('debug', sprintf('%s has booted (in %.3f secs)', $this->name, microtime(true) - $this->startTime));
     }
     return $this;
 }