示例#1
0
 /**
  * Gets list of command instances
  *
  * @return \Symfony\Component\Console\Command\Command[]
  * @throws \Exception
  */
 public function getCommands()
 {
     $commands = [];
     foreach ($this->getCommandsClasses() as $class) {
         if (class_exists($class)) {
             $commands[] = $this->serviceManager->create($class);
         } else {
             throw new \Exception('Class ' . $class . ' does not exist');
         }
     }
     return $commands;
 }
 /**
  * @covers Zend\ServiceManager\ServiceManager::canCreateFromAbstractFactory
  * @covers Zend\ServiceManager\ServiceManager::create
  */
 public function testAbstractFactoryNotUsedIfNotAbleToCreate()
 {
     $service = new \stdClass();
     $af1 = $this->getMock('Zend\\ServiceManager\\AbstractFactoryInterface');
     $af1->expects($this->any())->method('canCreateServiceWithName')->will($this->returnValue(true));
     $af1->expects($this->any())->method('createServiceWithName')->will($this->returnValue($service));
     $af2 = $this->getMock('Zend\\ServiceManager\\AbstractFactoryInterface');
     $af2->expects($this->any())->method('canCreateServiceWithName')->will($this->returnValue(false));
     $af2->expects($this->never())->method('createServiceWithName');
     $this->serviceManager->addAbstractFactory($af1);
     $this->serviceManager->addAbstractFactory($af2);
     $this->assertSame($service, $this->serviceManager->create('test'));
 }
示例#3
0
 /**
  * Create new entity manager
  *
  * @return \Doctrine\ORM\EntityManager
  */
 public function newEntityManager()
 {
     $newEntityManager = $this->locator->create('doctrine.entitymanager.orm_default');
     $this->entityManager = $newEntityManager;
     foreach ($this->locator->getCanonicalNames() as $alias => $canonicalName) {
         if (strstr($alias, '\\Service\\')) {
             $service = $this->locator->get($alias);
             if ($service instanceof AbstractService) {
                 $service->setObjectManager($newEntityManager);
             }
         }
     }
     return $newEntityManager;
 }
 public function testRegistersAutoloader()
 {
     $autoloaders = spl_autoload_functions();
     $serviceManager = new ServiceManager();
     $namespace = 'ZendTestProxy' . uniqid();
     $serviceManager->setService('Config', array('lazy_services' => array('class_map' => array('foo' => __CLASS__), 'proxies_namespace' => $namespace)));
     $serviceManager->setFactory('foo-delegator', 'Zend\\ServiceManager\\Proxy\\LazyServiceFactoryFactory');
     $serviceManager->create('foo-delegator');
     $currentAutoloaders = spl_autoload_functions();
     $proxyAutoloader = end($currentAutoloaders);
     $this->assertCount(count($autoloaders) + 1, $currentAutoloaders);
     $this->assertInstanceOf('ProxyManager\\Autoloader\\AutoloaderInterface', $proxyAutoloader);
     spl_autoload_unregister($proxyAutoloader);
 }
示例#5
0
 public function testDelegatorFromCallback()
 {
     $realService = $this->getMock('stdClass', array(), array(), 'RealService');
     $delegator = $this->getMock('stdClass', array(), array(), 'Delegator');
     $delegatorFactoryCallback = function ($serviceManager, $cName, $rName, $callback) use($delegator) {
         $delegator->real = call_user_func($callback);
         return $delegator;
     };
     $this->serviceManager->setFactory('foo-service', function () use($realService) {
         return $realService;
     });
     $this->serviceManager->addDelegator('foo-service', $delegatorFactoryCallback);
     $service = $this->serviceManager->create('foo-service');
     $this->assertSame($delegator, $service);
     $this->assertSame($realService, $service->real);
 }