From 57f39f53a9f5f2c15da9c79b7bda57eedf3cfb46 Mon Sep 17 00:00:00 2001
From: Helmut Hummel <helmut.hummel@typo3.org>
Date: Fri, 21 Feb 2014 13:32:03 +0100
Subject: [PATCH] [TASK] Use environment variable for functional test bootstrap

Make it possible to determine the original root path
of the installation by setting an environment variable
just like in unit test bootstrap.

Releases: 6.2
Resolves: #56182
Change-Id: I42af5d4db20a23eb5d1ce90fc87b6df818a11e88
Reviewed-on: https://review.typo3.org/27771
Reviewed-by: Helmut Hummel
Tested-by: Helmut Hummel
---
 .../core/Build/FunctionalTestsBootstrap.php   | 22 +++++++++++++++++--
 .../sysext/core/Build/UnitTestsBootstrap.php  |  2 ++
 2 files changed, 22 insertions(+), 2 deletions(-)

diff --git a/typo3/sysext/core/Build/FunctionalTestsBootstrap.php b/typo3/sysext/core/Build/FunctionalTestsBootstrap.php
index c496e3038f05..b5d9e11119d4 100644
--- a/typo3/sysext/core/Build/FunctionalTestsBootstrap.php
+++ b/typo3/sysext/core/Build/FunctionalTestsBootstrap.php
@@ -43,8 +43,26 @@ require_once(__DIR__ . '/../Tests/Exception.php');
  * be way more complicated if done within the test class.
  *
  * It is required that phpunit binary is called from the document root of the instance,
- * otherwise path calculation of the created TYPO3 CMS instance will fail.
+ * or TYPO3_PATH_WEB environement variable needs to be set,
+ * otherwise path calculation, of the created TYPO3 CMS instance will fail.
  */
+if (getenv('TYPO3_PATH_WEB')) {
+	$webRoot = getenv('TYPO3_PATH_WEB') . '/';
+} elseif (isset($_SERVER['PWD'])) {
+	$webRoot = $_SERVER['PWD'] . '/';
+} else {
+	$webRoot = getcwd() . '/';
+}
+
+/**
+ * Fail if configuration is not found
+ */
+if (!file_exists($webRoot . 'typo3conf/LocalConfiguration.php')) {
+	throw new \Exception('TYPO3 web root not found. Call PHPUnit from that directory or set TYPO3_PATH_WEB to it.');
+}
+
 if (!defined('ORIGINAL_ROOT')) {
-	define('ORIGINAL_ROOT', $_SERVER['PWD'] . '/');
+	define('ORIGINAL_ROOT', $webRoot);
 }
+
+unset($webRoot);
\ No newline at end of file
diff --git a/typo3/sysext/core/Build/UnitTestsBootstrap.php b/typo3/sysext/core/Build/UnitTestsBootstrap.php
index 6d1d5746ff29..9ffd6fbf3862 100644
--- a/typo3/sysext/core/Build/UnitTestsBootstrap.php
+++ b/typo3/sysext/core/Build/UnitTestsBootstrap.php
@@ -82,6 +82,8 @@ define('PATH_site', $webRoot);
 define('TYPO3_MODE', 'BE');
 define('TYPO3_cliMode', TRUE);
 
+unset($webRoot);
+
 /**
  * We need to fake the current script to be the cli dispatcher to satisfy some GeneralUtility::getIndpEnv tests
  * TODO: properly mock these tests
-- 
GitLab