示例#1
0
 public static function setUpBeforeClass()
 {
     $magentoDi = new Magento_Di_Zend();
     $magentoDi->instanceManager()->addTypePreference(self::TEST_INTERFACE, self::TEST_INTERFACE_IMPLEMENTATION);
     $magentoDi->instanceManager()->addAlias(self::TEST_CLASS_ALIAS, self::TEST_CLASS);
     self::$_objectManager = new Magento_ObjectManager_Zend(null, $magentoDi);
 }
示例#2
0
 public function testClearCache()
 {
     $object = $this->getMock('stdClass', array('__destruct'));
     $object->expects($this->once())->method('__destruct');
     $resource = $this->getMock('stdClass', array('__destruct'));
     $object->expects($this->once())->method('__destruct');
     $instanceManager = new Magento_Di_InstanceManager_Zend();
     $instanceManager->addSharedInstance($object, 'sharedInstance');
     $instanceManager->addSharedInstance($resource, 'Mage_Core_Model_Resource');
     $diInstance = new Magento_Di_Zend();
     $model = new Magento_Test_ObjectManager(null, $diInstance);
     // Reflection is the only way to setup fixture input data in place of the hard-coded property value
     $reflectionClass = new ReflectionProperty(get_class($model), '_classesToDestruct');
     $reflectionClass->setAccessible(true);
     $reflectionClass->setValue($model, array('sharedInstance', 'nonRegisteredInstance'));
     $diInstance->setInstanceManager($instanceManager);
     $this->assertSame($model, $model->clearCache());
     $this->assertNotSame($instanceManager, $diInstance->instanceManager());
     $this->assertSame($model, $diInstance->instanceManager()->getSharedInstance('Magento_ObjectManager'));
     $this->assertSame($resource, $diInstance->instanceManager()->getSharedInstance('Mage_Core_Model_Resource'));
     $this->assertFalse($diInstance->instanceManager()->hasSharedInstance('sharedInstance'));
 }
示例#3
0
 /**
  * Get class name by alias
  *
  * @param string
  * @return string|bool
  * @throws Zend\Di\Exception\RuntimeException
  */
 public function getClassFromAlias($alias)
 {
     return $this->_di->instanceManager()->getClassFromAlias($alias);
 }