bootstrap.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. use Magento\Framework\Autoload\AutoloaderRegistry;
  7. use Magento\Framework\App\Filesystem\DirectoryList;
  8. require_once __DIR__ . '/../../../../app/bootstrap.php';
  9. require_once __DIR__ . '/autoload.php';
  10. //to handle different types of errors on CI
  11. require __DIR__ . '/../../error_handler.php';
  12. $testsBaseDir = dirname(__DIR__);
  13. $integrationTestsDir = realpath("{$testsBaseDir}/../integration");
  14. $fixtureBaseDir = $integrationTestsDir. '/testsuite';
  15. if (!defined('TESTS_BASE_DIR')) {
  16. define('TESTS_BASE_DIR', $testsBaseDir);
  17. }
  18. if (!defined('TESTS_TEMP_DIR')) {
  19. define('TESTS_TEMP_DIR', $testsBaseDir . '/tmp');
  20. }
  21. if (!defined('TESTS_MODULES_PATH')) {
  22. define('TESTS_MODULES_PATH', $testsBaseDir . '/_files');
  23. }
  24. if (!defined('MAGENTO_MODULES_PATH')) {
  25. define('MAGENTO_MODULES_PATH', __DIR__ . '/../../../../app/code/Magento/');
  26. }
  27. $settings = new \Magento\TestFramework\Bootstrap\Settings($testsBaseDir, get_defined_constants());
  28. try {
  29. setCustomErrorHandler();
  30. $installConfigFile = $settings->getAsConfigFile('TESTS_INSTALL_CONFIG_FILE');
  31. if (!file_exists($installConfigFile)) {
  32. $installConfigFile .= '.dist';
  33. }
  34. if (!defined('TESTS_INSTALLATION_DB_CONFIG_FILE')) {
  35. define('TESTS_INSTALLATION_DB_CONFIG_FILE', $installConfigFile);
  36. }
  37. /* Bootstrap the application */
  38. $shell = new \Magento\Framework\Shell(new \Magento\Framework\Shell\CommandRenderer());
  39. $testFrameworkDir = __DIR__;
  40. $globalConfigFile = $settings->getAsConfigFile('TESTS_GLOBAL_CONFIG_FILE');
  41. if (!file_exists($globalConfigFile)) {
  42. $globalConfigFile .= '.dist';
  43. }
  44. $dirList = new DirectoryList(BP);
  45. $installDir = TESTS_TEMP_DIR;
  46. $application = new \Magento\TestFramework\SetupApplication(
  47. $shell,
  48. $installDir,
  49. $installConfigFile,
  50. $globalConfigFile,
  51. $settings->get('TESTS_GLOBAL_CONFIG_DIR'),
  52. $settings->get('TESTS_MAGENTO_MODE'),
  53. AutoloaderRegistry::getAutoloader(),
  54. false
  55. );
  56. $bootstrap = new \Magento\TestFramework\Bootstrap(
  57. $settings,
  58. new \Magento\TestFramework\Bootstrap\Environment(),
  59. new \Magento\TestFramework\Bootstrap\SetupDocBlock("{$testsBaseDir}/_files/"),
  60. new \Magento\TestFramework\Bootstrap\Profiler(new \Magento\Framework\Profiler\Driver\Standard()),
  61. $shell,
  62. $application,
  63. new \Magento\TestFramework\Bootstrap\MemoryFactory($shell)
  64. );
  65. //remove test modules files
  66. include_once __DIR__ . '/../../setup-integration/framework/removeTestModules.php';
  67. $bootstrap->runBootstrap();
  68. $application->createInstallDir();
  69. //We do not want to install anything
  70. $application->initialize([]);
  71. $application->cleanup();
  72. \Magento\TestFramework\Helper\Bootstrap::setInstance(new \Magento\TestFramework\Helper\Bootstrap($bootstrap));
  73. $dirSearch = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()
  74. ->create(\Magento\Framework\Component\DirSearch::class);
  75. $themePackageList = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()
  76. ->create(\Magento\Framework\View\Design\Theme\ThemePackageList::class);
  77. \Magento\Framework\App\Utility\Files::setInstance(
  78. new Magento\Framework\App\Utility\Files(
  79. new \Magento\Framework\Component\ComponentRegistrar(),
  80. $dirSearch,
  81. $themePackageList
  82. )
  83. );
  84. /* Unset declared global variables to release the PHPUnit from maintaining their values between tests */
  85. unset($testsBaseDir, $logWriter, $settings, $shell, $application, $bootstrap);
  86. } catch (\Exception $e) {
  87. echo $e . PHP_EOL;
  88. exit(1);
  89. }