bootstrap.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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. require_once __DIR__ . '/../../../../app/bootstrap.php';
  8. require_once __DIR__ . '/autoload.php';
  9. $testsBaseDir = dirname(__DIR__);
  10. $fixtureBaseDir = $testsBaseDir. '/testsuite';
  11. if (!defined('TESTS_TEMP_DIR')) {
  12. define('TESTS_TEMP_DIR', $testsBaseDir . '/tmp');
  13. }
  14. if (!defined('INTEGRATION_TESTS_DIR')) {
  15. define('INTEGRATION_TESTS_DIR', $testsBaseDir);
  16. }
  17. $testFrameworkDir = __DIR__;
  18. require_once 'deployTestModules.php';
  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. $installConfigFile = $settings->getAsConfigFile('TESTS_INSTALL_CONFIG_FILE');
  38. if (!file_exists($installConfigFile)) {
  39. $installConfigFile .= '.dist';
  40. }
  41. $globalConfigFile = $settings->getAsConfigFile('TESTS_GLOBAL_CONFIG_FILE');
  42. if (!file_exists($globalConfigFile)) {
  43. $globalConfigFile .= '.dist';
  44. }
  45. $sandboxUniqueId = md5(sha1_file($installConfigFile));
  46. $installDir = TESTS_TEMP_DIR . "/sandbox-{$settings->get('TESTS_PARALLEL_THREAD', 0)}-{$sandboxUniqueId}";
  47. $application = new \Magento\TestFramework\Application(
  48. $shell,
  49. $installDir,
  50. $installConfigFile,
  51. $globalConfigFile,
  52. $settings->get('TESTS_GLOBAL_CONFIG_DIR'),
  53. $settings->get('TESTS_MAGENTO_MODE'),
  54. AutoloaderRegistry::getAutoloader(),
  55. true
  56. );
  57. $bootstrap = new \Magento\TestFramework\Bootstrap(
  58. $settings,
  59. new \Magento\TestFramework\Bootstrap\Environment(),
  60. new \Magento\TestFramework\Bootstrap\DocBlock("{$testsBaseDir}/testsuite"),
  61. new \Magento\TestFramework\Bootstrap\Profiler(new \Magento\Framework\Profiler\Driver\Standard()),
  62. $shell,
  63. $application,
  64. new \Magento\TestFramework\Bootstrap\MemoryFactory($shell)
  65. );
  66. $bootstrap->runBootstrap();
  67. if ($settings->getAsBoolean('TESTS_CLEANUP')) {
  68. $application->cleanup();
  69. }
  70. if (!$application->isInstalled()) {
  71. $application->install($settings->getAsBoolean('TESTS_CLEANUP'));
  72. }
  73. $application->initialize([]);
  74. \Magento\TestFramework\Helper\Bootstrap::setInstance(new \Magento\TestFramework\Helper\Bootstrap($bootstrap));
  75. $dirSearch = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()
  76. ->create(\Magento\Framework\Component\DirSearch::class);
  77. $themePackageList = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()
  78. ->create(\Magento\Framework\View\Design\Theme\ThemePackageList::class);
  79. \Magento\Framework\App\Utility\Files::setInstance(
  80. new Magento\Framework\App\Utility\Files(
  81. new \Magento\Framework\Component\ComponentRegistrar(),
  82. $dirSearch,
  83. $themePackageList
  84. )
  85. );
  86. /* Unset declared global variables to release the PHPUnit from maintaining their values between tests */
  87. unset($testsBaseDir, $logWriter, $settings, $shell, $application, $bootstrap);
  88. } catch (\Exception $e) {
  89. echo $e . PHP_EOL;
  90. exit(1);
  91. }
  92. /**
  93. * Set custom error handler
  94. */
  95. function setCustomErrorHandler()
  96. {
  97. set_error_handler(
  98. function ($errNo, $errStr, $errFile, $errLine) {
  99. if (error_reporting()) {
  100. $errorNames = [
  101. E_ERROR => 'Error',
  102. E_WARNING => 'Warning',
  103. E_PARSE => 'Parse',
  104. E_NOTICE => 'Notice',
  105. E_CORE_ERROR => 'Core Error',
  106. E_CORE_WARNING => 'Core Warning',
  107. E_COMPILE_ERROR => 'Compile Error',
  108. E_COMPILE_WARNING => 'Compile Warning',
  109. E_USER_ERROR => 'User Error',
  110. E_USER_WARNING => 'User Warning',
  111. E_USER_NOTICE => 'User Notice',
  112. E_STRICT => 'Strict',
  113. E_RECOVERABLE_ERROR => 'Recoverable Error',
  114. E_DEPRECATED => 'Deprecated',
  115. E_USER_DEPRECATED => 'User Deprecated',
  116. ];
  117. $errName = isset($errorNames[$errNo]) ? $errorNames[$errNo] : "";
  118. throw new \PHPUnit\Framework\Exception(
  119. sprintf("%s: %s in %s:%s.", $errName, $errStr, $errFile, $errLine),
  120. $errNo
  121. );
  122. }
  123. }
  124. );
  125. }