bootstrap.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. use Magento\Framework\App\Filesystem\DirectoryList;
  7. use Magento\Framework\Autoload\AutoloaderRegistry;
  8. require_once __DIR__ . '/../../../../app/bootstrap.php';
  9. require_once __DIR__ . '/autoload.php';
  10. $testsBaseDir = dirname(__DIR__);
  11. $integrationTestsDir = realpath("{$testsBaseDir}/../integration");
  12. $fixtureBaseDir = $integrationTestsDir . '/testsuite';
  13. if (!defined('TESTS_TEMP_DIR')) {
  14. define('TESTS_TEMP_DIR', $testsBaseDir . '/tmp');
  15. }
  16. if (!defined('INTEGRATION_TESTS_DIR')) {
  17. define('INTEGRATION_TESTS_DIR', $integrationTestsDir);
  18. }
  19. try {
  20. setCustomErrorHandler();
  21. /* Bootstrap the application */
  22. $settings = new \Magento\TestFramework\Bootstrap\Settings($testsBaseDir, get_defined_constants());
  23. if ($settings->get('TESTS_EXTRA_VERBOSE_LOG')) {
  24. $filesystem = new \Magento\Framework\Filesystem\Driver\File();
  25. $exceptionHandler = new \Magento\Framework\Logger\Handler\Exception($filesystem);
  26. $loggerHandlers = [
  27. 'system' => new \Magento\Framework\Logger\Handler\System($filesystem, $exceptionHandler),
  28. 'debug' => new \Magento\Framework\Logger\Handler\Debug($filesystem)
  29. ];
  30. $shell = new \Magento\Framework\Shell(
  31. new \Magento\Framework\Shell\CommandRenderer(),
  32. new \Monolog\Logger('main', $loggerHandlers)
  33. );
  34. } else {
  35. $shell = new \Magento\Framework\Shell(new \Magento\Framework\Shell\CommandRenderer());
  36. }
  37. $testFrameworkDir = __DIR__;
  38. require_once INTEGRATION_TESTS_DIR . '/framework/deployTestModules.php';
  39. $installConfigFile = $settings->getAsConfigFile('TESTS_INSTALL_CONFIG_FILE');
  40. if (!file_exists($installConfigFile)) {
  41. $installConfigFile = $installConfigFile . '.dist';
  42. }
  43. $globalConfigFile = $settings->getAsConfigFile('TESTS_GLOBAL_CONFIG_FILE');
  44. if (!file_exists($installConfigFile)) {
  45. $installConfigFile = $installConfigFile . '.dist';
  46. }
  47. $dirList = new \Magento\Framework\App\Filesystem\DirectoryList(BP);
  48. $application = new \Magento\TestFramework\WebApiApplication(
  49. $shell,
  50. $dirList->getPath(DirectoryList::VAR_DIR),
  51. $installConfigFile,
  52. $globalConfigFile,
  53. BP . '/app/etc/',
  54. $settings->get('TESTS_MAGENTO_MODE'),
  55. AutoloaderRegistry::getAutoloader()
  56. );
  57. if (defined('TESTS_MAGENTO_INSTALLATION') && TESTS_MAGENTO_INSTALLATION === 'enabled') {
  58. $cleanup = (defined('TESTS_CLEANUP') && TESTS_CLEANUP === 'enabled');
  59. $application->install($cleanup);
  60. }
  61. $bootstrap = new \Magento\TestFramework\Bootstrap(
  62. $settings,
  63. new \Magento\TestFramework\Bootstrap\Environment(),
  64. new \Magento\TestFramework\Bootstrap\WebapiDocBlock("{$integrationTestsDir}/testsuite"),
  65. new \Magento\TestFramework\Bootstrap\Profiler(new \Magento\Framework\Profiler\Driver\Standard()),
  66. $shell,
  67. $application,
  68. new \Magento\TestFramework\Bootstrap\MemoryFactory($shell)
  69. );
  70. $bootstrap->runBootstrap();
  71. $application->initialize();
  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($bootstrap, $application, $settings, $shell);
  85. } catch (\Exception $e) {
  86. echo $e . PHP_EOL;
  87. exit(1);
  88. }
  89. /**
  90. * Set custom error handler
  91. */
  92. function setCustomErrorHandler()
  93. {
  94. set_error_handler(
  95. function ($errNo, $errStr, $errFile, $errLine) {
  96. if (error_reporting()) {
  97. $errorNames = [
  98. E_ERROR => 'Error',
  99. E_WARNING => 'Warning',
  100. E_PARSE => 'Parse',
  101. E_NOTICE => 'Notice',
  102. E_CORE_ERROR => 'Core Error',
  103. E_CORE_WARNING => 'Core Warning',
  104. E_COMPILE_ERROR => 'Compile Error',
  105. E_COMPILE_WARNING => 'Compile Warning',
  106. E_USER_ERROR => 'User Error',
  107. E_USER_WARNING => 'User Warning',
  108. E_USER_NOTICE => 'User Notice',
  109. E_STRICT => 'Strict',
  110. E_RECOVERABLE_ERROR => 'Recoverable Error',
  111. E_DEPRECATED => 'Deprecated',
  112. E_USER_DEPRECATED => 'User Deprecated',
  113. ];
  114. $errName = isset($errorNames[$errNo]) ? $errorNames[$errNo] : "";
  115. throw new \PHPUnit\Framework\Exception(
  116. sprintf("%s: %s in %s:%s.", $errName, $errStr, $errFile, $errLine),
  117. $errNo
  118. );
  119. }
  120. }
  121. );
  122. }