protected function tearDown()
 {
     parent::tearDown();
     /** @var ObjectManagerInterface|\PHPUnit_Framework_MockObject_MockObject $objectManagerMock*/
     $objectManagerMock = $this->getMock('Magento\\Framework\\ObjectManagerInterface');
     \Magento\Framework\App\ObjectManager::setInstance($objectManagerMock);
 }
示例#2
0
 protected function tearDown()
 {
     parent::tearDown();
     $magentoObjectManagerFactory = \Magento\Framework\App\Bootstrap::createObjectManagerFactory(BP, $_SERVER);
     $objectManager = $magentoObjectManagerFactory->create($_SERVER);
     \Magento\Framework\App\ObjectManager::setInstance($objectManager);
 }
示例#3
0
 public function setUp()
 {
     $this->mockViewFilesystem = $this->getMockBuilder('\\Magento\\Framework\\View\\FileSystem')->disableOriginalConstructor()->getMock();
     $objectManagerHelper = new \Magento\TestFramework\Helper\ObjectManager($this);
     $objectManagerMock = $this->getMock('Magento\\Framework\\ObjectManagerInterface');
     $objectManagerMock->expects($this->once())->method('get')->with('Magento\\Email\\Model\\Resource\\Template')->will($this->returnValue($objectManagerHelper->getObject('Magento\\Email\\Model\\Resource\\Template')));
     \Magento\Framework\App\ObjectManager::setInstance($objectManagerMock);
     $this->template = $objectManagerHelper->getObject('Magento\\Sales\\Model\\Email\\Template', ['viewFileSystem' => $this->mockViewFilesystem]);
 }
示例#4
0
 protected function setUp()
 {
     $this->context = $this->getMock('Magento\\Framework\\View\\Element\\Template\\Context', [], [], '', false, false);
     $this->orderCollectionFactory = $this->getMockBuilder('Magento\\Sales\\Model\\ResourceModel\\Order\\CollectionFactory')->disableOriginalConstructor()->setMethods(['create'])->getMock();
     $this->orderCollectionFactoryInterface = $this->getMockBuilder(\Magento\Sales\Model\ResourceModel\Order\CollectionFactoryInterface::class)->disableOriginalConstructor()->setMethods(['create'])->getMock();
     $this->objectManager = $this->getMock(\Magento\Framework\ObjectManagerInterface::class, [], [], '', false);
     $this->objectManager->expects($this->any())->method('get')->will($this->returnValue($this->orderCollectionFactoryInterface));
     \Magento\Framework\App\ObjectManager::setInstance($this->objectManager);
     $this->customerSession = $this->getMockBuilder('Magento\\Customer\\Model\\Session')->setMethods(['getCustomerId'])->disableOriginalConstructor()->getMock();
     $this->orderConfig = $this->getMockBuilder('Magento\\Sales\\Model\\Order\\Config')->setMethods(['getVisibleOnFrontStatuses'])->disableOriginalConstructor()->getMock();
     $this->pageConfig = $this->getMockBuilder('Magento\\Framework\\View\\Page\\Config')->disableOriginalConstructor()->getMock();
     $this->pageTitleMock = $this->getMockBuilder('Magento\\Framework\\View\\Page\\Title')->disableOriginalConstructor()->getMock();
 }
 protected function setUp()
 {
     $helper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
     $this->scopeConfigMock = $this->getMock('Magento\\Framework\\App\\Config\\ScopeConfigInterface');
     $this->scopeConfigMock->expects($this->any())->method('getValue')->willReturn(['test' => 1]);
     $this->structureMock = $this->getMock('Magento\\Config\\Model\\Config\\Structure', [], [], '', false);
     $this->structureMock->expects($this->any())->method('getFieldPathsByAttribute')->willReturn(['path' => 'test']);
     $this->resourceModelMock = $this->getMock('Magento\\Email\\Model\\Resource\\Template', [], [], '', false);
     $this->resourceModelMock->expects($this->any())->method('getSystemConfigByPathsAndTemplateId')->willReturn(['test_config' => 2015]);
     $objectManagerMock = $this->getMock('Magento\\Framework\\ObjectManagerInterface');
     $objectManagerMock->expects($this->any())->method('get')->with('Magento\\Email\\Model\\Resource\\Template')->will($this->returnValue($this->resourceModelMock));
     \Magento\Framework\App\ObjectManager::setInstance($objectManagerMock);
     $this->model = $helper->getObject('Magento\\Email\\Model\\BackendTemplate', ['scopeConfig' => $this->scopeConfigMock, 'structure' => $this->structureMock]);
 }
