[TASK] Functional tests without phpunit process isolation 29/57129/19
authorChristian Kuhn <lolli@schwarzbu.ch>
Tue, 5 Jun 2018 23:12:07 +0000 (01:12 +0200)
committerWouter Wolters <typo3@wouterwolters.nl>
Wed, 25 Jul 2018 20:44:10 +0000 (22:44 +0200)
We're finally able to manage our core internal framework state,
at least in the backend. This is a huge step. To proof this,
functional tests now execute without process isolation.

We need a couple of additional reset state methods. Those are
for now marked @internal to allow us changing this stuff if
needed later.

The SystemEnvironmentBuilder also needs a change to not
directly rely on PATH_thisScript anymore.

composer require --dev typo3/testing-framework ~4.1.0

Change-Id: I37fbee7e4cf6ccb2eec18d057b6b9671d6a85167
Resolves: #85649
Releases: master
Reviewed-on: https://review.typo3.org/57129
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Andreas Fernandez <a.fernandez@scripting-base.de>
Tested-by: Andreas Fernandez <a.fernandez@scripting-base.de>
Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl>
Tested-by: Wouter Wolters <typo3@wouterwolters.nl>
composer.json
composer.lock
typo3/sysext/core/Classes/Core/SystemEnvironmentBuilder.php
typo3/sysext/core/Classes/Database/ConnectionPool.php
typo3/sysext/core/Classes/Utility/GeneralUtility.php
typo3/sysext/core/Tests/Functional/Cache/Backend/MemcachedBackendTest.php
typo3/sysext/core/Tests/Functional/Cache/Backend/RedisBackendTest.php
typo3/sysext/core/composer.json

index 30e4a89..a5f5e94 100644 (file)
@@ -66,7 +66,7 @@
                "fiunchinho/phpunit-randomizer": "^4.0",
                "friendsofphp/php-cs-fixer": "^2.12.2",
                "typo3/cms-styleguide": "^9.1",
-               "typo3/testing-framework": "^4.0.2"
+               "typo3/testing-framework": "~4.1.0"
        },
        "suggest": {
                "ext-gd": "GDlib/Freetype is required for building images with text (GIFBUILDER) and can also be used to scale images",
index 47ba308..5e22986 100644 (file)
@@ -4,7 +4,7 @@
         "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
         "This file is @generated automatically"
     ],
