/** * Initialize application * * @param array $overriddenParams */ public function initialize($overriddenParams = array()) { $overriddenParams['base_dir'] = BP; $overriddenParams[\Magento\Framework\App\State::PARAM_MODE] = $this->_appMode; $overriddenParams = $this->_customizeParams($overriddenParams); /** @var \Magento\TestFramework\ObjectManager $objectManager */ $objectManager = Helper\Bootstrap::getObjectManager(); if (!$objectManager) { $objectManager = $this->_factory->create(BP, $overriddenParams); } else { $objectManager = $this->_factory->restore($objectManager, BP, $overriddenParams); } $directories = isset($overriddenParams[Filesystem::PARAM_APP_DIRS]) ? $overriddenParams[Filesystem::PARAM_APP_DIRS] : array(); $directoryList = new \Magento\TestFramework\App\Filesystem\DirectoryList(BP, $directories); $objectManager->addSharedInstance($directoryList, 'Magento\\Framework\\App\\Filesystem\\DirectoryList'); $objectManager->addSharedInstance($directoryList, 'Magento\\Framework\\Filesystem\\DirectoryList'); $objectManager->removeSharedInstance('Magento\\Framework\\App\\Filesystem'); $objectManager->removeSharedInstance('Magento\\Framework\\App\\Filesystem\\DirectoryList\\Verification'); Helper\Bootstrap::setObjectManager($objectManager); $objectManager->configure(array('preferences' => array('Magento\\Framework\\App\\State' => 'Magento\\TestFramework\\App\\State'))); /** Register event observer of Integration Framework */ /** @var \Magento\Framework\Event\Config\Data $eventConfigData */ $eventConfigData = $objectManager->get('Magento\\Framework\\Event\\Config\\Data'); $eventConfigData->merge(array('core_app_init_current_store_after' => array('integration_tests' => array('instance' => 'Magento\\TestFramework\\Event\\Magento', 'method' => 'initStoreAfter', 'name' => 'integration_tests')))); $this->loadArea(\Magento\TestFramework\Application::DEFAULT_APP_AREA); \Magento\Framework\Phrase::setRenderer($objectManager->get('Magento\\Framework\\Phrase\\RendererInterface')); /** @var \Magento\Framework\App\Filesystem\DirectoryList\Verification $verification */ $verification = $objectManager->get('Magento\\Framework\\App\\Filesystem\\DirectoryList\\Verification'); $verification->createAndVerifyDirectories(); $directoryList = $objectManager->get('Magento\\Framework\\App\\Filesystem\\DirectoryList'); $directoryListConfig = $objectManager->get('Magento\\Framework\\App\\Filesystem\\DirectoryList\\Configuration'); $directoryListConfig->configure($directoryList); $directories = isset($overriddenParams[\Magento\Framework\App\Filesystem::PARAM_APP_DIRS]) ? $overriddenParams[\Magento\Framework\App\Filesystem::PARAM_APP_DIRS] : array(); foreach ($directories as $code => $configOverrides) { $config = array_merge($directoryList->getConfig($code), $configOverrides); $directoryList->addDirectory($code, $config); } }
/** * Initialize application * * @param array $overriddenParams * @return void */ public function initialize($overriddenParams = []) { $overriddenParams[\Magento\Framework\App\State::PARAM_MODE] = $this->_appMode; $overriddenParams = $this->_customizeParams($overriddenParams); $directories = isset($overriddenParams[\Magento\Framework\App\Bootstrap::INIT_PARAM_FILESYSTEM_DIR_PATHS]) ? $overriddenParams[\Magento\Framework\App\Bootstrap::INIT_PARAM_FILESYSTEM_DIR_PATHS] : []; $directoryList = new DirectoryList(BP, $directories); /** @var \Magento\TestFramework\ObjectManager $objectManager */ $objectManager = Helper\Bootstrap::getObjectManager(); if (!$objectManager) { $objectManager = $this->_factory->create($overriddenParams); $objectManager->addSharedInstance($directoryList, 'Magento\\Framework\\App\\Filesystem\\DirectoryList'); $objectManager->addSharedInstance($directoryList, 'Magento\\Framework\\Filesystem\\DirectoryList'); } else { $objectManager = $this->_factory->restore($objectManager, $directoryList, $overriddenParams); } /** @var \Magento\TestFramework\App\Filesystem $filesystem */ $filesystem = $objectManager->get('Magento\\TestFramework\\App\\Filesystem'); $objectManager->removeSharedInstance('Magento\\Framework\\Filesystem'); $objectManager->addSharedInstance($filesystem, 'Magento\\Framework\\Filesystem'); /** @var \Psr\Log\LoggerInterface $logger */ $logger = $objectManager->create('Magento\\TestFramework\\ErrorLog\\Logger', ['name' => 'integration-tests', 'handlers' => ['system' => $objectManager->create('Magento\\Framework\\Logger\\Handler\\System', ['exceptionHandler' => $objectManager->create('Magento\\Framework\\Logger\\Handler\\Exception', ['filePath' => $this->installDir]), 'filePath' => $this->installDir]), 'debug' => $objectManager->create('Magento\\Framework\\Logger\\Handler\\Debug', ['filePath' => $this->installDir])]]); $objectManager->removeSharedInstance('Magento\\Framework\\Logger\\Monolog'); $objectManager->addSharedInstance($logger, 'Magento\\Framework\\Logger\\Monolog'); $sequenceBuilder = $objectManager->get('\\Magento\\TestFramework\\Db\\Sequence\\Builder'); $objectManager->addSharedInstance($sequenceBuilder, 'Magento\\SalesSequence\\Model\\Builder'); Helper\Bootstrap::setObjectManager($objectManager); $objectManagerConfiguration = ['preferences' => ['Magento\\Framework\\App\\State' => 'Magento\\TestFramework\\App\\State', 'Magento\\Framework\\Mail\\TransportInterface' => 'Magento\\TestFramework\\Mail\\TransportInterfaceMock', 'Magento\\Framework\\Mail\\Template\\TransportBuilder' => 'Magento\\TestFramework\\Mail\\Template\\TransportBuilderMock']]; if ($this->loadTestExtensionAttributes) { $objectManagerConfiguration = array_merge($objectManagerConfiguration, ['Magento\\Framework\\Api\\ExtensionAttribute\\Config\\Reader' => ['arguments' => ['fileResolver' => ['instance' => 'Magento\\TestFramework\\Api\\Config\\Reader\\FileResolver']]]]); } $objectManager->configure($objectManagerConfiguration); /** Register event observer of Integration Framework */ /** @var \Magento\Framework\Event\Config\Data $eventConfigData */ $eventConfigData = $objectManager->get('Magento\\Framework\\Event\\Config\\Data'); $eventConfigData->merge(['core_app_init_current_store_after' => ['integration_tests' => ['instance' => 'Magento\\TestFramework\\Event\\Magento', 'name' => 'integration_tests']]]); $this->loadArea(\Magento\TestFramework\Application::DEFAULT_APP_AREA); \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->configure($objectManager->get('Magento\\Framework\\ObjectManager\\DynamicConfigInterface')->getConfiguration()); \Magento\Framework\Phrase::setRenderer($objectManager->get('Magento\\Framework\\Phrase\\Renderer\\Placeholder')); /** @var \Magento\TestFramework\Db\Sequence $sequence */ $sequence = $objectManager->get('Magento\\TestFramework\\Db\\Sequence'); $sequence->generateSequences(); $objectManager->create('Magento\\TestFramework\\Config', ['configPath' => $this->globalConfigFile])->rewriteAdditionalConfig(); }