示例#6
0
 protected function setUp()
 {
     $this->entityFactoryMock = $this->getMock('Magento\\Framework\\Data\\Collection\\EntityFactoryInterface');
     $this->loggerMock = $this->getMock('Magento\\Framework\\Logger', [], [], '', false);
     $this->fetchStrategyMock = $this->getMock('Magento\\Framework\\Data\\Collection\\Db\\FetchStrategyInterface');
     $this->managerMock = $this->getMock('Magento\\Framework\\Event\\ManagerInterface');
     $this->connectionMock = $this->getMock('Magento\\Framework\\DB\\Adapter\\Pdo\\Mysql', [], [], '', false);
     $this->resourceMock = $this->getMock('Magento\\Framework\\Flag\\Resource', [], [], '', false);
     $this->resourceMock->expects($this->any())->method('getReadConnection')->will($this->returnValue($this->connectionMock));
     $this->selectMock = $this->getMock('Zend_Db_Select', ['getPart', 'setPart', 'from', 'columns'], [$this->connectionMock]);
     $this->connectionMock->expects($this->any())->method('select')->will($this->returnValue($this->selectMock));
     $this->objectManagerMock = $this->getMock('Magento\\Framework\\App\\ObjectManager', [], [], '', false);
     \Magento\Framework\App\ObjectManager::setInstance($this->objectManagerMock);
     $this->objectManagerHelper = new ObjectManagerHelper($this);
     $this->uut = $this->getUut();
 }
