[TASK] Use CLI and Composer Checks via Environment class 96/55996/20
authorBenni Mack <benni@typo3.org>
Sat, 3 Mar 2018 22:23:31 +0000 (23:23 +0100)
committerAndreas Fernandez <a.fernandez@scripting-base.de>
Wed, 1 Aug 2018 19:10:03 +0000 (21:10 +0200)
This patch removes the last occurrences of TYPO3_REQUESTTYPE_CLI
by using Environment::isCli().

A new "TYPO3/Testing" TYPO3_CONTEXT check ensures that the Frontend
Request is now always simulated in a non-CLI environment.

Used composer command:

  composer req typo3/testing-framework:~4.2.0 --dev

Resolves: #85712
Releases: master
Change-Id: I7472e86f2816fdabd025ad87014e64b25c3d1642
Reviewed-on: https://review.typo3.org/55996
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: TYPO3com <no-reply@typo3.com>
Tested-by: Andreas Fernandez <a.fernandez@scripting-base.de>
Reviewed-by: Benni Mack <benni@typo3.org>
Reviewed-by: Andreas Fernandez <a.fernandez@scripting-base.de>
composer.json
composer.lock
typo3/sysext/core/Classes/Core/SystemEnvironmentBuilder.php
typo3/sysext/core/composer.json
typo3/sysext/extbase/Classes/Core/Bootstrap.php
typo3/sysext/extbase/Classes/Mvc/Cli/RequestHandler.php
typo3/sysext/extbase/Classes/Mvc/Web/BackendRequestHandler.php
typo3/sysext/extbase/Classes/Service/EnvironmentService.php

