From 7287ebeddbd20dc710be164fc2d2d034779c8fac Mon Sep 17 00:00:00 2001
From: Alex Calandra <calandra.aj@gmail.com>
Date: Mon, 17 Sep 2018 13:01:47 -0500
Subject: [PATCH 1/3] 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
---
 dev/tests/functional/_bootstrap.php           | 46 ++++++++++++-------
 .../FunctionalTestingFramework/_bootstrap.php | 14 ++----
 2 files changed, 35 insertions(+), 25 deletions(-)

diff --git a/dev/tests/functional/_bootstrap.php b/dev/tests/functional/_bootstrap.php
index 219a2400f..b90160b97 100755
--- a/dev/tests/functional/_bootstrap.php
+++ b/dev/tests/functional/_bootstrap.php
@@ -12,31 +12,31 @@
 }
 
 defined('PROJECT_ROOT') || define('PROJECT_ROOT', dirname(dirname(dirname(__DIR__))));
+
 require_once realpath(PROJECT_ROOT . '/vendor/autoload.php');
 
 //Load constants from .env file
-defined('FW_BP') || define('FW_BP', PROJECT_ROOT);
-
-// add the debug flag here
-$debug_mode = $_ENV['MFTF_DEBUG'] ?? false;
-if (!(bool)$debug_mode && extension_loaded('xdebug')) {
-    xdebug_disable();
-}
-
-$RELATIVE_TESTS_MODULE_PATH = '/tests/functional/tests/MFTF';
-
-defined('MAGENTO_BP') || define('MAGENTO_BP', PROJECT_ROOT);
-defined('TESTS_BP') || define('TESTS_BP', dirname(dirname(__DIR__)));
-defined('TESTS_MODULE_PATH') || define('TESTS_MODULE_PATH', realpath(TESTS_BP . $RELATIVE_TESTS_MODULE_PATH));
-
-if (file_exists(TESTS_BP . DIRECTORY_SEPARATOR . '.env')) {
-    $env = new \Dotenv\Loader(TESTS_BP . DIRECTORY_SEPARATOR . '.env');
+$envFilePath = dirname(dirname(__DIR__));
+if (file_exists($envFilePath . DIRECTORY_SEPARATOR . '.env')) {
+    $env = new \Dotenv\Loader($envFilePath . DIRECTORY_SEPARATOR . '.env');
     $env->load();
 
     foreach ($_ENV as $key => $var) {
         defined($key) || define($key, $var);
     }
 
+    if (array_key_exists('MAGENTO_BP', $_ENV)) {
+        // TODO REMOVE THIS CODE ONCE WE HAVE STOPPED SUPPORTING dev/tests/acceptance PATH
+        // define TEST_PATH and TEST_MODULE_PATH
+        defined('TESTS_BP') || define('TESTS_BP', realpath(MAGENTO_BP . DIRECTORY_SEPARATOR . 'dev/tests/acceptance/'));
+
+        $RELATIVE_TESTS_MODULE_PATH = '/tests/functional/Magento/FunctionalTest';
+        defined('TESTS_MODULE_PATH') || define(
+            'TESTS_MODULE_PATH',
+            realpath(TESTS_BP . $RELATIVE_TESTS_MODULE_PATH)
+        );
+    }
+
     defined('MAGENTO_CLI_COMMAND_PATH') || define(
         'MAGENTO_CLI_COMMAND_PATH',
         'dev/tests/acceptance/utils/command.php'
@@ -46,3 +46,17 @@
     defined('MAGENTO_CLI_COMMAND_PARAMETER') || define('MAGENTO_CLI_COMMAND_PARAMETER', 'command');
     $env->setEnvironmentVariable('MAGENTO_CLI_COMMAND_PARAMETER', MAGENTO_CLI_COMMAND_PARAMETER);
 }
+
+defined('FW_BP') || define('FW_BP', PROJECT_ROOT);
+defined('MAGENTO_BP') || define('MAGENTO_BP', PROJECT_ROOT);
+defined('TESTS_BP') || define('TESTS_BP', dirname(dirname(__DIR__)));
+
+$RELATIVE_TESTS_MODULE_PATH = '/tests/functional/tests/MFTF';
+defined('TESTS_MODULE_PATH') || define('TESTS_MODULE_PATH', realpath(TESTS_BP . $RELATIVE_TESTS_MODULE_PATH));
+
+
+// add the debug flag here
+$debug_mode = $_ENV['MFTF_DEBUG'] ?? false;
+if (!(bool)$debug_mode && extension_loaded('xdebug')) {
+    xdebug_disable();
+}
diff --git a/src/Magento/FunctionalTestingFramework/_bootstrap.php b/src/Magento/FunctionalTestingFramework/_bootstrap.php
index 2e769fb8f..c23e901fa 100644
--- a/src/Magento/FunctionalTestingFramework/_bootstrap.php
+++ b/src/Magento/FunctionalTestingFramework/_bootstrap.php
@@ -6,23 +6,17 @@
  */
 
 // define framework basepath for schema pathing
-defined('FW_BP') || define('FW_BP', realpath(__DIR__ . '/../../../'));
-
-// get the root path of the project (we will always be installed under vendor)
+define('FW_BP', realpath(__DIR__ . '/../../../'));
+// get the root path of the project
 $projectRootPath = substr(FW_BP, 0, strpos(FW_BP, DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR));
-
 if (empty($projectRootPath)) {
     // If ProjectRootPath is empty, we are not under vendor and are executing standalone.
     require_once (realpath(FW_BP . "/dev/tests/functional/_bootstrap.php"));
     return;
 }
+$envFilepath = realpath($projectRootPath . '/dev/tests/acceptance/');
 
-// set Magento_BP as Root_Project Path
-define('PROJECT_ROOT', $projectRootPath);
-defined('MAGENTO_BP') || define('MAGENTO_BP', realpath($projectRootPath));
 
-// load .env (if it exists)
-$envFilepath = realpath(MAGENTO_BP . '/dev/tests/acceptance/');
 if (file_exists($envFilepath . DIRECTORY_SEPARATOR . '.env')) {
     $env = new \Dotenv\Loader($envFilepath . DIRECTORY_SEPARATOR . '.env');
     $env->load();
@@ -47,6 +41,8 @@
     $env->setEnvironmentVariable('MAGENTO_CLI_COMMAND_PARAMETER', MAGENTO_CLI_COMMAND_PARAMETER);
 }
 
+
+defined('MAGENTO_BP') || define('MAGENTO_BP', realpath(PROJECT_ROOT));
 // TODO REMOVE THIS CODE ONCE WE HAVE STOPPED SUPPORTING dev/tests/acceptance PATH
 // define TEST_PATH and TEST_MODULE_PATH
 defined('TESTS_BP') || define('TESTS_BP', realpath(MAGENTO_BP . DIRECTORY_SEPARATOR . 'dev/tests/acceptance/'));

From 1e3e5e5d308d1885226ee4389a10c3805adb220d Mon Sep 17 00:00:00 2001
From: Alex Calandra <calandra.aj@gmail.com>
Date: Mon, 17 Sep 2018 15:20:45 -0500
Subject: [PATCH 2/3] MQE-1040: MFTF standalone commands do not pass down
 constants correctly

- Updated filename
---
 bin/mftf                                                       | 2 +-
 .../functional/{_bootstrap.php => standalone_bootstrap.php}    | 0
 src/Magento/FunctionalTestingFramework/_bootstrap.php          | 3 ++-
 3 files changed, 3 insertions(+), 2 deletions(-)
 rename dev/tests/functional/{_bootstrap.php => standalone_bootstrap.php} (100%)

diff --git a/bin/mftf b/bin/mftf
index ef96ecca0..13d6ca7d1 100755
--- a/bin/mftf
+++ b/bin/mftf
@@ -12,7 +12,7 @@ if (PHP_SAPI !== 'cli') {
 }
 
 $autoloadPath = realpath(__DIR__ . '/../../../autoload.php');
-$testBootstrapPath = realpath(__DIR__ . '/../dev/tests/functional/_bootstrap.php');
+$testBootstrapPath = realpath(__DIR__ . '/../dev/tests/functional/standalone_bootstrap.php');
 
 try {
     if (file_exists($autoloadPath)) {
diff --git a/dev/tests/functional/_bootstrap.php b/dev/tests/functional/standalone_bootstrap.php
similarity index 100%
rename from dev/tests/functional/_bootstrap.php
rename to dev/tests/functional/standalone_bootstrap.php
diff --git a/src/Magento/FunctionalTestingFramework/_bootstrap.php b/src/Magento/FunctionalTestingFramework/_bootstrap.php
index c23e901fa..dd57bf988 100644
--- a/src/Magento/FunctionalTestingFramework/_bootstrap.php
+++ b/src/Magento/FunctionalTestingFramework/_bootstrap.php
@@ -11,9 +11,10 @@
 $projectRootPath = substr(FW_BP, 0, strpos(FW_BP, DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR));
 if (empty($projectRootPath)) {
     // If ProjectRootPath is empty, we are not under vendor and are executing standalone.
-    require_once (realpath(FW_BP . "/dev/tests/functional/_bootstrap.php"));
+    require_once (realpath(FW_BP . "/dev/tests/functional/standalone_bootstrap.php"));
     return;
 }
+defined('PROJECT_ROOT') || define('PROJECT_ROOT', $projectRootPath);
 $envFilepath = realpath($projectRootPath . '/dev/tests/acceptance/');
 
 

From a070fae8fd0d5d1d687a5f9f087fba8f7f17555a Mon Sep 17 00:00:00 2001
From: Alex Calandra <calandra.aj@gmail.com>
Date: Mon, 17 Sep 2018 15:23:14 -0500
Subject: [PATCH 3/3] MQE-1040: MFTF standalone commands do not pass down
 constants correctly

- Changed define to add defined
---
 src/Magento/FunctionalTestingFramework/_bootstrap.php | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/Magento/FunctionalTestingFramework/_bootstrap.php b/src/Magento/FunctionalTestingFramework/_bootstrap.php
index dd57bf988..585b047fa 100644
--- a/src/Magento/FunctionalTestingFramework/_bootstrap.php
+++ b/src/Magento/FunctionalTestingFramework/_bootstrap.php
@@ -6,7 +6,7 @@
  */
 
 // define framework basepath for schema pathing
-define('FW_BP', realpath(__DIR__ . '/../../../'));
+defined('FW_BP') || define('FW_BP', realpath(__DIR__ . '/../../../'));
 // get the root path of the project
 $projectRootPath = substr(FW_BP, 0, strpos(FW_BP, DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR));
 if (empty($projectRootPath)) {