Application.php 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\TestFramework;
  7. use Magento\Framework\Autoload\AutoloaderInterface;
  8. use Magento\Framework\App\Filesystem\DirectoryList;
  9. use Magento\Framework\App\DeploymentConfig;
  10. use Magento\Framework\Config\ConfigOptionsListConstants;
  11. use Magento\Framework\App\DeploymentConfig\Reader;
  12. use Magento\Framework\Filesystem\Glob;
  13. /**
  14. * Encapsulates application installation, initialization and uninstall.
  15. *
  16. * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
  17. * @SuppressWarnings(PHPMD.TooManyFields)
  18. */
  19. class Application
  20. {
  21. /**
  22. * Default application area.
  23. */
  24. const DEFAULT_APP_AREA = 'global';
  25. /**
  26. * DB vendor adapter instance.
  27. *
  28. * @var \Magento\TestFramework\Db\AbstractDb
  29. */
  30. protected $_db;
  31. /**
  32. * Shell command executor.
  33. *
  34. * @var \Magento\Framework\Shell
  35. */
  36. protected $_shell;
  37. /**
  38. * Configuration file that contains installation parameters.
  39. *
  40. * @var string
  41. */
  42. private $installConfigFile;
  43. /**
  44. * The loaded installation parameters.
  45. *
  46. * @var array
  47. */
  48. protected $installConfig;
  49. /**
  50. * Application *.xml configuration files.
  51. *
  52. * @var array
  53. */
  54. protected $_globalConfigDir;
  55. /**
  56. * Installation destination directory.
  57. *
  58. * @var string
  59. */
  60. protected $installDir;
  61. /**
  62. * Installation destination directory with configuration files.
  63. *
  64. * @var string
  65. */
  66. protected $_configDir;
  67. /**
  68. * Application initialization parameters.
  69. *
  70. * @var array
  71. */
  72. protected $_initParams = [];
  73. /**
  74. * Mode to run application.
  75. *
  76. * @var string
  77. */
  78. protected $_appMode;
  79. /**
  80. * Application area.
  81. *
  82. * @var null
  83. */
  84. protected $_appArea = null;
  85. /**
  86. * Primary DI Config.
  87. *
  88. * @var array
  89. */
  90. protected $_primaryConfigData = [];
  91. /**
  92. * Object manager factory.
  93. *
  94. * @var \Magento\TestFramework\ObjectManagerFactory
  95. */
  96. protected $_factory;
  97. /**
  98. * Directory list.
  99. *
  100. * @var \Magento\Framework\App\Filesystem\DirectoryList
  101. */
  102. protected $dirList;
  103. /**
  104. * Config file for integration tests.
  105. *
  106. * @var string
  107. */
  108. private $globalConfigFile;
  109. /**
  110. * Defines whether load test extension attributes or not.
  111. *
  112. * @var bool
  113. */
  114. private $loadTestExtensionAttributes;
  115. /**
  116. * @var bool
  117. */
  118. protected $dumpDb = true;
  119. /**
  120. * @var bool
  121. */
  122. protected $canLoadArea = true;
  123. /**
  124. * @var bool
  125. */
  126. protected $canInstallSequence = true;
  127. /**
  128. * Constructor.
  129. *
  130. * @param \Magento\Framework\Shell $shell
  131. * @param string $installDir
  132. * @param array $installConfigFile
  133. * @param string $globalConfigFile
  134. * @param string $globalConfigDir
  135. * @param string $appMode
  136. * @param AutoloaderInterface $autoloadWrapper
  137. * @param bool|null $loadTestExtensionAttributes
  138. */
  139. public function __construct(
  140. \Magento\Framework\Shell $shell,
  141. $installDir,
  142. $installConfigFile,
  143. $globalConfigFile,
  144. $globalConfigDir,
  145. $appMode,
  146. AutoloaderInterface $autoloadWrapper,
  147. $loadTestExtensionAttributes = false
  148. ) {
  149. if (getcwd() != BP . '/dev/tests/integration') {
  150. chdir(BP . '/dev/tests/integration');
  151. }
  152. $this->_shell = $shell;
  153. $this->installConfigFile = $installConfigFile;
  154. $this->_globalConfigDir = realpath($globalConfigDir);
  155. $this->_appMode = $appMode;
  156. $this->installDir = $installDir;
  157. $this->loadTestExtensionAttributes = $loadTestExtensionAttributes;
  158. $customDirs = $this->getCustomDirs();
  159. $this->dirList = new \Magento\Framework\App\Filesystem\DirectoryList(BP, $customDirs);
  160. \Magento\Framework\Autoload\Populator::populateMappings(
  161. $autoloadWrapper,
  162. $this->dirList
  163. );
  164. $this->_initParams = [
  165. \Magento\Framework\App\Bootstrap::INIT_PARAM_FILESYSTEM_DIR_PATHS => $customDirs,
  166. \Magento\Framework\App\State::PARAM_MODE => $appMode
  167. ];
  168. $driverPool = new \Magento\Framework\Filesystem\DriverPool;
  169. $configFilePool = new \Magento\Framework\Config\File\ConfigFilePool;
  170. $this->_factory = new \Magento\TestFramework\ObjectManagerFactory($this->dirList, $driverPool, $configFilePool);
  171. $this->_configDir = $this->dirList->getPath(DirectoryList::CONFIG);
  172. $this->globalConfigFile = $globalConfigFile;
  173. }
  174. /**
  175. * Retrieve the database adapter instance.
  176. *
  177. * @return \Magento\TestFramework\Db\AbstractDb
  178. */
  179. public function getDbInstance()
  180. {
  181. if (null === $this->_db) {
  182. if ($this->isInstalled()) {
  183. $configPool = new \Magento\Framework\Config\File\ConfigFilePool();
  184. $driverPool = new \Magento\Framework\Filesystem\DriverPool();
  185. $reader = new Reader($this->dirList, $driverPool, $configPool);
  186. $deploymentConfig = new DeploymentConfig($reader, []);
  187. $host = $deploymentConfig->get(
  188. ConfigOptionsListConstants::CONFIG_PATH_DB_CONNECTION_DEFAULT .
  189. '/' . ConfigOptionsListConstants::KEY_HOST
  190. );
  191. $user = $deploymentConfig->get(
  192. ConfigOptionsListConstants::CONFIG_PATH_DB_CONNECTION_DEFAULT .
  193. '/' . ConfigOptionsListConstants::KEY_USER
  194. );
  195. $password = $deploymentConfig->get(
  196. ConfigOptionsListConstants::CONFIG_PATH_DB_CONNECTION_DEFAULT .
  197. '/' . ConfigOptionsListConstants::KEY_PASSWORD
  198. );
  199. $dbName = $deploymentConfig->get(
  200. ConfigOptionsListConstants::CONFIG_PATH_DB_CONNECTION_DEFAULT .
  201. '/' . ConfigOptionsListConstants::KEY_NAME
  202. );
  203. } else {
  204. $installConfig = $this->getInstallConfig();
  205. $host = $installConfig['db-host'];
  206. $user = $installConfig['db-user'];
  207. $password = $installConfig['db-password'];
  208. $dbName = $installConfig['db-name'];
  209. }
  210. $this->_db = new Db\Mysql(
  211. $host,
  212. $user,
  213. $password,
  214. $dbName,
  215. $this->getTempDir(),
  216. $this->_shell
  217. );
  218. }
  219. return $this->_db;
  220. }
  221. /**
  222. * Gets installation parameters.
  223. *
  224. * @return array
  225. */
  226. protected function getInstallConfig()
  227. {
  228. if (null === $this->installConfig) {
  229. $this->installConfig = include $this->installConfigFile;
  230. }
  231. return $this->installConfig;
  232. }
  233. /**
  234. * Gets deployment configuration path.
  235. *
  236. * @return string
  237. */
  238. private function getLocalConfig()
  239. {
  240. return $this->_configDir . '/config.php';
  241. }
  242. /**
  243. * Get path to temporary directory.
  244. *
  245. * @return string
  246. */
  247. public function getTempDir()
  248. {
  249. return $this->installDir;
  250. }
  251. /**
  252. * Retrieve application initialization parameters.
  253. *
  254. * @return array
  255. */
  256. public function getInitParams()
  257. {
  258. return $this->_initParams;
  259. }
  260. /**
  261. * Weather the application is installed or not.
  262. *
  263. * @return bool
  264. */
  265. public function isInstalled()
  266. {
  267. return is_file($this->getLocalConfig());
  268. }
  269. /**
  270. * Create logger instance and rewrite already exist one in ObjectManager.
  271. *
  272. * @return \Psr\Log\LoggerInterface
  273. */
  274. private function initLogger()
  275. {
  276. $objectManager = Helper\Bootstrap::getObjectManager();
  277. /** @var \Psr\Log\LoggerInterface $logger */
  278. $logger = $objectManager->create(
  279. \Magento\TestFramework\ErrorLog\Logger::class,
  280. [
  281. 'name' => 'integration-tests',
  282. 'handlers' => [
  283. 'system' => $objectManager->create(
  284. \Magento\Framework\Logger\Handler\System::class,
  285. [
  286. 'exceptionHandler' => $objectManager->create(
  287. \Magento\Framework\Logger\Handler\Exception::class,
  288. ['filePath' => $this->installDir]
  289. ),
  290. 'filePath' => $this->installDir
  291. ]
  292. ),
  293. 'debug' => $objectManager->create(
  294. \Magento\Framework\Logger\Handler\Debug::class,
  295. ['filePath' => $this->installDir]
  296. ),
  297. ]
  298. ]
  299. );
  300. $objectManager->removeSharedInstance(\Magento\Framework\Logger\Monolog::class);
  301. $objectManager->addSharedInstance($logger, \Magento\Framework\Logger\Monolog::class);
  302. return $logger;
  303. }
  304. /**
  305. * Initialize application
  306. *
  307. * @param array $overriddenParams
  308. * @return void
  309. */
  310. public function initialize($overriddenParams = [])
  311. {
  312. $overriddenParams[\Magento\Framework\App\State::PARAM_MODE] = $this->_appMode;
  313. $overriddenParams = $this->_customizeParams($overriddenParams);
  314. $directories = isset($overriddenParams[\Magento\Framework\App\Bootstrap::INIT_PARAM_FILESYSTEM_DIR_PATHS])
  315. ? $overriddenParams[\Magento\Framework\App\Bootstrap::INIT_PARAM_FILESYSTEM_DIR_PATHS]
  316. : [];
  317. $directoryList = new DirectoryList(BP, $directories);
  318. /** @var \Magento\TestFramework\ObjectManager $objectManager */
  319. $objectManager = Helper\Bootstrap::getObjectManager();
  320. if (!$objectManager) {
  321. $objectManager = $this->_factory->create($overriddenParams);
  322. $objectManager->addSharedInstance($directoryList, \Magento\Framework\App\Filesystem\DirectoryList::class);
  323. $objectManager->addSharedInstance($directoryList, \Magento\Framework\Filesystem\DirectoryList::class);
  324. } else {
  325. $objectManager = $this->_factory->restore($objectManager, $directoryList, $overriddenParams);
  326. }
  327. /** @var \Magento\TestFramework\App\Filesystem $filesystem */
  328. $filesystem = $objectManager->get(\Magento\TestFramework\App\Filesystem::class);
  329. $objectManager->removeSharedInstance(\Magento\Framework\Filesystem::class);
  330. $objectManager->addSharedInstance($filesystem, \Magento\Framework\Filesystem::class);
  331. Helper\Bootstrap::setObjectManager($objectManager);
  332. $this->initLogger();
  333. $sequenceBuilder = $objectManager->get(\Magento\TestFramework\Db\Sequence\Builder::class);
  334. $objectManager->addSharedInstance($sequenceBuilder, \Magento\SalesSequence\Model\Builder::class);
  335. $objectManagerConfiguration = [
  336. 'preferences' => [
  337. \Magento\Framework\App\State::class => \Magento\TestFramework\App\State::class,
  338. \Magento\Framework\Mail\TransportInterface::class =>
  339. \Magento\TestFramework\Mail\TransportInterfaceMock::class,
  340. \Magento\Framework\Mail\Template\TransportBuilder::class
  341. => \Magento\TestFramework\Mail\Template\TransportBuilderMock::class,
  342. ]
  343. ];
  344. if ($this->loadTestExtensionAttributes) {
  345. $objectManagerConfiguration = array_merge(
  346. $objectManagerConfiguration,
  347. [
  348. \Magento\Framework\Api\ExtensionAttribute\Config\Reader::class => [
  349. 'arguments' => [
  350. 'fileResolver' => [
  351. 'instance' => \Magento\TestFramework\Api\Config\Reader\FileResolver::class
  352. ],
  353. ],
  354. ],
  355. ]
  356. );
  357. }
  358. $objectManager->configure($objectManagerConfiguration);
  359. /** Register event observer of Integration Framework */
  360. /** @var \Magento\Framework\Event\Config\Data $eventConfigData */
  361. $eventConfigData = $objectManager->get(\Magento\Framework\Event\Config\Data::class);
  362. $eventConfigData->merge(
  363. [
  364. 'core_app_init_current_store_after' => [
  365. 'integration_tests' => [
  366. 'instance' => \Magento\TestFramework\Event\Magento::class,
  367. 'name' => 'integration_tests'
  368. ]
  369. ]
  370. ]
  371. );
  372. if ($this->canLoadArea) {
  373. $this->loadArea(\Magento\TestFramework\Application::DEFAULT_APP_AREA);
  374. }
  375. \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->configure(
  376. $objectManager->get(\Magento\Framework\ObjectManager\DynamicConfigInterface::class)->getConfiguration()
  377. );
  378. \Magento\Framework\Phrase::setRenderer(
  379. $objectManager->get(\Magento\Framework\Phrase\Renderer\Placeholder::class)
  380. );
  381. if ($this->canInstallSequence) {
  382. /** @var \Magento\TestFramework\Db\Sequence $sequence */
  383. $sequence = $objectManager->get(\Magento\TestFramework\Db\Sequence::class);
  384. $sequence->generateSequences();
  385. }
  386. $objectManager->create(\Magento\TestFramework\Config::class, ['configPath' => $this->globalConfigFile])
  387. ->rewriteAdditionalConfig();
  388. }
  389. /**
  390. * Reset and initialize again an already installed application
  391. *
  392. * @param array $overriddenParams
  393. * @return void
  394. */
  395. public function reinitialize(array $overriddenParams = [])
  396. {
  397. $this->_resetApp();
  398. $this->initialize($overriddenParams);
  399. }
  400. /**
  401. * Run application normally, but with encapsulated initialization options
  402. *
  403. * @return void
  404. */
  405. public function run()
  406. {
  407. $objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
  408. /** @var \Magento\Framework\App\Http $app */
  409. $app = $objectManager->get(\Magento\Framework\App\Http::class);
  410. $response = $app->launch();
  411. $response->sendResponse();
  412. }
  413. /**
  414. * Create install dir for integration framework
  415. *
  416. * @return void
  417. */
  418. public function createInstallDir()
  419. {
  420. $this->_ensureDirExists($this->installDir);
  421. $this->_ensureDirExists($this->_configDir);
  422. $this->copyAppConfigFiles();
  423. }
  424. /**
  425. * Cleanup both the database and the file system
  426. *
  427. * @return void
  428. */
  429. public function cleanup()
  430. {
  431. $this->createInstallDir();
  432. /**
  433. * @see \Magento\Setup\Mvc\Bootstrap\InitParamListener::BOOTSTRAP_PARAM
  434. */
  435. $this->_shell->execute(
  436. PHP_BINARY . ' -f %s setup:uninstall -vvv -n --magento-init-params=%s',
  437. [BP . '/bin/magento', $this->getInitParamsQuery()]
  438. );
  439. }
  440. /**
  441. * Install an application
  442. *
  443. * @param bool $cleanup
  444. * @return void
  445. * @throws \Magento\Framework\Exception\LocalizedException
  446. */
  447. public function install($cleanup)
  448. {
  449. $dirs = \Magento\Framework\App\Bootstrap::INIT_PARAM_FILESYSTEM_DIR_PATHS;
  450. $this->_ensureDirExists($this->installDir);
  451. $this->_ensureDirExists($this->_configDir);
  452. $this->_ensureDirExists($this->_initParams[$dirs][DirectoryList::PUB][DirectoryList::PATH]);
  453. $this->_ensureDirExists($this->_initParams[$dirs][DirectoryList::MEDIA][DirectoryList::PATH]);
  454. $this->_ensureDirExists($this->_initParams[$dirs][DirectoryList::STATIC_VIEW][DirectoryList::PATH]);
  455. $this->_ensureDirExists($this->_initParams[$dirs][DirectoryList::VAR_DIR][DirectoryList::PATH]);
  456. $this->copyAppConfigFiles();
  457. $this->copyGlobalConfigFile();
  458. $installParams = $this->getInstallCliParams();
  459. // performance optimization: restore DB from last good dump to make installation on top of it (much faster)
  460. // do not restore from the database if the cleanup option is set to ensure we have a clean DB to test on
  461. $db = $this->getDbInstance();
  462. if ($db->isDbDumpExists() && !$cleanup) {
  463. $db->restoreFromDbDump();
  464. }
  465. // run install script
  466. $this->_shell->execute(
  467. PHP_BINARY . ' -f %s setup:install -vvv ' . implode(' ', array_keys($installParams)),
  468. array_merge([BP . '/bin/magento'], array_values($installParams))
  469. );
  470. // enable only specified list of caches
  471. $initParamsQuery = $this->getInitParamsQuery();
  472. $this->_shell->execute(
  473. PHP_BINARY . ' -f %s cache:disable -vvv --bootstrap=%s',
  474. [BP . '/bin/magento', $initParamsQuery]
  475. );
  476. $this->_shell->execute(
  477. PHP_BINARY . ' -f %s cache:enable -vvv %s %s %s %s --bootstrap=%s',
  478. [
  479. BP . '/bin/magento',
  480. \Magento\Framework\App\Cache\Type\Config::TYPE_IDENTIFIER,
  481. \Magento\Framework\App\Cache\Type\Layout::TYPE_IDENTIFIER,
  482. \Magento\Framework\App\Cache\Type\Translate::TYPE_IDENTIFIER,
  483. \Magento\Eav\Model\Cache\Type::TYPE_IDENTIFIER,
  484. $initParamsQuery,
  485. ]
  486. );
  487. // right after a clean installation, store DB dump for future reuse in tests or running the test suite again
  488. if (!$db->isDbDumpExists() && $this->dumpDb) {
  489. $this->getDbInstance()->storeDbDump();
  490. }
  491. }
  492. /**
  493. * Copies configuration files from the main code base, so the installation could proceed in the tests directory
  494. *
  495. * @return void
  496. */
  497. private function copyAppConfigFiles()
  498. {
  499. $globalConfigFiles = Glob::glob(
  500. $this->_globalConfigDir . '/{di.xml,*/di.xml,db_schema.xml,vendor_path.php}',
  501. Glob::GLOB_BRACE
  502. );
  503. foreach ($globalConfigFiles as $file) {
  504. $targetFile = $this->_configDir . str_replace($this->_globalConfigDir, '', $file);
  505. $this->_ensureDirExists(dirname($targetFile));
  506. if ($file !== $targetFile) {
  507. copy($file, $targetFile);
  508. }
  509. }
  510. }
  511. /**
  512. * Copies global configuration file from the tests folder (see TESTS_GLOBAL_CONFIG_FILE)
  513. *
  514. * @return void
  515. */
  516. private function copyGlobalConfigFile()
  517. {
  518. $targetFile = $this->_configDir . '/config.local.php';
  519. copy($this->globalConfigFile, $targetFile);
  520. }
  521. /**
  522. * Gets a list of CLI params for installation
  523. *
  524. * @return array
  525. */
  526. private function getInstallCliParams()
  527. {
  528. $params = $this->getInstallConfig();
  529. /**
  530. * Literal value is used instead of constant, because autoloader is not integrated with Magento Setup app
  531. * @see \Magento\Setup\Mvc\Bootstrap\InitParamListener::BOOTSTRAP_PARAM
  532. */
  533. $params['magento-init-params'] = $this->getInitParamsQuery();
  534. $result = [];
  535. foreach ($params as $key => $value) {
  536. if (!empty($value)) {
  537. $result["--{$key}=%s"] = $value;
  538. }
  539. }
  540. return $result;
  541. }
  542. /**
  543. * Encodes init params into a query string
  544. *
  545. * @return string
  546. */
  547. private function getInitParamsQuery()
  548. {
  549. return urldecode(http_build_query($this->_initParams));
  550. }
  551. /**
  552. * Sub-routine for merging custom parameters with the ones defined in object state
  553. *
  554. * @param array $params
  555. * @return array
  556. */
  557. public function _customizeParams($params)
  558. {
  559. return array_replace_recursive($this->_initParams, $params);
  560. }
  561. /**
  562. * Reset application global state
  563. */
  564. protected function _resetApp()
  565. {
  566. /** @var $objectManager \Magento\TestFramework\ObjectManager */
  567. $objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
  568. $objectManager->clearCache();
  569. \Magento\Framework\Data\Form::setElementRenderer(null);
  570. \Magento\Framework\Data\Form::setFieldsetRenderer(null);
  571. \Magento\Framework\Data\Form::setFieldsetElementRenderer(null);
  572. $this->_appArea = null;
  573. }
  574. /**
  575. * Create a directory with write permissions or don't touch existing one
  576. *
  577. * @param string $dir
  578. * @return void
  579. * @throws \Magento\Framework\Exception\LocalizedException
  580. */
  581. protected function _ensureDirExists($dir)
  582. {
  583. if (!file_exists($dir)) {
  584. $old = umask(0);
  585. mkdir($dir, 0777, true);
  586. umask($old);
  587. } elseif (!is_dir($dir)) {
  588. throw new \Magento\Framework\Exception\LocalizedException(__("'%1' is not a directory.", $dir));
  589. }
  590. }
  591. /**
  592. * Ge current application area
  593. *
  594. * @return string
  595. */
  596. public function getArea()
  597. {
  598. return $this->_appArea;
  599. }
  600. /**
  601. * Load application area
  602. *
  603. * @param string $areaCode
  604. * @return void
  605. * @throws \Magento\Framework\Exception\LocalizedException
  606. */
  607. public function loadArea($areaCode)
  608. {
  609. $this->_appArea = $areaCode;
  610. $scope = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
  611. \Magento\Framework\Config\Scope::class
  612. );
  613. $scope->setCurrentScope($areaCode);
  614. \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->configure(
  615. \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
  616. \Magento\Framework\App\ObjectManager\ConfigLoader::class
  617. )->load(
  618. $areaCode
  619. )
  620. );
  621. $app = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(\Magento\Framework\App\AreaList::class);
  622. $areasForPartialLoading = [
  623. \Magento\Framework\App\Area::AREA_GLOBAL,
  624. \Magento\Framework\App\Area::AREA_WEBAPI_REST,
  625. \Magento\Framework\App\Area::AREA_WEBAPI_SOAP,
  626. \Magento\Framework\App\Area::AREA_CRONTAB,
  627. \Magento\Framework\App\Area::AREA_GRAPHQL
  628. ];
  629. if (in_array($areaCode, $areasForPartialLoading, true)) {
  630. $app->getArea($areaCode)->load(\Magento\Framework\App\Area::PART_CONFIG);
  631. } else {
  632. \Magento\TestFramework\Helper\Bootstrap::getInstance()->loadArea($areaCode);
  633. }
  634. }
  635. /**
  636. * Gets customized directory paths
  637. *
  638. * @return array
  639. */
  640. protected function getCustomDirs()
  641. {
  642. $path = DirectoryList::PATH;
  643. $var = "{$this->installDir}/var";
  644. $generated = "{$this->installDir}/generated";
  645. $customDirs = [
  646. DirectoryList::CONFIG => [$path => "{$this->installDir}/etc"],
  647. DirectoryList::VAR_DIR => [$path => $var],
  648. DirectoryList::MEDIA => [$path => "{$this->installDir}/pub/media"],
  649. DirectoryList::STATIC_VIEW => [$path => "{$this->installDir}/pub/static"],
  650. DirectoryList::TMP_MATERIALIZATION_DIR => [$path => "{$var}/view_preprocessed/pub/static"],
  651. DirectoryList::GENERATED_CODE => [$path => "{$generated}/code"],
  652. DirectoryList::CACHE => [$path => "{$var}/cache"],
  653. DirectoryList::LOG => [$path => "{$var}/log"],
  654. DirectoryList::SESSION => [$path => "{$var}/session"],
  655. DirectoryList::TMP => [$path => "{$var}/tmp"],
  656. DirectoryList::UPLOAD => [$path => "{$var}/upload"],
  657. DirectoryList::PUB => [$path => "{$this->installDir}/pub"],
  658. ];
  659. return $customDirs;
  660. }
  661. }