index a5f5e94..0a1b9d3 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.1.0"
+               "typo3/testing-framework": "~4.2.0"
        },
        "suggest": {
                "ext-gd": "GDlib/Freetype is required for building images with text (GIFBUILDER) and can also be used to scale images",
index 44aeece..0a33180 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": "cb674f386df7a9d87641f393120ecbac",
+    "content-hash": "e70017c026794000fa6e1a9a3837f07d",
     "packages": [
         {
             "name": "cogpowered/finediff",
         },
         {
             "name": "typo3/testing-framework",
-            "version": "4.1.0",
+            "version": "4.2.0",
             "source": {
                 "type": "git",
                 "url": "https://github.com/TYPO3/testing-framework.git",
-                "reference": "f3371a5cedc30ada5bc38a4d3b3d92baea1d2873"
+                "reference": "5aaee9dd602961087af339fb4fd2597e162cb821"
             },
             "dist": {
                 "type": "zip",
-                "url": "https://api.github.com/repos/TYPO3/testing-framework/zipball/f3371a5cedc30ada5bc38a4d3b3d92baea1d2873",
-                "reference": "f3371a5cedc30ada5bc38a4d3b3d92baea1d2873",
+                "url": "https://api.github.com/repos/TYPO3/testing-framework/zipball/5aaee9dd602961087af339fb4fd2597e162cb821",
+                "reference": "5aaee9dd602961087af339fb4fd2597e162cb821",
                 "shasum": ""
             },
             "require": {
                 "tests",
                 "typo3"
             ],
-            "time": "2018-07-25T20:17:43+00:00"
+            "time": "2018-08-01T18:28:16+00:00"
         },
         {
             "name": "webmozart/assert",
index 96e3e6e..9ac8dc0 100644 (file)
@@ -267,7 +267,9 @@ class SystemEnvironmentBuilder
      */
     public static function initializeEnvironment(ApplicationContext $context)
     {
-        $isCli = PHP_SAPI === 'cli';
+        // TYPO3_CONTEXT is set in testing framework to check for frontend calls
+        // forked from a CLI process
+        $isCli = PHP_SAPI === 'cli' && (string)$context !== 'Testing/Frontend';
         // Absolute path of the entry script that was called
         $scriptPath = PATH_thisScript;
         $rootPath = rtrim(PATH_site, '/');
index 0033f27..437e7c4 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.1.0"
+               "typo3/testing-framework": "~4.2.0"
        },
        "suggest": {
                "ext-fileinfo": "Used for proper file type detection in the file abstraction layer",
index 0620f0b..d8d8f62 100644 (file)
@@ -17,6 +17,7 @@ namespace TYPO3\CMS\Extbase\Core;
 use Psr\Http\Message\ResponseInterface;
 use Psr\Http\Message\ServerRequestInterface;
 use TYPO3\CMS\Backend\Routing\Route;
+use TYPO3\CMS\Core\Core\Environment;
 use TYPO3\CMS\Extbase\Mvc\Web\Response;
 
 /**
@@ -63,7 +64,7 @@ class Bootstrap implements \TYPO3\CMS\Extbase\Core\BootstrapInterface
      */
     public function initialize($configuration)
     {
-        if (!$this->isInCliMode()) {
+        if (!Environment::isCli()) {
             if (!isset($configuration['vendorName']) || $configuration['vendorName'] === '') {
                 throw new \RuntimeException('Invalid configuration: "vendorName" is not set', 1526629315);
             }
@@ -171,7 +172,7 @@ class Bootstrap implements \TYPO3\CMS\Extbase\Core\BootstrapInterface
             $content = $response->shutdown();
             $this->resetSingletons();
             $this->objectManager->get(\TYPO3\CMS\Extbase\Service\CacheService::class)->clearCachesOfRegisteredPageIds();
-            if ($this->isInCliMode() && $response->getExitCode()) {
+            if (Environment::isCli() && $response->getExitCode()) {
                 throw new \TYPO3\CMS\Extbase\Mvc\Exception\CommandException('The request has been terminated as the response defined an exit code.', $response->getExitCode());
             }
         }
@@ -242,12 +243,4 @@ class Bootstrap implements \TYPO3\CMS\Extbase\Core\BootstrapInterface
     {
         $this->persistenceManager->persistAll();
     }
-
-    /**
-     * @return bool
-     */
-    protected function isInCliMode()
-    {
-        return TYPO3_REQUESTTYPE & TYPO3_REQUESTTYPE_CLI;
-    }
 }
index 46c534e..ac26861 100644 (file)
@@ -14,6 +14,8 @@ namespace TYPO3\CMS\Extbase\Mvc\Cli;
  * The TYPO3 project - inspiring people to share!
  */
 
+use TYPO3\CMS\Core\Core\Environment;
+
 /**
  * The generic command line interface request handler for the MVC framework.
  *
@@ -37,11 +39,6 @@ class RequestHandler implements \TYPO3\CMS\Extbase\Mvc\RequestHandlerInterface
     protected $requestBuilder;
 
     /**
-     * @var \TYPO3\CMS\Extbase\Service\EnvironmentService
-     */
-    protected $environmentService;
-
-    /**
      * @param \TYPO3\CMS\Extbase\Object\ObjectManagerInterface $objectManager
      */
     public function injectObjectManager(\TYPO3\CMS\Extbase\Object\ObjectManagerInterface $objectManager)
@@ -66,14 +63,6 @@ class RequestHandler implements \TYPO3\CMS\Extbase\Mvc\RequestHandlerInterface
     }
 
     /**
-     * @param \TYPO3\CMS\Extbase\Service\EnvironmentService $environmentService
-     */
-    public function injectEnvironmentService(\TYPO3\CMS\Extbase\Service\EnvironmentService $environmentService)
-    {
-        $this->environmentService = $environmentService;
-    }
-
-    /**
      * Handles the request
      *
      * @return \TYPO3\CMS\Extbase\Mvc\ResponseInterface
@@ -101,7 +90,7 @@ class RequestHandler implements \TYPO3\CMS\Extbase\Mvc\RequestHandlerInterface
      */
     public function canHandleRequest()
     {
-        return $this->environmentService->isEnvironmentInCliMode();
+        return Environment::isCli();
     }
 
     /**
index 86d8931..f816811 100644 (file)
@@ -14,6 +14,8 @@ namespace TYPO3\CMS\Extbase\Mvc\Web;
  * The TYPO3 project - inspiring people to share!
  */
 
+use TYPO3\CMS\Core\Core\Environment;
+
 /**
  * A request handler which can handle web requests invoked by the backend.
  */
@@ -40,6 +42,6 @@ class BackendRequestHandler extends AbstractRequestHandler
      */
     public function canHandleRequest()
     {
-        return $this->environmentService->isEnvironmentInBackendMode() && !$this->environmentService->isEnvironmentInCliMode();
+        return $this->environmentService->isEnvironmentInBackendMode() && !Environment::isCli();
     }
 }
index c402c6c..b587af6 100644 (file)
@@ -14,6 +14,8 @@ namespace TYPO3\CMS\Extbase\Service;
  * The TYPO3 project - inspiring people to share!
  */
 
+use TYPO3\CMS\Core\Core\Environment;
+
 /**
  * Service for determining environment params
  */
@@ -46,7 +48,7 @@ class EnvironmentService implements \TYPO3\CMS\Core\SingletonInterface
      */
     public function isEnvironmentInCliMode()
     {
-        return TYPO3_REQUESTTYPE & TYPO3_REQUESTTYPE_CLI;
+        return Environment::isCli();
     }
 
     /**