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 error_reporting(~E_USER_NOTICE);
8 define('PROJECT_ROOT', dirname(dirname(__DIR__)));
9 
10 $vendorAutoloadPath = realpath(PROJECT_ROOT . '/vendor/autoload.php');
11 $mftfTestCasePath = realpath(PROJECT_ROOT . '/dev/tests/util/MftfTestCase.php');
12 
13 require_once $vendorAutoloadPath;
14 require_once $mftfTestCasePath;
15 
16 // Set up AspectMock
17 $kernel = \AspectMock\Kernel::getInstance();
18 $kernel->init([
19  'debug' => true,
20  'includePaths' => [PROJECT_ROOT . DIRECTORY_SEPARATOR . 'src'],
21  'cacheDir' => PROJECT_ROOT .
22  DIRECTORY_SEPARATOR .
23  'dev' .
24  DIRECTORY_SEPARATOR .
25  'tests' .
26  DIRECTORY_SEPARATOR .
27  '.cache'
28 ]);
29 
30 // set mftf appplication context
32  true,
33  \Magento\FunctionalTestingFramework\Config\MftfApplicationConfig::UNIT_TEST_PHASE,
34  true,
35  false
36 );
37 
38 // Load needed framework env params
40  'MAGENTO_BASE_URL' => 'http://baseurl:8080',
41  'MAGENTO_BACKEND_NAME' => 'admin',
42  'MAGENTO_ADMIN_USERNAME' => 'admin',
43  'MAGENTO_ADMIN_PASSWORD' => 'admin123',
44  'DEFAULT_TIMEZONE' => 'America/Los_Angeles'
45 ];
46 
47 foreach ($TEST_ENVS as $key => $value) {
48  $_ENV[$key] = $value;
49  putenv("{$key}=${value}");
50 }
51 
52 // Add our test module to the whitelist
53 putenv('MODULE_WHITELIST=Magento_TestModule');
54 
55 // Define our own set of paths for the tests
56 defined('FW_BP') || define('FW_BP', PROJECT_ROOT);
57 
58 $RELATIVE_TESTS_MODULE_PATH = DIRECTORY_SEPARATOR . 'verification';
59 
60 defined('TESTS_BP') || define('TESTS_BP', __DIR__);
61 defined('TESTS_MODULE_PATH') || define('TESTS_MODULE_PATH', TESTS_BP . $RELATIVE_TESTS_MODULE_PATH);
62 defined('MAGENTO_BP') || define('MAGENTO_BP', __DIR__);
63 
64 $utilDir = DIRECTORY_SEPARATOR . 'Util'. DIRECTORY_SEPARATOR . '*.php';
65 
66 //Load required util files from functional dir
67 $functionalUtilFiles = glob(TESTS_BP . DIRECTORY_SEPARATOR . 'verification' . $utilDir);
68 foreach (sortInterfaces($functionalUtilFiles) as $functionalUtilFile) {
69  require($functionalUtilFile);
70 }
71 
72 //Load required util files from unit dir
73 $unitUtilFiles = glob(TESTS_BP . DIRECTORY_SEPARATOR . 'unit' . $utilDir);
74 foreach (sortInterfaces($unitUtilFiles) as $unitUtilFile) {
75  require($unitUtilFile);
76 }
77 
78 
79 // Mocks suite files location getter return to get files in verification/_suite Directory
80 // This mocks the paths of the suite files but still parses the xml files
81 $suiteDirectory = TESTS_BP . DIRECTORY_SEPARATOR . "verification" . DIRECTORY_SEPARATOR . "_suite";
82 
83 $paths = [
84  $suiteDirectory . DIRECTORY_SEPARATOR . 'functionalSuite.xml',
85  $suiteDirectory . DIRECTORY_SEPARATOR . 'functionalSuiteHooks.xml'
86 ];
87 
88 // create and return the iterator for these file paths
90 try {
91  AspectMock\Test::double(
92  Magento\FunctionalTestingFramework\Config\FileResolver\Root::class,
93  ['get' => $iterator]
94  )->make();
95 } catch (Exception $e) {
96  echo "Suite directory not mocked.";
97 }
98 
100 {
101  $bottom = [];
102  $top = [];
103  foreach ($files as $file) {
104  if (strstr(strtolower($file), 'interface')) {
105  $top[] = $file;
106  continue;
107  }
108 
109  $bottom[] = $file;
110  }
111 
112  return array_merge($top, $bottom);
113 }
$TEST_ENVS
Definition: _bootstrap.php:39
const PROJECT_ROOT
Definition: _bootstrap.php:8
$RELATIVE_TESTS_MODULE_PATH
Definition: _bootstrap.php:58
defined('TESTS_BP')||define('TESTS_BP' __DIR__
Definition: _bootstrap.php:60
$mftfTestCasePath
Definition: _bootstrap.php:11
foreach(sortInterfaces($unitUtilFiles) as $unitUtilFile) $suiteDirectory
Definition: _bootstrap.php:81
$value
Definition: gender.phtml:16
$kernel
Definition: _bootstrap.php:17
$iterator
Definition: _bootstrap.php:89
$utilDir
Definition: _bootstrap.php:64
$vendorAutoloadPath
Definition: _bootstrap.php:10
foreach(sortInterfaces($functionalUtilFiles) as $functionalUtilFile) $unitUtilFiles
Definition: _bootstrap.php:73
$functionalUtilFiles
Definition: _bootstrap.php:67
static create($forceGenerate, $phase, $verboseEnabled, $debugEnabled)
$paths
Definition: _bootstrap.php:83
catch(Exception $e) sortInterfaces($files)
Definition: _bootstrap.php:99
foreach($appDirs as $dir) $files