示例#7
0
 public function testConfigureObjectManager()
 {
     try {
         $origObjectManager = ObjectManager::getInstance();
     } catch (\Exception $e) {
         $origObjectManager = null;
     }
     $objectManagerMock = $this->getMockBuilder('Magento\\Framework\\App\\ObjectManager')->disableOriginalConstructor()->getMock();
     ObjectManager::setInstance($objectManagerMock);
     $diConfigMock = $this->getMockBuilder('\\Magento\\Framework\\Interception\\ObjectManager\\ConfigInterface')->disableOriginalConstructor()->getMock();
     $configLoaderMock = $this->getMockBuilder('Magento\\Framework\\App\\ObjectManager\\ConfigLoader')->disableOriginalConstructor()->getMock();
     $configLoaderMock->expects($this->any())->method('load')->willReturn([]);
     $omReturnMap = [['Magento\\Framework\\App\\ObjectManager\\ConfigLoader', $configLoaderMock], ['Magento\\Framework\\Config\\ScopeInterface', $this->getMockBuilder('Magento\\Framework\\Config\\ScopeInterface')->disableOriginalConstructor()->getMock()], ['Magento\\Framework\\App\\ObjectManager\\ConfigCache', $this->getMockBuilder('Magento\\Framework\\App\\ObjectManager\\ConfigCache')->disableOriginalConstructor()->getMock()], ['Magento\\Framework\\Interception\\Config\\Config', $this->getMockBuilder('Magento\\Framework\\Interception\\Config\\Config')->disableOriginalConstructor()->getMock()]];
     $objectManagerMock->expects($this->any())->method('get')->willReturnMap($omReturnMap);
     $sharedInstances = ['class_name' => 'shared_object'];
     $this->_developer->configureObjectManager($diConfigMock, $sharedInstances);
     $expectedSharedInstances = ['class_name' => 'shared_object', 'Magento\\Framework\\ObjectManager\\ConfigLoaderInterface' => $configLoaderMock];
     $this->assertSame($expectedSharedInstances, $sharedInstances);
     if (isset($origObjectManager)) {
         ObjectManager::setInstance($origObjectManager);
     }
 }
 /**
  * Create ObjectManager
  *
  * @param array $arguments
  * @return \Magento\Framework\ObjectManagerInterface
  *
  * @SuppressWarnings(PHPMD.NPathComplexity)
  */
 public function create(array $arguments)
 {
     $deploymentConfig = $this->createDeploymentConfig($this->directoryList, $this->configFilePool, $arguments);
     $arguments = array_merge($deploymentConfig->get(), $arguments);
     $definitionFactory = new \Magento\Framework\ObjectManager\DefinitionFactory($this->driverPool->getDriver(DriverPool::FILE), $this->directoryList->getPath(DirectoryList::DI), $this->directoryList->getPath(DirectoryList::GENERATION), $deploymentConfig->get(self::CONFIG_PATH_DEFINITION_FORMAT, Serialized::MODE_NAME));
     $definitions = $definitionFactory->createClassDefinition($deploymentConfig->get('definitions'));
     $relations = $definitionFactory->createRelations();
     /** @var EnvironmentFactory $enFactory */
     $enFactory = new $this->envFactoryClassName($relations, $definitions);
     /** @var EnvironmentInterface $env */
     $env = $enFactory->createEnvironment();
     /** @var ConfigInterface $diConfig */
     $diConfig = $env->getDiConfig();
     $appMode = isset($arguments[State::PARAM_MODE]) ? $arguments[State::PARAM_MODE] : State::MODE_DEFAULT;
     $booleanUtils = new \Magento\Framework\Stdlib\BooleanUtils();
     $argInterpreter = $this->createArgumentInterpreter($booleanUtils);
     $argumentMapper = new \Magento\Framework\ObjectManager\Config\Mapper\Dom($argInterpreter);
     if ($env->getMode() != Environment\Compiled::MODE) {
         $configData = $this->_loadPrimaryConfig($this->directoryList, $this->driverPool, $argumentMapper, $appMode);
         if ($configData) {
             $diConfig->extend($configData);
         }
     }
     // set cache profiler decorator if enabled
     if (\Magento\Framework\Profiler::isEnabled()) {
         $cacheFactoryArguments = $diConfig->getArguments('Magento\\Framework\\App\\Cache\\Frontend\\Factory');
         $cacheFactoryArguments['decorators'][] = ['class' => 'Magento\\Framework\\Cache\\Frontend\\Decorator\\Profiler', 'parameters' => ['backendPrefixes' => ['Zend_Cache_Backend_', 'Cm_Cache_Backend_']]];
         $cacheFactoryConfig = ['Magento\\Framework\\App\\Cache\\Frontend\\Factory' => ['arguments' => $cacheFactoryArguments]];
         $diConfig->extend($cacheFactoryConfig);
     }
     $sharedInstances = ['Magento\\Framework\\App\\DeploymentConfig' => $deploymentConfig, 'Magento\\Framework\\App\\Filesystem\\DirectoryList' => $this->directoryList, 'Magento\\Framework\\Filesystem\\DirectoryList' => $this->directoryList, 'Magento\\Framework\\Filesystem\\DriverPool' => $this->driverPool, 'Magento\\Framework\\ObjectManager\\RelationsInterface' => $relations, 'Magento\\Framework\\Interception\\DefinitionInterface' => $definitionFactory->createPluginDefinition(), 'Magento\\Framework\\ObjectManager\\ConfigInterface' => $diConfig, 'Magento\\Framework\\Interception\\ObjectManager\\ConfigInterface' => $diConfig, 'Magento\\Framework\\ObjectManager\\DefinitionInterface' => $definitions, 'Magento\\Framework\\Stdlib\\BooleanUtils' => $booleanUtils, 'Magento\\Framework\\ObjectManager\\Config\\Mapper\\Dom' => $argumentMapper, 'Magento\\Framework\\ObjectManager\\ConfigLoaderInterface' => $env->getObjectManagerConfigLoader(), $this->_configClassName => $diConfig];
     $arguments['shared_instances'] =& $sharedInstances;
     $this->factory = $env->getObjectManagerFactory($arguments);
     /** @var \Magento\Framework\ObjectManagerInterface $objectManager */
     $objectManager = new $this->_locatorClassName($this->factory, $diConfig, $sharedInstances);
     $this->factory->setObjectManager($objectManager);
     ObjectManager::setInstance($objectManager);
     $definitionFactory->getCodeGenerator()->setObjectManager($objectManager);
     $env->configureObjectManager($diConfig, $sharedInstances);
     return $objectManager;
 }
