forked from magento/magento2-functional-testing-framework
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_bootstrap.php
141 lines (120 loc) · 4.02 KB
/
_bootstrap.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
error_reporting(~E_USER_NOTICE);
define('PROJECT_ROOT', dirname(dirname(__DIR__)));
$vendorAutoloadPath = realpath(PROJECT_ROOT . '/vendor/autoload.php');
$mftfTestCasePath = realpath(PROJECT_ROOT . '/dev/tests/util/MftfTestCase.php');
require_once $vendorAutoloadPath;
require_once $mftfTestCasePath;
// Set up AspectMock
$kernel = \AspectMock\Kernel::getInstance();
$kernel->init([
'debug' => true,
'includePaths' => [
PROJECT_ROOT . DIRECTORY_SEPARATOR . 'src',
PROJECT_ROOT . DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . 'allure-framework'
],
'cacheDir' => PROJECT_ROOT .
DIRECTORY_SEPARATOR .
'dev' .
DIRECTORY_SEPARATOR .
'tests' .
DIRECTORY_SEPARATOR .
'.cache'
]);
// set mftf appplication context
\Magento\FunctionalTestingFramework\Config\MftfApplicationConfig::create(
true,
\Magento\FunctionalTestingFramework\Config\MftfApplicationConfig::UNIT_TEST_PHASE,
true,
\Magento\FunctionalTestingFramework\Config\MftfApplicationConfig::LEVEL_NONE,
false
);
// Load needed framework env params
$TEST_ENVS = [
'MAGENTO_BASE_URL' => 'http://baseurl:8080',
'MAGENTO_BACKEND_NAME' => 'admin',
'MAGENTO_ADMIN_USERNAME' => 'admin',
'MAGENTO_ADMIN_PASSWORD' => 'admin123',
'DEFAULT_TIMEZONE' => 'America/Los_Angeles',
'WAIT_TIMEOUT' => '10'
];
foreach ($TEST_ENVS as $key => $value) {
$_ENV[$key] = $value;
putenv("{$key}=${value}");
}
// Add our test module to the whitelist
putenv('MODULE_WHITELIST=Magento_TestModule');
// Define our own set of paths for the tests
defined('FW_BP') || define('FW_BP', PROJECT_ROOT);
$RELATIVE_TESTS_MODULE_PATH = DIRECTORY_SEPARATOR . 'verification';
defined('TESTS_BP') || define('TESTS_BP', __DIR__);
defined('TESTS_MODULE_PATH') || define('TESTS_MODULE_PATH', TESTS_BP . $RELATIVE_TESTS_MODULE_PATH);
defined('MAGENTO_BP') || define('MAGENTO_BP', __DIR__);
define('DOCS_OUTPUT_DIR',
FW_BP .
DIRECTORY_SEPARATOR .
"dev" .
DIRECTORY_SEPARATOR .
"tests" .
DIRECTORY_SEPARATOR .
"unit" .
DIRECTORY_SEPARATOR .
"_output"
);
define('RESOURCE_DIR',
FW_BP .
DIRECTORY_SEPARATOR .
"dev" .
DIRECTORY_SEPARATOR .
"tests" .
DIRECTORY_SEPARATOR .
"unit" .
DIRECTORY_SEPARATOR .
"Resources"
);
$utilDir = DIRECTORY_SEPARATOR . 'Util'. DIRECTORY_SEPARATOR . '*.php';
//Load required util files from functional dir
$functionalUtilFiles = glob(TESTS_BP . DIRECTORY_SEPARATOR . 'verification' . $utilDir);
foreach (sortInterfaces($functionalUtilFiles) as $functionalUtilFile) {
require($functionalUtilFile);
}
//Load required util files from unit dir
$unitUtilFiles = glob(TESTS_BP . DIRECTORY_SEPARATOR . 'unit' . $utilDir);
foreach (sortInterfaces($unitUtilFiles) as $unitUtilFile) {
require($unitUtilFile);
}
// Mocks suite files location getter return to get files in verification/_suite Directory
// This mocks the paths of the suite files but still parses the xml files
$suiteDirectory = TESTS_BP . DIRECTORY_SEPARATOR . "verification" . DIRECTORY_SEPARATOR . "_suite";
$paths = [
$suiteDirectory . DIRECTORY_SEPARATOR . 'functionalSuite.xml',
$suiteDirectory . DIRECTORY_SEPARATOR . 'functionalSuiteHooks.xml',
$suiteDirectory . DIRECTORY_SEPARATOR . 'functionalSuiteExtends.xml'
];
// create and return the iterator for these file paths
$iterator = new Magento\FunctionalTestingFramework\Util\Iterator\File($paths);
try {
AspectMock\Test::double(
Magento\FunctionalTestingFramework\Config\FileResolver\Root::class,
['get' => $iterator]
)->make();
} catch (Exception $e) {
echo "Suite directory not mocked.";
}
function sortInterfaces($files)
{
$bottom = [];
$top = [];
foreach ($files as $file) {
if (strstr(strtolower($file), 'interface')) {
$top[] = $file;
continue;
}
$bottom[] = $file;
}
return array_merge($top, $bottom);
}