Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
bootstrap.php
Go to the documentation of this file.
1 <?php
7 
8 require_once __DIR__ . '/../../../../app/bootstrap.php';
9 require_once __DIR__ . '/autoload.php';
10 
13 
14 if (!defined('TESTS_TEMP_DIR')) {
15  define('TESTS_TEMP_DIR', $testsBaseDir . '/tmp');
16 }
17 
18 if (!defined('INTEGRATION_TESTS_DIR')) {
19  define('INTEGRATION_TESTS_DIR', $testsBaseDir);
20 }
21 
23 require_once 'deployTestModules.php';
24 
25 try {
27 
28  /* Bootstrap the application */
29  $settings = new \Magento\TestFramework\Bootstrap\Settings($testsBaseDir, get_defined_constants());
30 
31  if ($settings->get('TESTS_EXTRA_VERBOSE_LOG')) {
32  $filesystem = new \Magento\Framework\Filesystem\Driver\File();
33  $exceptionHandler = new \Magento\Framework\Logger\Handler\Exception($filesystem);
34  $loggerHandlers = [
35  'system' => new \Magento\Framework\Logger\Handler\System($filesystem, $exceptionHandler),
36  'debug' => new \Magento\Framework\Logger\Handler\Debug($filesystem)
37  ];
38  $shell = new \Magento\Framework\Shell(
39  new \Magento\Framework\Shell\CommandRenderer(),
40  new \Monolog\Logger('main', $loggerHandlers)
41  );
42  } else {
43  $shell = new \Magento\Framework\Shell(new \Magento\Framework\Shell\CommandRenderer());
44  }
45 
46  $installConfigFile = $settings->getAsConfigFile('TESTS_INSTALL_CONFIG_FILE');
47  if (!file_exists($installConfigFile)) {
48  $installConfigFile .= '.dist';
49  }
50  $globalConfigFile = $settings->getAsConfigFile('TESTS_GLOBAL_CONFIG_FILE');
51  if (!file_exists($globalConfigFile)) {
52  $globalConfigFile .= '.dist';
53  }
55  $installDir = TESTS_TEMP_DIR . "/sandbox-{$settings->get('TESTS_PARALLEL_THREAD', 0)}-{$sandboxUniqueId}";
56  $application = new \Magento\TestFramework\Application(
57  $shell,
61  $settings->get('TESTS_GLOBAL_CONFIG_DIR'),
62  $settings->get('TESTS_MAGENTO_MODE'),
63  AutoloaderRegistry::getAutoloader(),
64  true
65  );
66 
67  $bootstrap = new \Magento\TestFramework\Bootstrap(
68  $settings,
69  new \Magento\TestFramework\Bootstrap\Environment(),
70  new \Magento\TestFramework\Bootstrap\DocBlock("{$testsBaseDir}/testsuite"),
71  new \Magento\TestFramework\Bootstrap\Profiler(new \Magento\Framework\Profiler\Driver\Standard()),
72  $shell,
74  new \Magento\TestFramework\Bootstrap\MemoryFactory($shell)
75  );
76  $bootstrap->runBootstrap();
77  if ($settings->getAsBoolean('TESTS_CLEANUP')) {
78  $application->cleanup();
79  }
80  if (!$application->isInstalled()) {
81  $application->install($settings->getAsBoolean('TESTS_CLEANUP'));
82  }
83  $application->initialize([]);
84 
85  \Magento\TestFramework\Helper\Bootstrap::setInstance(new \Magento\TestFramework\Helper\Bootstrap($bootstrap));
86 
88  ->create(\Magento\Framework\Component\DirSearch::class);
90  ->create(\Magento\Framework\View\Design\Theme\ThemePackageList::class);
92  new Magento\Framework\App\Utility\Files(
93  new \Magento\Framework\Component\ComponentRegistrar(),
94  $dirSearch,
96  )
97  );
98 
99  /* Unset declared global variables to release the PHPUnit from maintaining their values between tests */
100  unset($testsBaseDir, $logWriter, $settings, $shell, $application, $bootstrap);
101 } catch (\Exception $e) {
102  echo $e . PHP_EOL;
103  exit(1);
104 }
105 
110 {
111  set_error_handler(
112  function ($errNo, $errStr, $errFile, $errLine) {
113  if (error_reporting()) {
114  $errorNames = [
115  E_ERROR => 'Error',
116  E_WARNING => 'Warning',
117  E_PARSE => 'Parse',
118  E_NOTICE => 'Notice',
119  E_CORE_ERROR => 'Core Error',
120  E_CORE_WARNING => 'Core Warning',
121  E_COMPILE_ERROR => 'Compile Error',
122  E_COMPILE_WARNING => 'Compile Warning',
123  E_USER_ERROR => 'User Error',
124  E_USER_WARNING => 'User Warning',
125  E_USER_NOTICE => 'User Notice',
126  E_STRICT => 'Strict',
127  E_RECOVERABLE_ERROR => 'Recoverable Error',
128  E_DEPRECATED => 'Deprecated',
129  E_USER_DEPRECATED => 'User Deprecated',
130  ];
131 
132  $errName = isset($errorNames[$errNo]) ? $errorNames[$errNo] : "";
133 
134  throw new \PHPUnit\Framework\Exception(
135  sprintf("%s: %s in %s:%s.", $errName, $errStr, $errFile, $errLine),
136  $errNo
137  );
138  }
139  }
140  );
141 }
$fixtureBaseDir
Definition: bootstrap.php:15
defined('TESTS_BP')||define('TESTS_BP' __DIR__
Definition: _bootstrap.php:60
if(!file_exists($installConfigFile)) if(!defined('TESTS_INSTALLATION_DB_CONFIG_FILE')) $shell
Definition: bootstrap.php:46
$testsBaseDir
Definition: bootstrap.php:13
$installDir
Definition: bootstrap.php:55
$themePackageList
Definition: bootstrap.php:88
if(defined('TESTS_MAGENTO_INSTALLATION') &&TESTS_MAGENTO_INSTALLATION==='enabled') $bootstrap
Definition: bootstrap.php:73
$application
Definition: bootstrap.php:58
if(!file_exists($installConfigFile)) $globalConfigFile
Definition: bootstrap.php:53
static setInstance(Files $instance=null)
Definition: Files.php:136
$dirSearch
Definition: bootstrap.php:86
if(!file_exists($globalConfigFile)) $sandboxUniqueId
Definition: bootstrap.php:54
exit
Definition: redirect.phtml:12
$settings
Definition: bootstrap.php:29
catch(\Exception $e) setCustomErrorHandler()
Definition: bootstrap.php:106
static setInstance(\Magento\TestFramework\Helper\Bootstrap $instance)
Definition: Bootstrap.php:35
$filesystem
$testFrameworkDir
Definition: bootstrap.php:46
$installConfigFile
Definition: bootstrap.php:49