-    "content-hash": "a71e25c63829d22da3013a310006d675",
+    "content-hash": "cb674f386df7a9d87641f393120ecbac",
     "packages": [
         {
             "name": "cogpowered/finediff",
         },
         {
             "name": "typo3/testing-framework",
-            "version": "4.0.2",
+            "version": "4.1.0",
             "source": {
                 "type": "git",
                 "url": "https://github.com/TYPO3/testing-framework.git",
-                "reference": "dadfd1c953856429ad2a1b9ab8b8bea779e1f960"
+                "reference": "f3371a5cedc30ada5bc38a4d3b3d92baea1d2873"
             },
             "dist": {
                 "type": "zip",
-                "url": "https://api.github.com/repos/TYPO3/testing-framework/zipball/dadfd1c953856429ad2a1b9ab8b8bea779e1f960",
-                "reference": "dadfd1c953856429ad2a1b9ab8b8bea779e1f960",
+                "url": "https://api.github.com/repos/TYPO3/testing-framework/zipball/f3371a5cedc30ada5bc38a4d3b3d92baea1d2873",
+                "reference": "f3371a5cedc30ada5bc38a4d3b3d92baea1d2873",
                 "shasum": ""
             },
             "require": {
                 "tests",
                 "typo3"
             ],
-            "time": "2018-07-23T11:56:51+00:00"
+            "time": "2018-07-25T20:17:43+00:00"
         },
         {
             "name": "webmozart/assert",
index 2ed868d..96e3e6e 100644 (file)
@@ -267,18 +267,41 @@ class SystemEnvironmentBuilder
      */
     public static function initializeEnvironment(ApplicationContext $context)
     {
-        $sitePath = rtrim(PATH_site, '/');
+        $isCli = PHP_SAPI === 'cli';
+        // Absolute path of the entry script that was called
+        $scriptPath = PATH_thisScript;
+        $rootPath = rtrim(PATH_site, '/');
+        if (getenv('TYPO3_PATH_ROOT')) {
+            $rootPath = GeneralUtility::fixWindowsFilePath(getenv('TYPO3_PATH_ROOT'));
+            $rootPath = rtrim($rootPath, '/');
+            // Check if the root path has been set in the environment (e.g. by the composer installer)
+            if ($isCli && self::usesComposerClassLoading() && StringUtility::endsWith($scriptPath, 'typo3')) {
+                // PATH_thisScript is used for various path calculations based on the document root
+                // Therefore we assume it is always a subdirectory of the document root, which is not the case
+                // in composer mode on cli, as the binary is in the composer bin directory.
+                // Because of that, we enforce the document root path of this binary to be set
+                $scriptName = '/typo3/sysext/core/bin/typo3';
+            } else {
+                // Base the script path on the path taken from the environment
+                // to make relative path calculations work in case only one of both is symlinked
+                // or has the real path
+                $scriptName = substr($scriptPath, strlen($rootPath));
+            }
+            $scriptPath = $rootPath . $scriptName;
+        }
+
+        $sitePath = rtrim($rootPath, '/');
         $projectRootPath = GeneralUtility::fixWindowsFilePath(getenv('TYPO3_PATH_APP'));
         $isDifferentRootPath = ($projectRootPath && $projectRootPath !== $sitePath);
         Environment::initialize(
             $context,
-            PHP_SAPI === 'cli',
+            $isCli,
             self::usesComposerClassLoading(),
             $isDifferentRootPath ? $projectRootPath : $sitePath,
             $sitePath,
             $isDifferentRootPath ? $projectRootPath . '/var'    : $sitePath . '/typo3temp/var',
             $isDifferentRootPath ? $projectRootPath . '/config' : $sitePath . '/typo3conf',
-            PATH_thisScript,
+            $scriptPath,
             self::getTypo3Os() === 'WIN' ? 'WINDOWS' : 'UNIX'
         );
     }
index 47e5ced..5f77766 100644 (file)
@@ -235,4 +235,16 @@ class ConnectionPool
     {
         return $this->customDoctrineTypes;
     }
+
+    /**
+     * Reset internal list of connections. This is an internal method (for now)
+     * currently used in functional tests only to close connections and start
+     * new ones in between single tests.
+     *
+     * @internal May be changed or removed any point in time
+     */
+    public function resetConnections(): void
+    {
+        static::$connections = [];
+    }
 }
index f2c8c7e..58aae01 100644 (file)
@@ -4142,6 +4142,19 @@ class GeneralUtility
     }
 
     /**
+     * For testing purposes only!
+     * The functional test framework uses this to reset the internal $application context
+     * variable in between multiple tests before it is re-initialized using presetApplicationContext()
+     * which otherwise throws an exception if the internal variable is already set.
+     *
+     * @internal May be changed or removed any time
+     */
+    public static function resetApplicationContext(): void
+    {
+        static::$applicationContext = null;
+    }
+
+    /**
      * Get the ApplicationContext
      *
      * @return \TYPO3\CMS\Core\Core\ApplicationContext
index 5ee450e..c03545b 100644 (file)
@@ -29,7 +29,8 @@ class MemcachedBackendTest extends FunctionalTestCase
      */
     protected function setUp()
     {
-        parent::setUp();
+        // Note this functional does NOT call parent::setUp() since it does
+        // not need a full blown instance and database
         if (!extension_loaded('memcache') && !extension_loaded('memcached')) {
             $this->markTestSkipped('Neither "memcache" nor "memcached" extension was available');
         }
index 7e96009..45f41a2 100644 (file)
@@ -32,6 +32,8 @@ class RedisBackendTest extends FunctionalTestCase
      */
     protected function setUp()
     {
+        // Note this functional does NOT call parent::setUp() since it does
+        // not need a full blown instance and database
         if (!extension_loaded('redis')) {
             $this->markTestSkipped('redis extension was not available');
         }
index c81f317..0033f27 100644 (file)
@@ -47,7 +47,7 @@
                "fiunchinho/phpunit-randomizer": "^4.0",
                "friendsofphp/php-cs-fixer": "^2.12.2",
                "typo3/cms-styleguide": "^9.1",
-               "typo3/testing-framework": "^4.0.2"
+               "typo3/testing-framework": "~4.1.0"
        },
        "suggest": {
                "ext-fileinfo": "Used for proper file type detection in the file abstraction layer",