示例#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
 /**
  * @param array $arguments
  *
  * @dataProvider testNewInstanceWithDefinitionsWithResolveDataProvider
  */
 public function testNewInstanceWithDefinitionsWithResolve(array $arguments)
 {
     $className = self::TEST_CLASS_MODEL . '_Alias';
     $classAlias = self::TEST_CLASS_MODEL;
     $this->_prepareMockForNewInstanceWithDefinitionsWithResolve($classAlias);
     $testModel = $this->_model->newInstance($className, $arguments, false);
     $this->assertInstanceOf($classAlias, $testModel);
     $this->assertAttributeEquals($this->_expectedDataValue, '_data', $testModel);
 }
示例#3
0
 /**
  * Create Magento_ObjectManager_Zend instance
  *
  * @param bool $mockNewInstance
  */
 protected function _prepareObjectManagerForGetCreateTests($mockNewInstance = false)
 {
     $this->_magentoConfig = $this->getMock('Mage_Core_Model_Config', array('loadBase'), array(), '', false);
     $this->_magentoConfig->expects($this->any())->method('loadBase')->will($this->returnSelf());
     $this->_instanceManager = $this->getMock('Magento_Di_InstanceManager_Zend', array('addSharedInstance'), array(), '', false);
     $this->_diInstance = $this->getMock('Magento_Di_Zend', array('instanceManager', 'newInstance', 'get', 'setDefinitionList'));
     $this->_diInstance->expects($this->any())->method('instanceManager')->will($this->returnValue($this->_instanceManager));
     if ($mockNewInstance) {
         $this->_diInstance->expects($this->once())->method('newInstance')->will($this->returnCallback(array($this, 'verifyCreate')));
     } else {
         $this->_diInstance->expects($this->once())->method('get')->will($this->returnCallback(array($this, 'verifyGet')));
     }
     $this->_objectManager = new Magento_ObjectManager_Zend(null, $this->_diInstance);
 }
示例#4
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'));
 }
示例#5
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);
 }