/**
  * @covers Zend\ServiceManager\Di\DiAbstractServiceFactory::canCreateServiceWithName
  */
 public function testCanCreateServiceWithName()
 {
     $instance = new DiAbstractServiceFactory($this->getMock('Zend\\Di\\Di'));
     $im = $instance->instanceManager();
     $locator = new ServiceManager();
     // will check shared instances
     $this->assertFalse($instance->canCreateServiceWithName($locator, 'a-shared-instance-alias', 'a-shared-instance-alias'));
     $im->addSharedInstance(new \stdClass(), 'a-shared-instance-alias');
     $this->assertTrue($instance->canCreateServiceWithName($locator, 'a-shared-instance-alias', 'a-shared-instance-alias'));
     // will check aliases
     $this->assertFalse($instance->canCreateServiceWithName($locator, 'an-alias', 'an-alias'));
     $im->addAlias('an-alias', 'stdClass');
     $this->assertTrue($instance->canCreateServiceWithName($locator, 'an-alias', 'an-alias'));
     // will check instance configurations
     $this->assertFalse($instance->canCreateServiceWithName($locator, __NAMESPACE__ . '\\Non\\Existing', __NAMESPACE__ . '\\Non\\Existing'));
     $im->setConfig(__NAMESPACE__ . '\\Non\\Existing', array('parameters' => array('a' => 'b')));
     $this->assertTrue($instance->canCreateServiceWithName($locator, __NAMESPACE__ . '\\Non\\Existing', __NAMESPACE__ . '\\Non\\Existing'));
     // will check preferences for abstract types
     $this->assertFalse($instance->canCreateServiceWithName($locator, __NAMESPACE__ . '\\AbstractClass', __NAMESPACE__ . '\\AbstractClass'));
     $im->setTypePreference(__NAMESPACE__ . '\\AbstractClass', array(__NAMESPACE__ . '\\Non\\Existing'));
     $this->assertTrue($instance->canCreateServiceWithName($locator, __NAMESPACE__ . '\\AbstractClass', __NAMESPACE__ . '\\AbstractClass'));
     // will check definitions
     $def = $instance->definitions();
     $this->assertFalse($instance->canCreateServiceWithName($locator, __NAMESPACE__ . '\\Other\\Non\\Existing', __NAMESPACE__ . '\\Other\\Non\\Existing'));
     $classDefinition = $this->getMock('Zend\\Di\\Definition\\DefinitionInterface');
     $classDefinition->expects($this->any())->method('hasClass')->with($this->equalTo(__NAMESPACE__ . '\\Other\\Non\\Existing'))->will($this->returnValue(true));
     $def->addDefinition($classDefinition);
     $this->assertTrue($instance->canCreateServiceWithName($locator, __NAMESPACE__ . '\\Other\\Non\\Existing', __NAMESPACE__ . '\\Other\\Non\\Existing'));
 }
    public function testDiAbstractServiceFactory()
    {
        $di = $this->getMock('Zend\Di\Di');
        $factory = new DiAbstractServiceFactory($di);
        $factory->instanceManager()->setConfig('ZendTest\ServiceManager\TestAsset\Bar', array('parameters' => array('foo' => array('a'))));
        $this->serviceManager->addAbstractFactory($factory);

        $this->assertTrue($this->serviceManager->has('ZendTest\ServiceManager\TestAsset\Bar', true));

        $bar = $this->serviceManager->get('ZendTest\ServiceManager\TestAsset\Bar', true);
        $this->assertInstanceOf('ZendTest\ServiceManager\TestAsset\Bar', $bar);
    }
Exemple #3
0
 /**
  * @covers Zend\ServiceManager\Di\DiAbstractServiceFactory::createServiceWithName
  * @covers Zend\ServiceManager\Di\DiAbstractServiceFactory::get
  */
 public function testCreateServiceWithName()
 {
     $foo = $this->diAbstractServiceFactory->createServiceWithName($this->mockServiceLocator, 'foo');
     $this->assertEquals($this->fooInstance, $foo);
 }
Exemple #4
0
 public function __construct()
 {
     $di = new \Zend\Di\Di();
     parent::__construct($di, self::USE_SL_BEFORE_DI);
 }