示例#9
0
 /**
  * Test for the magic method __wakeup
  *
  * @covers \Magento\Framework\App\Response\Http::__wakeup
  */
 public function testWakeUpWith()
 {
     $objectManagerMock = $this->getMock('Magento\\Framework\\App\\ObjectManager', [], [], '', false);
     $objectManagerMock->expects($this->once())->method('create')->with('Magento\\Framework\\Stdlib\\CookieManagerInterface')->will($this->returnValue($this->cookieManagerMock));
     $objectManagerMock->expects($this->at(1))->method('get')->with('Magento\\Framework\\Stdlib\\Cookie\\CookieMetadataFactory')->will($this->returnValue($this->cookieMetadataFactoryMock));
     \Magento\Framework\App\ObjectManager::setInstance($objectManagerMock);
     $this->model->__wakeup();
 }
 /**
  * Create ObjectManager
  *
  * @param string $rootDir
  * @param array $arguments
  * @param bool $useCompiled
  * @return \Magento\Framework\ObjectManager
  *
  * @SuppressWarnings(PHPMD.NPathComplexity)
  */
 public function create($rootDir, array $arguments, $useCompiled = true)
 {
     $directories = isset($arguments[Filesystem::PARAM_APP_DIRS]) ? $arguments[Filesystem::PARAM_APP_DIRS] : array();
     $directoryList = new DirectoryList($rootDir, $directories);
     (new \Magento\Framework\Autoload\IncludePath())->addIncludePath(array($directoryList->getDir(Filesystem::GENERATION_DIR)));
     $appArguments = $this->createAppArguments($directoryList, $arguments);
     $definitionFactory = new \Magento\Framework\ObjectManager\DefinitionFactory(new \Magento\Framework\Filesystem\Driver\File(), $directoryList->getDir(Filesystem::DI_DIR), $directoryList->getDir(Filesystem::GENERATION_DIR), $appArguments->get('definition.format', 'serialized'));
     $definitions = $definitionFactory->createClassDefinition($appArguments->get('definitions'), $useCompiled);
     $relations = $definitionFactory->createRelations();
     $configClass = $this->_configClassName;
     /** @var \Magento\Framework\ObjectManager\Config\Config $diConfig */
     $diConfig = new $configClass($relations, $definitions);
     $appMode = $appArguments->get(State::PARAM_MODE, State::MODE_DEFAULT);
     $booleanUtils = new \Magento\Framework\Stdlib\BooleanUtils();
     $argInterpreter = $this->createArgumentInterpreter($booleanUtils);
     $argumentMapper = new \Magento\Framework\ObjectManager\Config\Mapper\Dom($argInterpreter);
     $configData = $this->_loadPrimaryConfig($directoryList, $argumentMapper, $appMode);
     if ($configData) {
         $diConfig->extend($configData);
     }
     $this->factory = new \Magento\Framework\ObjectManager\Factory\Factory($diConfig, null, $definitions, $appArguments->get());
     $className = $this->_locatorClassName;
     $sharedInstances = ['Magento\\Framework\\App\\Arguments' => $appArguments, 'Magento\\Framework\\App\\Filesystem\\DirectoryList' => $directoryList, 'Magento\\Framework\\Filesystem\\DirectoryList' => $directoryList, 'Magento\\Framework\\ObjectManager\\Relations' => $relations, 'Magento\\Framework\\Interception\\Definition' => $definitionFactory->createPluginDefinition(), 'Magento\\Framework\\ObjectManager\\Config' => $diConfig, 'Magento\\Framework\\ObjectManager\\Definition' => $definitions, 'Magento\\Framework\\Stdlib\\BooleanUtils' => $booleanUtils, 'Magento\\Framework\\ObjectManager\\Config\\Mapper\\Dom' => $argumentMapper, $configClass => $diConfig];
     /** @var \Magento\Framework\ObjectManager $objectManager */
     $objectManager = new $className($this->factory, $diConfig, $sharedInstances);
     $this->factory->setObjectManager($objectManager);
     ObjectManager::setInstance($objectManager);
     /** @var \Magento\Framework\App\Filesystem\DirectoryList\Verification $verification */
     $verification = $objectManager->get('Magento\\Framework\\App\\Filesystem\\DirectoryList\\Verification');
     $verification->createAndVerifyDirectories();
     $diConfig->setCache($objectManager->get('Magento\\Framework\\App\\ObjectManager\\ConfigCache'));
     $objectManager->configure($objectManager->get('Magento\\Framework\\App\\ObjectManager\\ConfigLoader')->load('global'));
     $objectManager->get('Magento\\Framework\\Config\\ScopeInterface')->setCurrentScope('global');
     $objectManager->get('Magento\\Framework\\App\\Resource')->setCache($objectManager->get('Magento\\Framework\\App\\CacheInterface'));
     $interceptionConfig = $objectManager->get('Magento\\Framework\\Interception\\Config\\Config');
     $diConfig->setInterceptionConfig($interceptionConfig);
     $this->configureDirectories($objectManager);
     return $objectManager;
 }
示例#11
0
 protected function tearDown()
 {
     parent::tearDown();
     \Magento\Framework\App\ObjectManager::setInstance($this->objectManagerBackup);
 }
 public function tearDown()
 {
     \Magento\Framework\App\ObjectManager::setInstance($this->applicationObjectManager);
 }