Bootstrap.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. /**
  7. * Bootstrap for the integration testing environment
  8. */
  9. namespace Magento\TestFramework;
  10. class Bootstrap
  11. {
  12. /**#@+
  13. * Predefined admin user credentials
  14. */
  15. const ADMIN_NAME = 'user';
  16. const ADMIN_PASSWORD = 'password1';
  17. const ADMIN_EMAIL = 'admin@example.com';
  18. const ADMIN_FIRSTNAME = 'firstname';
  19. const ADMIN_LASTNAME = 'lastname';
  20. /**#@- */
  21. /**
  22. * Predefined admin user role name
  23. */
  24. const ADMIN_ROLE_NAME = 'Administrators';
  25. /**
  26. * @var \Magento\TestFramework\Bootstrap\Settings
  27. */
  28. private $_settings;
  29. /**
  30. * @var \Magento\TestFramework\Application
  31. */
  32. private $_application;
  33. /**
  34. * @var \Magento\TestFramework\Bootstrap\Environment
  35. */
  36. private $_envBootstrap;
  37. /**
  38. * @var \Magento\TestFramework\Bootstrap\DocBlock
  39. */
  40. private $_docBlockBootstrap;
  41. /**
  42. * @var \Magento\TestFramework\Bootstrap\Profiler
  43. */
  44. private $_profilerBootstrap;
  45. /**
  46. * @var \Magento\Framework\Shell
  47. */
  48. private $_shell;
  49. /**
  50. * @var \Magento\TestFramework\Bootstrap\MemoryFactory
  51. */
  52. private $memoryFactory;
  53. /**
  54. * Constructor
  55. *
  56. * @param \Magento\TestFramework\Bootstrap\Settings $settings
  57. * @param \Magento\TestFramework\Bootstrap\Environment $envBootstrap
  58. * @param \Magento\TestFramework\Bootstrap\DocBlock $docBlockBootstrap
  59. * @param \Magento\TestFramework\Bootstrap\Profiler $profilerBootstrap
  60. * @param \Magento\Framework\Shell $shell
  61. * @param Application $application
  62. * @param Bootstrap\MemoryFactory $memoryFactory
  63. * @internal param string $tmpDir
  64. */
  65. public function __construct(
  66. \Magento\TestFramework\Bootstrap\Settings $settings,
  67. \Magento\TestFramework\Bootstrap\Environment $envBootstrap,
  68. \Magento\TestFramework\Bootstrap\DocBlock $docBlockBootstrap,
  69. \Magento\TestFramework\Bootstrap\Profiler $profilerBootstrap,
  70. \Magento\Framework\Shell $shell,
  71. \Magento\TestFramework\Application $application,
  72. \Magento\TestFramework\Bootstrap\MemoryFactory $memoryFactory
  73. ) {
  74. $this->_settings = $settings;
  75. $this->_envBootstrap = $envBootstrap;
  76. $this->_docBlockBootstrap = $docBlockBootstrap;
  77. $this->_profilerBootstrap = $profilerBootstrap;
  78. $this->_shell = $shell;
  79. $this->_application = $application;
  80. $this->memoryFactory = $memoryFactory;
  81. }
  82. /**
  83. * Retrieve the application instance
  84. *
  85. * @return Application
  86. */
  87. public function getApplication()
  88. {
  89. return $this->_application;
  90. }
  91. /**
  92. * Perform bootstrap actions required to completely setup the testing environment
  93. */
  94. public function runBootstrap()
  95. {
  96. $this->_envBootstrap->emulateHttpRequest($_SERVER);
  97. $this->_envBootstrap->emulateSession($_SESSION);
  98. $profilerOutputFile = $this->_settings->getAsFile('TESTS_PROFILER_FILE');
  99. if ($profilerOutputFile) {
  100. $this->_profilerBootstrap->registerFileProfiler($profilerOutputFile);
  101. }
  102. $profilerBambooOutputFile = $this->_settings->getAsFile('TESTS_BAMBOO_PROFILER_FILE');
  103. $profilerBambooMetricsFile = $this->_settings->getAsFile('TESTS_BAMBOO_PROFILER_METRICS_FILE');
  104. if ($profilerBambooOutputFile && $profilerBambooMetricsFile) {
  105. $this->_profilerBootstrap->registerBambooProfiler($profilerBambooOutputFile, $profilerBambooMetricsFile);
  106. }
  107. $memoryBootstrap = $this->memoryFactory->create(
  108. $this->_settings->get('TESTS_MEM_USAGE_LIMIT', 0),
  109. $this->_settings->get('TESTS_MEM_LEAK_LIMIT', 0)
  110. );
  111. $memoryBootstrap->activateStatsDisplaying();
  112. $memoryBootstrap->activateLimitValidation();
  113. $this->_docBlockBootstrap->registerAnnotations($this->_application);
  114. }
  115. }