Skip to content

Commit 66b6ecd

Browse files
authored
MQE-1040: MFTF standalone commands do not pass down constants correctly (magento#226)
* MQE-1040: MFTF standalone commands do not pass down constants correctly - Updated Magento_bp and Tests_bp to be set after env is loaded - Updated standalone bootstrap to use different relative module path if magento_bp is set * MQE-1040: MFTF standalone commands do not pass down constants correctly - Updated filename * MQE-1040: MFTF standalone commands do not pass down constants correctly - Changed define to add defined
1 parent d02fe0c commit 66b6ecd

File tree

3 files changed

+37
-26
lines changed

3 files changed

+37
-26
lines changed

bin/mftf

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ if (PHP_SAPI !== 'cli') {
1212
}
1313

1414
$autoloadPath = realpath(__DIR__ . '/../../../autoload.php');
15-
$testBootstrapPath = realpath(__DIR__ . '/../dev/tests/functional/_bootstrap.php');
15+
$testBootstrapPath = realpath(__DIR__ . '/../dev/tests/functional/standalone_bootstrap.php');
1616

1717
try {
1818
if (file_exists($autoloadPath)) {

dev/tests/functional/_bootstrap.php renamed to dev/tests/functional/standalone_bootstrap.php

+30-16
Original file line numberDiff line numberDiff line change
@@ -12,31 +12,31 @@
1212
}
1313

1414
defined('PROJECT_ROOT') || define('PROJECT_ROOT', dirname(dirname(dirname(__DIR__))));
15+
1516
require_once realpath(PROJECT_ROOT . '/vendor/autoload.php');
1617

1718
//Load constants from .env file
18-
defined('FW_BP') || define('FW_BP', PROJECT_ROOT);
19-
20-
// add the debug flag here
21-
$debug_mode = $_ENV['MFTF_DEBUG'] ?? false;
22-
if (!(bool)$debug_mode && extension_loaded('xdebug')) {
23-
xdebug_disable();
24-
}
25-
26-
$RELATIVE_TESTS_MODULE_PATH = '/tests/functional/tests/MFTF';
27-
28-
defined('MAGENTO_BP') || define('MAGENTO_BP', PROJECT_ROOT);
29-
defined('TESTS_BP') || define('TESTS_BP', dirname(dirname(__DIR__)));
30-
defined('TESTS_MODULE_PATH') || define('TESTS_MODULE_PATH', realpath(TESTS_BP . $RELATIVE_TESTS_MODULE_PATH));
31-
32-
if (file_exists(TESTS_BP . DIRECTORY_SEPARATOR . '.env')) {
33-
$env = new \Dotenv\Loader(TESTS_BP . DIRECTORY_SEPARATOR . '.env');
19+
$envFilePath = dirname(dirname(__DIR__));
20+
if (file_exists($envFilePath . DIRECTORY_SEPARATOR . '.env')) {
21+
$env = new \Dotenv\Loader($envFilePath . DIRECTORY_SEPARATOR . '.env');
3422
$env->load();
3523

3624
foreach ($_ENV as $key => $var) {
3725
defined($key) || define($key, $var);
3826
}
3927

28+
if (array_key_exists('MAGENTO_BP', $_ENV)) {
29+
// TODO REMOVE THIS CODE ONCE WE HAVE STOPPED SUPPORTING dev/tests/acceptance PATH
30+
// define TEST_PATH and TEST_MODULE_PATH
31+
defined('TESTS_BP') || define('TESTS_BP', realpath(MAGENTO_BP . DIRECTORY_SEPARATOR . 'dev/tests/acceptance/'));
32+
33+
$RELATIVE_TESTS_MODULE_PATH = '/tests/functional/Magento/FunctionalTest';
34+
defined('TESTS_MODULE_PATH') || define(
35+
'TESTS_MODULE_PATH',
36+
realpath(TESTS_BP . $RELATIVE_TESTS_MODULE_PATH)
37+
);
38+
}
39+
4040
defined('MAGENTO_CLI_COMMAND_PATH') || define(
4141
'MAGENTO_CLI_COMMAND_PATH',
4242
'dev/tests/acceptance/utils/command.php'
@@ -56,3 +56,17 @@
5656
}
5757

5858
}
59+
60+
defined('FW_BP') || define('FW_BP', PROJECT_ROOT);
61+
defined('MAGENTO_BP') || define('MAGENTO_BP', PROJECT_ROOT);
62+
defined('TESTS_BP') || define('TESTS_BP', dirname(dirname(__DIR__)));
63+
64+
$RELATIVE_TESTS_MODULE_PATH = '/tests/functional/tests/MFTF';
65+
defined('TESTS_MODULE_PATH') || define('TESTS_MODULE_PATH', realpath(TESTS_BP . $RELATIVE_TESTS_MODULE_PATH));
66+
67+
68+
// add the debug flag here
69+
$debug_mode = $_ENV['MFTF_DEBUG'] ?? false;
70+
if (!(bool)$debug_mode && extension_loaded('xdebug')) {
71+
xdebug_disable();
72+
}

src/Magento/FunctionalTestingFramework/_bootstrap.php

+6-9
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,17 @@
77

88
// define framework basepath for schema pathing
99
defined('FW_BP') || define('FW_BP', realpath(__DIR__ . '/../../../'));
10-
11-
// get the root path of the project (we will always be installed under vendor)
10+
// get the root path of the project
1211
$projectRootPath = substr(FW_BP, 0, strpos(FW_BP, DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR));
13-
1412
if (empty($projectRootPath)) {
1513
// If ProjectRootPath is empty, we are not under vendor and are executing standalone.
16-
require_once (realpath(FW_BP . "/dev/tests/functional/_bootstrap.php"));
14+
require_once (realpath(FW_BP . "/dev/tests/functional/standalone_bootstrap.php"));
1715
return;
1816
}
17+
defined('PROJECT_ROOT') || define('PROJECT_ROOT', $projectRootPath);
18+
$envFilepath = realpath($projectRootPath . '/dev/tests/acceptance/');
1919

20-
// set Magento_BP as Root_Project Path
21-
define('PROJECT_ROOT', $projectRootPath);
22-
defined('MAGENTO_BP') || define('MAGENTO_BP', realpath($projectRootPath));
2320

24-
// load .env (if it exists)
25-
$envFilepath = realpath(MAGENTO_BP . '/dev/tests/acceptance/');
2621
if (file_exists($envFilepath . DIRECTORY_SEPARATOR . '.env')) {
2722
$env = new \Dotenv\Loader($envFilepath . DIRECTORY_SEPARATOR . '.env');
2823
$env->load();
@@ -56,6 +51,8 @@
5651
}
5752
}
5853

54+
55+
defined('MAGENTO_BP') || define('MAGENTO_BP', realpath(PROJECT_ROOT));
5956
// TODO REMOVE THIS CODE ONCE WE HAVE STOPPED SUPPORTING dev/tests/acceptance PATH
6057
// define TEST_PATH and TEST_MODULE_PATH
6158
defined('TESTS_BP') || define('TESTS_BP', realpath(MAGENTO_BP . DIRECTORY_SEPARATOR . 'dev/tests/acceptance/'));

0 commit comments

Comments
 (0)