public static function setUpBeforeClass() { $config = new \Magento\Framework\ObjectManager\Config\Config(); $factory = new \Magento\Framework\ObjectManager\Factory\Factory($config); self::$_objectManager = new \Magento\Framework\ObjectManager\ObjectManager($factory, $config); self::$_objectManager->configure(array('preferences' => array(self::TEST_INTERFACE => self::TEST_INTERFACE_IMPLEMENTATION))); $factory->setObjectManager(self::$_objectManager); }
/** * @magentoConfigFixture current_store catalog/productalert/allow_price 1 * * @magentoDataFixture Magento/ProductAlert/_files/product_alert.php */ public function testProcess() { $this->_objectManager->configure(['Magento\\ProductAlert\\Model\\Observer' => ['arguments' => ['transportBuilder' => ['instance' => 'Magento\\TestFramework\\Mail\\Template\\TransportBuilderMock']]], 'Magento\\ProductAlert\\Model\\Email' => ['arguments' => ['transportBuilder' => ['instance' => 'Magento\\TestFramework\\Mail\\Template\\TransportBuilderMock']]], 'preferences' => ['Magento\\Framework\\Mail\\TransportInterface' => 'Magento\\TestFramework\\Mail\\TransportInterfaceMock', 'Magento\\TestFramework\\Mail\\Template\\TransportBuilder' => 'Magento\\TestFramework\\Mail\\Template\\TransportBuilderMock']]); \Magento\TestFramework\Helper\Bootstrap::getInstance()->loadArea(\Magento\Framework\App\Area::AREA_FRONTEND); $observer = $this->_objectManager->get('Magento\\ProductAlert\\Model\\Observer'); $observer->process(); /** @var \Magento\TestFramework\Mail\Template\TransportBuilderMock $transportBuilder */ $transportBuilder = $this->_objectManager->get('Magento\\TestFramework\\Mail\\Template\\TransportBuilderMock'); $this->assertStringMatchesFormat('%AHello %A' . $this->_customerViewHelper->getCustomerName($this->_customerSession->getCustomerDataObject()) . ',%A', $transportBuilder->getSentMessage()->getBodyHtml()->getContent()); }
/** * Run application * * @return \Magento\Framework\App\ResponseInterface */ public function launch() { $areaCode = 'install'; $this->_state->setAreaCode($areaCode); $this->_objectManager->configure($this->_loader->load($areaCode)); if (isset($this->_arguments['uninstall'])) { $sessionConsole = $this->_objectManager->create('\\Magento\\Framework\\Session\\SessionConsole'); $installerModel = $this->_objectManager->create('Magento\\Install\\Model\\Installer', ['session' => $sessionConsole]); $installer = $this->_installerFactory->create(['installArgs' => $this->_arguments, 'installer' => $installerModel]); } else { $installer = $this->_installerFactory->create(array('installArgs' => $this->_arguments)); } if (isset($this->_arguments['show_locales'])) { $this->_output->readableOutput($this->_output->prepareArray($installer->getAvailableLocales())); } elseif (isset($this->_arguments['show_currencies'])) { $this->_output->readableOutput($this->_output->prepareArray($installer->getAvailableCurrencies())); } elseif (isset($this->_arguments['show_timezones'])) { $this->_output->readableOutput($this->_output->prepareArray($installer->getAvailableTimezones())); } elseif (isset($this->_arguments['show_install_options'])) { $this->_output->readableOutput(PHP_EOL . 'Required parameters:'); $this->_output->readableOutput($this->_output->alignArrayKeys($installer->getRequiredParams())); $this->_output->readableOutput(PHP_EOL . 'Optional parameters:'); $this->_output->readableOutput($this->_output->alignArrayKeys($installer->getOptionalParams())); $this->_output->readableOutput(PHP_EOL . 'Flag values are considered positive if set to 1, y, true or yes.' . 'Any other value is considered as negative.' . PHP_EOL); } else { $this->_handleInstall($installer); } $this->_response->setCode(0); return $this->_response; }
/** * Finds requested resource and provides it to the client * * @return \Magento\Framework\App\ResponseInterface * @throws \Exception */ public function launch() { $appMode = $this->state->getMode(); if ($appMode == \Magento\Framework\App\State::MODE_PRODUCTION) { $this->response->setHttpResponseCode(404); } else { try { $path = $this->request->get('resource'); $params = $this->parsePath($path); $this->state->setAreaCode($params['area']); $this->objectManager->configure($this->configLoader->load($params['area'])); $file = $params['file']; unset($params['file']); $asset = $this->assetRepo->createAsset($file, $params); $this->response->setFilePath($asset->getSourceFile()); $this->publisher->publish($asset); } catch (\Exception $e) { if ($appMode == \Magento\Framework\App\State::MODE_DEVELOPER) { throw $e; } $this->response->setHttpResponseCode(404); } } return $this->response; }
/** * Run application * * @return ResponseInterface */ public function launch() { $areaCode = $this->_areaList->getCodeByFrontName($this->_request->getFrontName()); $this->_state->setAreaCode($areaCode); $this->_objectManager->configure($this->_configLoader->load($areaCode)); $this->_response = $this->_objectManager->get('Magento\\Framework\\App\\FrontControllerInterface')->dispatch($this->_request); // This event gives possibility to launch something before sending output (allow cookie setting) $eventParams = array('request' => $this->_request, 'response' => $this->_response); $this->_eventManager->dispatch('controller_front_send_response_before', $eventParams); return $this->_response; }
/** * Run application * * @return ResponseInterface */ public function launch() { try { $areaCode = $this->_areaList->getCodeByFrontName($this->_request->getFrontName()); $this->_state->setAreaCode($areaCode); $this->_objectManager->configure($this->_configLoader->load($areaCode)); $this->_response = $this->_objectManager->get('Magento\\Framework\\App\\FrontControllerInterface')->dispatch($this->_request); // This event gives possibility to launch something before sending output (allow cookie setting) $eventParams = array('request' => $this->_request, 'response' => $this->_response); $this->_eventManager->dispatch('controller_front_send_response_before', $eventParams); } catch (\Exception $exception) { $message = $exception->getMessage() . "\n"; try { if ($this->_state->getMode() == State::MODE_DEVELOPER) { $message .= '<pre>'; $message .= $exception->getMessage() . "\n\n"; $message .= $exception->getTraceAsString(); $message .= '</pre>'; } else { $reportData = array($exception->getMessage(), $exception->getTraceAsString()); // retrieve server data if (isset($_SERVER)) { if (isset($_SERVER['REQUEST_URI'])) { $reportData['url'] = $_SERVER['REQUEST_URI']; } if (isset($_SERVER['SCRIPT_NAME'])) { $reportData['script_name'] = $_SERVER['SCRIPT_NAME']; } } require_once $this->_filesystem->getPath(Filesystem::PUB_DIR) . '/errors/report.php'; $processor = new \Magento\Framework\Error\Processor($this->_response); $processor->saveReport($reportData); $this->_response = $processor->processReport(); } } catch (\Exception $exception) { $message .= "Unknown error happened."; } $this->_response->setHttpResponseCode(500); $this->_response->setBody($message); } return $this->_response; }
/** * Configure Object Manager * This method is static to have the ability to configure multiple instances of Object manager when needed * * @param MagentoObjectManager $objectManager */ public static function configure(MagentoObjectManager $objectManager) { $objectManager->configure($objectManager->get('Mtf\\ObjectManager\\ConfigLoader\\Primary')->load()); $objectManager->configure($objectManager->get('Mtf\\ObjectManager\\ConfigLoader\\Module')->load()); $objectManager->configure($objectManager->get('Mtf\\ObjectManager\\ConfigLoader\\Module')->load('etc/ui')); $objectManager->configure($objectManager->get('Mtf\\ObjectManager\\ConfigLoader\\Module')->load('etc/curl')); }
/** * Replace name of url model * * @param string $className * @return $this */ public function replaceClassName($className) { $this->_objectManager->configure(array('preferences' => array(self::CLASS_NAME => $className))); return $this; }
/** * Load area configuration * * @return $this */ protected function _initConfig() { $this->_objectManager->configure($this->_diConfigLoader->load($this->_code)); return $this; }
/** * @param string $areaCode * @return void */ public function emulateLayoutArea($areaCode) { $configuration = array('Magento\\Framework\\View\\Layout' => array('arguments' => array('area' => $areaCode))); $this->_objectManager->configure($configuration); }