From d7b922f4a2e5ab64459830cd021fc085c8c2de46 Mon Sep 17 00:00:00 2001
From: Helmut Hummel <helmut.hummel@typo3.org>
Date: Thu, 6 Mar 2014 11:53:07 +0100
Subject: [PATCH] [TASK] Deprecate usage of $GLOBALS['typo3CacheManager']

* Replace all instances of $GLOBALS['typo3CacheManager']
  in the core with a makeInstance call.
* Adapt the tests.
* Make use of dependency injection where possible.
* Add compatibility layer with deprecation message
  for $GLOBALS['typo3CacheManager'] and $GLOBALS['typo3CacheFactory']

Resolves: #56597
Releases: 6.2
Change-Id: Idb035723626b24cfd768204bf24987171f5b0feb
Reviewed-on: https://review.typo3.org/28101
Reviewed-by: Christian Kuhn
Tested-by: Christian Kuhn
Reviewed-by: Wouter Wolters
Tested-by: Wouter Wolters
---
 .../FrontendBackendUserAuthentication.php     |  2 +-
 .../backend/Classes/Sprite/SpriteManager.php  |  4 +-
 .../Classes/Utility/BackendUtility.php        |  8 +-
 typo3/sysext/core/Classes/Cache/Cache.php     | 38 +++++---
 .../GlobalObjectDeprecationDecorator.php      | 69 ++++++++++++++
 typo3/sysext/core/Classes/Core/Bootstrap.php  | 11 ++-
 .../core/Classes/DataHandling/DataHandler.php | 30 ++----
 .../Localization/LocalizationFactory.php      |  2 +-
 .../Classes/TypoScript/TemplateService.php    |  4 +-
 .../Utility/ExtensionManagementUtility.php    | 31 +++++--
 .../core/Classes/Utility/GeneralUtility.php   | 27 ++++++
 .../core/Classes/Utility/RootlineUtility.php  |  2 +-
 .../core/Tests/Integrity/IntegrityTest.php    | 14 +--
 .../core/Tests/Unit/Core/BootstrapTest.php    | 10 +-
 .../Parser/LocallangXmlParserTest.php         |  2 +-
 .../Localization/Parser/XliffParserTest.php   |  2 +-
 .../Unit/Resource/ResourceStorageTest.php     |  1 -
 .../ExtensionManagementUtilityTest.php        | 92 ++++++++++---------
 .../Tests/Unit/Utility/GeneralUtilityTest.php |  4 +-
 .../sysext/extbase/Classes/Core/Bootstrap.php |  2 +-
 .../Object/Container/ClassInfoCache.php       |  2 +-
 .../Classes/Object/Container/Container.php    |  2 +-
 .../Classes/Scheduler/TaskExecutor.php        |  2 +-
 .../Tests/Unit/Scheduler/TaskExecutorTest.php | 48 ++++++----
 .../Classes/Utility/ConfigurationUtility.php  |  2 +-
 .../Classes/Utility/InstallUtility.php        | 11 ++-
 .../Tests/Unit/Utility/InstallUtilityTest.php |  7 +-
 .../Classes/View/AbstractTemplateView.php     |  2 +-
 .../fluid/Classes/View/StandaloneView.php     |  2 +-
 .../ContentObject/ContentObjectRenderer.php   |  4 +-
 .../TypoScriptFrontendController.php          |  6 +-
 .../frontend/Classes/Page/PageRepository.php  | 14 +--
 .../Controller/IndexedPagesController.php     |  2 +-
 .../Classes/Controller/AbstractController.php |  2 +-
 .../Action/Step/DatabaseConnect.php           |  2 +-
 .../CachingFrameworkDatabaseSchemaService.php |  2 +-
 .../Classes/Service/ClearCacheService.php     |  2 +-
 .../install/Classes/View/StandaloneView.php   |  2 +-
 .../CachingFrameworkGarbageCollectionTask.php |  2 +-
 .../CachingFrameworkGarbageCollectionTest.php | 31 ++++++-
 .../Classes/Hook/DataHandlerHook.php          |  2 +-
 .../Classes/Service/GridDataService.php       |  2 +-
 42 files changed, 328 insertions(+), 178 deletions(-)
 create mode 100644 typo3/sysext/core/Classes/Compatibility/GlobalObjectDeprecationDecorator.php

diff --git a/typo3/sysext/backend/Classes/FrontendBackendUserAuthentication.php b/typo3/sysext/backend/Classes/FrontendBackendUserAuthentication.php
index 109960b6b66b..3127aa1a6e66 100644
--- a/typo3/sysext/backend/Classes/FrontendBackendUserAuthentication.php
+++ b/typo3/sysext/backend/Classes/FrontendBackendUserAuthentication.php
@@ -260,7 +260,7 @@ class FrontendBackendUserAuthentication extends \TYPO3\CMS\Core\Authentication\B
 	 * @return integer The number of pages for this page in the table "cache_pages
 	 */
 	public function extGetNumberOfCachedPages($pageId) {
-		$pageCache = $GLOBALS['typo3CacheManager']->getCache('cache_pages');
+		$pageCache = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Cache\\CacheManager')->getCache('cache_pages');
 		$pageCacheEntries = $pageCache->getByTag('pageId_' . (int)$pageId);
 		return count($pageCacheEntries);
 	}
diff --git a/typo3/sysext/backend/Classes/Sprite/SpriteManager.php b/typo3/sysext/backend/Classes/Sprite/SpriteManager.php
index 66cc35b41c68..536a9ea94159 100644
--- a/typo3/sysext/backend/Classes/Sprite/SpriteManager.php
+++ b/typo3/sysext/backend/Classes/Sprite/SpriteManager.php
@@ -62,7 +62,7 @@ class SpriteManager {
 		if (!static::isInitialized()) {
 			$cacheIdentifier = static::getCacheIdentifier();
 			/** @var $codeCache \TYPO3\CMS\Core\Cache\Frontend\PhpFrontend */
-			$codeCache = $GLOBALS['typo3CacheManager']->getCache('cache_core');
+			$codeCache = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Cache\\CacheManager')->getCache('cache_core');
 			if ($codeCache->has($cacheIdentifier)) {
 				$codeCache->requireOnce($cacheIdentifier);
 			} else {
@@ -117,7 +117,7 @@ class SpriteManager {
 		$cacheFileContent = '$GLOBALS[\'TBE_STYLES\'][\'spriteIconApi\'][\'iconsAvailable\'] = ';
 		$cacheFileContent .= var_export($iconNames, TRUE) . ';';
 		/** @var $codeCache \TYPO3\CMS\Core\Cache\Frontend\PhpFrontend */
-		$GLOBALS['typo3CacheManager']->getCache('cache_core')->set(static::getCacheIdentifier(), $cacheFileContent);
+		GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Cache\\CacheManager')->getCache('cache_core')->set(static::getCacheIdentifier(), $cacheFileContent);
 	}
 
 	/**
diff --git a/typo3/sysext/backend/Classes/Utility/BackendUtility.php b/typo3/sysext/backend/Classes/Utility/BackendUtility.php
index 7aa57772ff6b..9e00ffa72c3a 100644
--- a/typo3/sysext/backend/Classes/Utility/BackendUtility.php
+++ b/typo3/sysext/backend/Classes/Utility/BackendUtility.php
@@ -1092,7 +1092,7 @@ class BackendUtility {
 	 * @return 	void
 	 */
 	static public function storeHash($hash, $data, $ident) {
-		$GLOBALS['typo3CacheManager']->getCache('cache_hash')->set($hash, $data, array('ident_' . $ident), 0);
+		GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Cache\\CacheManager')->getCache('cache_hash')->set($hash, $data, array('ident_' . $ident), 0);
 	}
 
 	/**
@@ -1102,12 +1102,12 @@ class BackendUtility {
 	 * IDENTICAL to the function by same name found in \TYPO3\CMS\Frontend\Page\PageRepository
 	 *
 	 * @param string $hash The hash-string which was used to store the data value
-	 * @param integer $expTime Variabele is not used in the function
+	 * @param integer $expTime Variable is not used in the function
 	 * @return mixed The "data" from the cache
 	 */
 	static public function getHash($hash, $expTime = 0) {
 		$hashContent = NULL;
-		$cacheEntry = $GLOBALS['typo3CacheManager']->getCache('cache_hash')->get($hash);
+		$cacheEntry = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Cache\\CacheManager')->getCache('cache_hash')->get($hash);
 		if ($cacheEntry) {
 			$hashContent = $cacheEntry;
 		}
@@ -1892,7 +1892,7 @@ class BackendUtility {
 			return $GLOBALS['TCA'][$table]['columns'][$col]['label'];
 		}
 		if ($printAllWrap) {
-			\TYPO3\CMS\Core\Utility\GeneralUtility::deprecationLog('The third parameter of getItemLabel() is deprecated with TYPO3 CMS 6.2 and will be removed two versions later.');
+			GeneralUtility::deprecationLog('The third parameter of getItemLabel() is deprecated with TYPO3 CMS 6.2 and will be removed two versions later.');
 			$parts = explode('|', $printAllWrap);
 			return $parts[0] . $col . $parts[1];
 		}
diff --git a/typo3/sysext/core/Classes/Cache/Cache.php b/typo3/sysext/core/Classes/Cache/Cache.php
index 694f29597a17..eabf77c09bd9 100644
--- a/typo3/sysext/core/Classes/Cache/Cache.php
+++ b/typo3/sysext/core/Classes/Cache/Cache.php
@@ -23,6 +23,8 @@ namespace TYPO3\CMS\Core\Cache;
  *
  *  This copyright notice MUST APPEAR in all copies of the script!
  ***************************************************************/
+use TYPO3\CMS\Core\Utility\GeneralUtility;
+
 /**
  * A cache handling helper class
  *
@@ -35,23 +37,34 @@ class Cache {
 	 */
 	static protected $isCachingFrameworkInitialized = FALSE;
 
+	/**
+	 * @var CacheManager
+	 */
+	static protected $cacheManager;
+
+	/**
+	 * @var CacheFactory
+	 */
+	static protected $cacheFactory;
+
 	/**
 	 * Initializes the caching framework by loading the cache manager and factory
 	 * into the global context.
 	 *
-	 * @return void
+	 * @return CacheManager
 	 */
 	static public function initializeCachingFramework() {
 		if (!self::isCachingFrameworkInitialized()) {
 			// New operator used on purpose, makeInstance() is not ready to be used so early in bootstrap
-			$GLOBALS['typo3CacheManager'] = new \TYPO3\CMS\Core\Cache\CacheManager();
-			\TYPO3\CMS\Core\Utility\GeneralUtility::setSingletonInstance('TYPO3\\CMS\\Core\\Cache\\CacheManager', $GLOBALS['typo3CacheManager']);
-			$GLOBALS['typo3CacheManager']->setCacheConfigurations($GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']);
+			self::$cacheManager = new CacheManager();
+			GeneralUtility::setSingletonInstance('TYPO3\\CMS\\Core\\Cache\\CacheManager', self::$cacheManager);
+			self::$cacheManager->setCacheConfigurations($GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']);
 			// New operator used on purpose, makeInstance() is not ready to be used so early in bootstrap
-			$GLOBALS['typo3CacheFactory'] = new \TYPO3\CMS\Core\Cache\CacheFactory('production', $GLOBALS['typo3CacheManager']);
-			\TYPO3\CMS\Core\Utility\GeneralUtility::setSingletonInstance('TYPO3\\CMS\\Core\\Cache\\CacheFactory', $GLOBALS['typo3CacheFactory']);
+			self::$cacheFactory = new CacheFactory('production', self::$cacheManager);
+			GeneralUtility::setSingletonInstance('TYPO3\\CMS\\Core\\Cache\\CacheFactory', self::$cacheFactory);
 			self::$isCachingFrameworkInitialized = TRUE;
 		}
+		return self::$cacheManager;
 	}
 
 	/**
@@ -61,9 +74,6 @@ class Cache {
 	 * @return boolean True if caching framework is initialized
 	 */
 	static public function isCachingFrameworkInitialized() {
-		if (!self::$isCachingFrameworkInitialized && isset($GLOBALS['typo3CacheManager']) && $GLOBALS['typo3CacheManager'] instanceof \TYPO3\CMS\Core\Cache\CacheManager && isset($GLOBALS['typo3CacheFactory']) && $GLOBALS['typo3CacheFactory'] instanceof \TYPO3\CMS\Core\Cache\CacheFactory) {
-			self::$isCachingFrameworkInitialized = TRUE;
-		}
 		return self::$isCachingFrameworkInitialized;
 	}
 
@@ -75,8 +85,10 @@ class Cache {
 	 */
 	static public function flagCachingFrameworkForReinitialization() {
 		self::$isCachingFrameworkInitialized = FALSE;
-		unset($GLOBALS['typo3CacheManager']);
-		unset($GLOBALS['typo3CacheFactory']);
+		GeneralUtility::removeSingletonInstance('TYPO3\\CMS\\Core\\Cache\\CacheManager', self::$cacheManager);
+		GeneralUtility::removeSingletonInstance('TYPO3\\CMS\\Core\\Cache\\CacheFactory', self::$cacheFactory);
+		self::$cacheManager = NULL;
+		self::$cacheFactory = NULL;
 	}
 
 	/**
@@ -90,7 +102,7 @@ class Cache {
 	static public function getDatabaseTableDefinitions() {
 		$tableDefinitions = '';
 		foreach ($GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations'] as $cacheName => $_) {
-			$backend = $GLOBALS['typo3CacheManager']->getCache($cacheName)->getBackend();
+			$backend = self::$cacheManager->getCache($cacheName)->getBackend();
 			if (method_exists($backend, 'getTableDefinitions')) {
 				$tableDefinitions .= LF . $backend->getTableDefinitions();
 			}
@@ -107,7 +119,7 @@ class Cache {
 	 * @return array
 	 */
 	public function addCachingFrameworkRequiredDatabaseSchemaToTablesDefinition(array $sqlString, $extensionKey) {
-		$GLOBALS['typo3CacheManager']->setCacheConfigurations($GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']);
+		self::$cacheManager->setCacheConfigurations($GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']);
 		$sqlString[] = static::getDatabaseTableDefinitions();
 		return array('sqlString' => $sqlString, 'extensionKey' => $extensionKey);
 	}
diff --git a/typo3/sysext/core/Classes/Compatibility/GlobalObjectDeprecationDecorator.php b/typo3/sysext/core/Classes/Compatibility/GlobalObjectDeprecationDecorator.php
new file mode 100644
index 000000000000..8693d9376083
--- /dev/null
+++ b/typo3/sysext/core/Classes/Compatibility/GlobalObjectDeprecationDecorator.php
@@ -0,0 +1,69 @@
+<?php
+namespace TYPO3\CMS\Core\Compatibility;
+
+/***************************************************************
+ * Copyright notice
+ *
+ * (c) 2014 Helmut Hummel <helmut.hummel@typo3.org>
+ * All rights reserved
+ *
+ * This script is part of the TYPO3 project. The TYPO3 project is
+ * free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * The GNU General Public License can be found at
+ * http://www.gnu.org/copyleft/gpl.html.
+ *
+ * This script is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * This copyright notice MUST APPEAR in all copies of the script!
+ ***************************************************************/
+
+use TYPO3\CMS\Core\Utility\GeneralUtility;
+
+/**
+ * Class CacheManagerGlobal will be instanciated and
+ * passed to $GLOBALS['typo3CacheManager'] to not break
+ * extension code
+ *
+ */
+class GlobalObjectDeprecationDecorator {
+
+	/**
+	 * @var string
+	 */
+	protected $className;
+
+	/**
+	 * @var string
+	 */
+	protected $deprecationMessage;
+
+	/**
+	 * @param string $className
+	 * @param string $deprecationMessage
+	 */
+	public function __construct($className, $deprecationMessage = NULL) {
+		$this->className = $className;
+		$this->deprecationMessage = $deprecationMessage ?: 'Usage of $GLOBALS[\'typo3CacheManager\'] and $GLOBALS[\'typo3CacheFactory\'] are deprecated since 6.2 will be removed in two versions. Use \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\'' . $this->className . '\') or dependency injection to access the singletons.';
+	}
+
+	/**
+	 * Calls decorated object and issues a deprecation message
+	 *
+	 * @param string $methodName
+	 * @param array $arguments
+	 * @return mixed
+	 * @deprecated
+	 */
+	public function __call($methodName, $arguments) {
+		GeneralUtility::deprecationLog($this->deprecationMessage);
+		$decoratedObject = GeneralUtility::makeInstance($this->className);
+		return call_user_func_array(array($decoratedObject, $methodName), $arguments);
+	}
+}
\ No newline at end of file
diff --git a/typo3/sysext/core/Classes/Core/Bootstrap.php b/typo3/sysext/core/Classes/Core/Bootstrap.php
index c9942f76c479..85395c99bdf8 100644
--- a/typo3/sysext/core/Classes/Core/Bootstrap.php
+++ b/typo3/sysext/core/Classes/Core/Bootstrap.php
@@ -480,9 +480,10 @@ class Bootstrap {
 	 * @return Bootstrap
 	 */
 	protected function initializeCachingFramework() {
-		// @todo Please deuglify
-		\TYPO3\CMS\Core\Cache\Cache::initializeCachingFramework();
-		$this->setEarlyInstance('TYPO3\CMS\Core\Cache\CacheManager', $GLOBALS['typo3CacheManager']);
+		$this->setEarlyInstance('TYPO3\\CMS\\Core\\Cache\\CacheManager', \TYPO3\CMS\Core\Cache\Cache::initializeCachingFramework());
+		// @deprecated since 6.2 will be removed in two versions
+		$GLOBALS['typo3CacheManager'] = new \TYPO3\CMS\Core\Compatibility\GlobalObjectDeprecationDecorator('TYPO3\\CMS\\Core\\Cache\\CacheManager');
+		$GLOBALS['typo3CacheFactory'] = new \TYPO3\CMS\Core\Compatibility\GlobalObjectDeprecationDecorator('TYPO3\\CMS\\Core\\Cache\\CacheFactory');
 		return $this;
 	}
 
@@ -698,7 +699,7 @@ class Bootstrap {
 	 * @return Bootstrap
 	 */
 	protected function setFinalCachingFrameworkCacheConfiguration() {
-		$GLOBALS['typo3CacheManager']->setCacheConfigurations($GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']);
+		$this->getEarlyInstance('TYPO3\\CMS\\Core\\Cache\\CacheManager')->setCacheConfigurations($GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']);
 		return $this;
 	}
 
@@ -896,7 +897,7 @@ class Bootstrap {
 	public function loadCachedTca() {
 		$cacheIdentifier = 'tca_fe_' . sha1((TYPO3_version . PATH_site . 'tca_fe'));
 		/** @var $codeCache \TYPO3\CMS\Core\Cache\Frontend\PhpFrontend */
-		$codeCache = $GLOBALS['typo3CacheManager']->getCache('cache_core');
+		$codeCache = $this->getEarlyInstance('TYPO3\\CMS\\Core\\Cache\\CacheManager')->getCache('cache_core');
 		if ($codeCache->has($cacheIdentifier)) {
 			// substr is necessary, because the php frontend wraps php code around the cache value
 			$GLOBALS['TCA'] = unserialize(substr($codeCache->get($cacheIdentifier), 6, -2));
diff --git a/typo3/sysext/core/Classes/DataHandling/DataHandler.php b/typo3/sysext/core/Classes/DataHandling/DataHandler.php
index 2a065a539a7f..503dc0b28dd8 100644
--- a/typo3/sysext/core/Classes/DataHandling/DataHandler.php
+++ b/typo3/sysext/core/Classes/DataHandling/DataHandler.php
@@ -6537,18 +6537,6 @@ class DataHandler {
 		}
 	}
 
-	/**
-	 * Unlink (delete) core cache files
-	 *
-	 * @return void
-	 * @deprecated since 6.0, will be removed in two versions, use the cache manager directly instead
-	 * @todo Define visibility
-	 */
-	public function removeCacheFiles() {
-		GeneralUtility::logDeprecatedFunction();
-		$GLOBALS['typo3CacheManager']->flushCachesInGroup('system');
-	}
-
 	/**
 	 * Returns array, $CPtable, of pages under the $pid going down to $counter levels.
 	 * Selecting ONLY pages which the user has read-access to!
@@ -6957,13 +6945,13 @@ class DataHandler {
 							// point to real pages and caches at all. Flushing caches for
 							// those records does not make sense and decreases performance
 							if ($pageId >= 0) {
-								$GLOBALS['typo3CacheManager']->flushCachesByTag('pageId_' . $pageId);
+								GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Cache\\CacheManager')->flushCachesByTag('pageId_' . $pageId);
 							}
 						}
 					}
 					// Delete cache for current table and record
-					$GLOBALS['typo3CacheManager']->flushCachesByTag($table);
-					$GLOBALS['typo3CacheManager']->flushCachesByTag($table . '_' . $uid);
+					GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Cache\\CacheManager')->flushCachesByTag($table);
+					GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Cache\\CacheManager')->flushCachesByTag($table . '_' . $uid);
 				}
 			}
 			// Clear cache for pages entered in TSconfig:
@@ -7031,13 +7019,13 @@ class DataHandler {
 		switch (strtolower($cacheCmd)) {
 			case 'pages':
 				if ($this->admin || $this->BE_USER->getTSConfigVal('options.clearCache.pages')) {
-					$GLOBALS['typo3CacheManager']->flushCachesInGroup('pages');
+					GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Cache\\CacheManager')->flushCachesInGroup('pages');
 				}
 				break;
 			case 'all':
 				if ($this->admin || $this->BE_USER->getTSConfigVal('options.clearCache.all')) {
 					// Clear cache group "all" of caching framework caches
-					$GLOBALS['typo3CacheManager']->flushCachesInGroup('all');
+					GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Cache\\CacheManager')->flushCachesInGroup('all');
 					if (\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded('cms')) {
 						$GLOBALS['TYPO3_DB']->exec_TRUNCATEquery('cache_treelist');
 					}
@@ -7058,7 +7046,7 @@ class DataHandler {
 			case 'temp_cached':
 			case 'system':
 				if ($this->admin || $this->BE_USER->getTSConfigVal('options.clearCache.system')) {
-					$GLOBALS['typo3CacheManager']->flushCachesInGroup('system');
+					GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Cache\\CacheManager')->flushCachesInGroup('system');
 				}
 				break;
 		}
@@ -7092,7 +7080,7 @@ class DataHandler {
 		// process caching framwork operations
 		if (count($tagsToFlush) > 0) {
 			foreach ($tagsToFlush as $tag) {
-				$GLOBALS['typo3CacheManager']->flushCachesInGroupByTag('pages', $tag);
+				GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Cache\\CacheManager')->flushCachesInGroupByTag('pages', $tag);
 			}
 		}
 
@@ -7213,7 +7201,7 @@ class DataHandler {
 	 */
 	public function internal_clearPageCache() {
 		GeneralUtility::logDeprecatedFunction();
-		$GLOBALS['typo3CacheManager']->flushCachesInGroup('pages');
+		GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Cache\\CacheManager')->flushCachesInGroup('pages');
 	}
 
 	/**
@@ -7323,7 +7311,7 @@ class DataHandler {
 	 * @return \TYPO3\CMS\Core\Cache\Frontend\VariableFrontend
 	 */
 	protected function getMemoryCache() {
-		return $GLOBALS['typo3CacheManager']->getCache('cache_runtime');
+		return GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Cache\\CacheManager')->getCache('cache_runtime');
 	}
 
 	/**
diff --git a/typo3/sysext/core/Classes/Localization/LocalizationFactory.php b/typo3/sysext/core/Classes/Localization/LocalizationFactory.php
index ad5e7b17fb0c..ef9d135b89d3 100644
--- a/typo3/sysext/core/Classes/Localization/LocalizationFactory.php
+++ b/typo3/sysext/core/Classes/Localization/LocalizationFactory.php
@@ -71,7 +71,7 @@ class LocalizationFactory implements \TYPO3\CMS\Core\SingletonInterface {
 	 * @return void
 	 */
 	protected function initializeCache() {
-		$this->cacheInstance = $GLOBALS['typo3CacheManager']->getCache('l10n');
+		$this->cacheInstance = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Cache\\CacheManager')->getCache('l10n');
 	}
 
 	/**
diff --git a/typo3/sysext/core/Classes/TypoScript/TemplateService.php b/typo3/sysext/core/Classes/TypoScript/TemplateService.php
index f88446ee726f..6337fb24b7dd 100644
--- a/typo3/sysext/core/Classes/TypoScript/TemplateService.php
+++ b/typo3/sysext/core/Classes/TypoScript/TemplateService.php
@@ -393,7 +393,7 @@ class TemplateService {
 	 * @return array Returns the unmatched array $currentPageData if found cached in "cache_pagesection". Otherwise FALSE is returned which means that the array must be generated and stored in the cache
 	 */
 	public function getCurrentPageData() {
-		return $GLOBALS['typo3CacheManager']->getCache('cache_pagesection')->get((int)$GLOBALS['TSFE']->id . '_' . GeneralUtility::md5int($GLOBALS['TSFE']->MP));
+		return GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Cache\\CacheManager')->getCache('cache_pagesection')->get((int)$GLOBALS['TSFE']->id . '_' . GeneralUtility::md5int($GLOBALS['TSFE']->MP));
 	}
 
 	/**
@@ -520,7 +520,7 @@ class TemplateService {
 				// Only save the data if we're not simulating by hidden/starttime/endtime
 				$mpvarHash = GeneralUtility::md5int($GLOBALS['TSFE']->MP);
 				/** @var $pageSectionCache \TYPO3\CMS\Core\Cache\Frontend\FrontendInterface */
-				$pageSectionCache = $GLOBALS['typo3CacheManager']->getCache('cache_pagesection');
+				$pageSectionCache = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Cache\\CacheManager')->getCache('cache_pagesection');
 				$pageSectionCache->set((int)$GLOBALS['TSFE']->id . '_' . $mpvarHash, $cc, array(
 					'pageId_' . (int)$GLOBALS['TSFE']->id,
 					'mpvarHash_' . $mpvarHash
diff --git a/typo3/sysext/core/Classes/Utility/ExtensionManagementUtility.php b/typo3/sysext/core/Classes/Utility/ExtensionManagementUtility.php
index 2d0b70fd3510..91b4238b9fc3 100644
--- a/typo3/sysext/core/Classes/Utility/ExtensionManagementUtility.php
+++ b/typo3/sysext/core/Classes/Utility/ExtensionManagementUtility.php
@@ -67,6 +67,23 @@ class ExtensionManagementUtility {
 		static::$packageManager = $packageManager;
 	}
 
+	/**
+	 * @var \TYPO3\CMS\Core\Cache\CacheManager
+	 */
+	static protected $cacheManager;
+
+	/**
+	 * Getter for the cache manager
+	 *
+	 * @return \TYPO3\CMS\Core\Cache\CacheManager $cacheManager
+	 */
+	static protected function getCacheManager() {
+		if (static::$cacheManager === NULL) {
+			static::$cacheManager = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Cache\\CacheManager');
+		}
+		return static::$cacheManager;
+	}
+
 	/**************************************
 	 *
 	 * PATHS and other evaluation
@@ -1446,7 +1463,7 @@ tt_content.' . $key . $prefix . ' {
 		if ($allowCaching) {
 			$cacheIdentifier = self::getExtLocalconfCacheIdentifier();
 			/** @var $codeCache \TYPO3\CMS\Core\Cache\Frontend\PhpFrontend */
-			$codeCache = $GLOBALS['typo3CacheManager']->getCache('cache_core');
+			$codeCache = self::getCacheManager()->getCache('cache_core');
 			if ($codeCache->has($cacheIdentifier)) {
 				$codeCache->requireOnce($cacheIdentifier);
 			} else {
@@ -1516,7 +1533,7 @@ tt_content.' . $key . $prefix . ' {
 		$phpCodeToCache = implode(LF, $phpCodeToCache);
 		// Remove all start and ending php tags from content
 		$phpCodeToCache = preg_replace('/<\\?php|\\?>/is', '', $phpCodeToCache);
-		$GLOBALS['typo3CacheManager']->getCache('cache_core')->set(self::getExtLocalconfCacheIdentifier(), $phpCodeToCache);
+		self::getCacheManager()->getCache('cache_core')->set(self::getExtLocalconfCacheIdentifier(), $phpCodeToCache);
 	}
 
 	/**
@@ -1546,7 +1563,7 @@ tt_content.' . $key . $prefix . ' {
 		if ($allowCaching) {
 			$cacheIdentifier = static::getBaseTcaCacheIdentifier();
 			/** @var $codeCache \TYPO3\CMS\Core\Cache\Frontend\PhpFrontend */
-			$codeCache = $GLOBALS['typo3CacheManager']->getCache('cache_core');
+			$codeCache = self::getCacheManager()->getCache('cache_core');
 			if ($codeCache->has($cacheIdentifier)) {
 				// substr is necessary, because the php frontend wraps php code around the cache value
 				$GLOBALS['TCA'] = unserialize(substr($codeCache->get($cacheIdentifier), 6, -2));
@@ -1600,7 +1617,7 @@ tt_content.' . $key . $prefix . ' {
 	 */
 	static protected function createBaseTcaCacheFile() {
 		/** @var $codeCache \TYPO3\CMS\Core\Cache\Frontend\PhpFrontend */
-		$codeCache = $GLOBALS['typo3CacheManager']->getCache('cache_core');
+		$codeCache = self::getCacheManager()->getCache('cache_core');
 		$codeCache->set(static::getBaseTcaCacheIdentifier(), serialize($GLOBALS['TCA']));
 	}
 
@@ -1630,7 +1647,7 @@ tt_content.' . $key . $prefix . ' {
 			self::$extTablesWasReadFromCacheOnce = TRUE;
 			$cacheIdentifier = self::getExtTablesCacheIdentifier();
 			/** @var $codeCache \TYPO3\CMS\Core\Cache\Frontend\PhpFrontend */
-			$codeCache = $GLOBALS['typo3CacheManager']->getCache('cache_core');
+			$codeCache = self::getCacheManager()->getCache('cache_core');
 			if ($codeCache->has($cacheIdentifier)) {
 				$codeCache->requireOnce($cacheIdentifier);
 			} else {
@@ -1707,7 +1724,7 @@ tt_content.' . $key . $prefix . ' {
 		$phpCodeToCache = implode(LF, $phpCodeToCache);
 		// Remove all start and ending php tags from content
 		$phpCodeToCache = preg_replace('/<\\?php|\\?>/is', '', $phpCodeToCache);
-		$GLOBALS['typo3CacheManager']->getCache('cache_core')->set(self::getExtTablesCacheIdentifier(), $phpCodeToCache);
+		self::getCacheManager()->getCache('cache_core')->set(self::getExtTablesCacheIdentifier(), $phpCodeToCache);
 	}
 
 	/**
@@ -1788,7 +1805,7 @@ tt_content.' . $key . $prefix . ' {
 	 * @return void
 	 */
 	static public function removeCacheFiles() {
-		$GLOBALS['typo3CacheManager']->flushCachesInGroup('system');
+		self::getCacheManager()->flushCachesInGroup('system');
 	}
 
 	/**
diff --git a/typo3/sysext/core/Classes/Utility/GeneralUtility.php b/typo3/sysext/core/Classes/Utility/GeneralUtility.php
index fa25704a99d2..090461b632f5 100644
--- a/typo3/sysext/core/Classes/Utility/GeneralUtility.php
+++ b/typo3/sysext/core/Classes/Utility/GeneralUtility.php
@@ -4395,6 +4395,33 @@ Connection: close
 		self::$singletonInstances[$className] = $instance;
 	}
 
+	/**
+	 * Removes the instance of a singleton class to be returned by makeInstance.
+	 *
+	 * Warning:
+	 * This is NOT a public API method and must not be used in own extensions!
+	 * This methods exists mostly for unit tests to inject a mock of a singleton class.
+	 * If you use this, make sure to always combine this with getSingletonInstances()
+	 * and resetSingletonInstances() in setUp() and tearDown() of the test class.
+	 *
+	 * @see makeInstance
+	 * @throws \InvalidArgumentException
+	 * @param string $className
+	 * @param \TYPO3\CMS\Core\SingletonInterface $instance
+	 * @return void
+	 * @internal
+	 */
+	static public function removeSingletonInstance($className, \TYPO3\CMS\Core\SingletonInterface $instance) {
+		self::checkInstanceClassName($className, $instance);
+		if (!isset(self::$singletonInstances[$className])) {
+			throw new \InvalidArgumentException('No Instance registered for ' . $className . '.', 1394099179);
+		}
+		if ($instance !== self::$singletonInstances[$className]) {
+			throw new \InvalidArgumentException('The instance you are trying to remove has not been registered before.', 1394099256);
+		}
+		unset(self::$singletonInstances[$className]);
+	}
+
 	/**
 	 * Set a group of singleton instances. Similar to setSingletonInstance(),
 	 * but multiple instances can be set.
diff --git a/typo3/sysext/core/Classes/Utility/RootlineUtility.php b/typo3/sysext/core/Classes/Utility/RootlineUtility.php
index 3203ba760a8a..4e551c0e53c4 100644
--- a/typo3/sysext/core/Classes/Utility/RootlineUtility.php
+++ b/typo3/sysext/core/Classes/Utility/RootlineUtility.php
@@ -162,7 +162,7 @@ class RootlineUtility {
 			}
 		}
 		if (self::$cache === NULL) {
-			self::$cache = $GLOBALS['typo3CacheManager']->getCache('cache_rootline');
+			self::$cache = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Cache\\CacheManager')->getCache('cache_rootline');
 		}
 		self::$rootlineFields = array_merge(self::$rootlineFields, \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(',', $GLOBALS['TYPO3_CONF_VARS']['FE']['addRootLineFields'], TRUE));
 		self::$rootlineFields = array_unique(self::$rootlineFields);
diff --git a/typo3/sysext/core/Tests/Integrity/IntegrityTest.php b/typo3/sysext/core/Tests/Integrity/IntegrityTest.php
index 6fa1ce0d5b7e..23fb5a3ff799 100644
--- a/typo3/sysext/core/Tests/Integrity/IntegrityTest.php
+++ b/typo3/sysext/core/Tests/Integrity/IntegrityTest.php
@@ -34,17 +34,6 @@ namespace TYPO3\CMS\Core\Tests\Integrity;
  */
 class IntegrityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
 
-	/**
-	 * This test fails if some test before mocked or substituted
-	 * $GLOBALS['typo3CacheManager'] but did not reconstitute correctly.
-	 *
-	 * @test
-	 */
-	public function globalsTypo3CacheManagerIsInstanceOfCoreCacheManager() {
-		$this->assertTrue(is_object($GLOBALS['typo3CacheManager']));
-		$this->assertTrue($GLOBALS['typo3CacheManager'] instanceof \TYPO3\CMS\Core\Cache\CacheManager);
-	}
-
 	/**
 	 * This test fails if some test before called
 	 * \TYPO3\CMS\Core\Utility\GeneralUtility::purgeInstances() without a proper
@@ -58,6 +47,7 @@ class IntegrityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
 	 */
 	public function standardSingletonIsRegistered() {
 		$registeredSingletons = \TYPO3\CMS\Core\Utility\GeneralUtility::getSingletonInstances();
-		$this->assertArrayHasKey('TYPO3\CMS\Core\Cache\CacheManager', $registeredSingletons);
+		$this->assertArrayHasKey('TYPO3\\CMS\\Core\\Cache\\CacheManager', $registeredSingletons);
+		$this->assertTrue($registeredSingletons['TYPO3\\CMS\\Core\\Cache\\CacheManager'] instanceof \TYPO3\CMS\Core\Cache\CacheManager);
 	}
 }
diff --git a/typo3/sysext/core/Tests/Unit/Core/BootstrapTest.php b/typo3/sysext/core/Tests/Unit/Core/BootstrapTest.php
index d5c70e386bf2..9c1e46a30fe8 100644
--- a/typo3/sysext/core/Tests/Unit/Core/BootstrapTest.php
+++ b/typo3/sysext/core/Tests/Unit/Core/BootstrapTest.php
@@ -54,11 +54,11 @@ class BootstrapTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
 			'',
 			FALSE
 		);
-		$GLOBALS['typo3CacheManager'] = $this->getMock(
+		$mockCacheManager = $this->getMock(
 			'TYPO3\\CMS\\Core\\Cache\\CacheManager',
 			array('getCache')
 		);
-		$GLOBALS['typo3CacheManager']
+		$mockCacheManager
 			->expects($this->any())
 			->method('getCache')
 			->will($this->returnValue($mockCache));
@@ -69,6 +69,7 @@ class BootstrapTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
 		$mockCache
 			->expects($this->once())
 			->method('get');
+		$bootstrapInstance->setEarlyInstance('TYPO3\\CMS\\Core\\Cache\\CacheManager', $mockCacheManager);
 		$bootstrapInstance->loadCachedTca();
 	}
 
@@ -91,11 +92,11 @@ class BootstrapTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
 			'',
 			FALSE
 		);
-		$GLOBALS['typo3CacheManager'] = $this->getMock(
+		$mockCacheManager = $this->getMock(
 			'TYPO3\\CMS\\Core\\Cache\\CacheManager',
 			array('getCache')
 		);
-		$GLOBALS['typo3CacheManager']
+		$mockCacheManager
 			->expects($this->any())
 			->method('getCache')
 			->will($this->returnValue($mockCache));
@@ -106,6 +107,7 @@ class BootstrapTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
 		$mockCache
 			->expects($this->once())
 			->method('set');
+		$bootstrapInstance->setEarlyInstance('TYPO3\\CMS\\Core\\Cache\\CacheManager', $mockCacheManager);
 		$bootstrapInstance->loadCachedTca();
 	}
 }
diff --git a/typo3/sysext/core/Tests/Unit/Localization/Parser/LocallangXmlParserTest.php b/typo3/sysext/core/Tests/Unit/Localization/Parser/LocallangXmlParserTest.php
index caaeda19a523..b73be56ad863 100644
--- a/typo3/sysext/core/Tests/Unit/Localization/Parser/LocallangXmlParserTest.php
+++ b/typo3/sysext/core/Tests/Unit/Localization/Parser/LocallangXmlParserTest.php
@@ -63,7 +63,7 @@ class LocallangXmlParserTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
 		$GLOBALS['TYPO3_CONF_VARS']['SYS']['lang']['format']['priority'] = 'xml';
 		\TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Localization\\LanguageStore')->initialize();
 			// Clear localization cache
-		$GLOBALS['typo3CacheManager']->getCache('l10n')->flush();
+		\TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Cache\\CacheManager')->getCache('l10n')->flush();
 	}
 
 	/**
diff --git a/typo3/sysext/core/Tests/Unit/Localization/Parser/XliffParserTest.php b/typo3/sysext/core/Tests/Unit/Localization/Parser/XliffParserTest.php
index bd41ff9c52fc..7dacbfa8f17f 100644
--- a/typo3/sysext/core/Tests/Unit/Localization/Parser/XliffParserTest.php
+++ b/typo3/sysext/core/Tests/Unit/Localization/Parser/XliffParserTest.php
@@ -70,7 +70,7 @@ class XliffParserTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
 		$GLOBALS['TYPO3_CONF_VARS']['SYS']['lang']['format']['priority'] = 'xlf';
 		\TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Localization\\LanguageStore')->initialize();
 			// Clear localization cache
-		$GLOBALS['typo3CacheManager']->getCache('l10n')->flush();
+		\TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Cache\\CacheManager')->getCache('l10n')->flush();
 	}
 
 	/**
diff --git a/typo3/sysext/core/Tests/Unit/Resource/ResourceStorageTest.php b/typo3/sysext/core/Tests/Unit/Resource/ResourceStorageTest.php
index f5f09123ffb2..74e24e7b523b 100644
--- a/typo3/sysext/core/Tests/Unit/Resource/ResourceStorageTest.php
+++ b/typo3/sysext/core/Tests/Unit/Resource/ResourceStorageTest.php
@@ -46,7 +46,6 @@ class ResourceStorageTest extends \TYPO3\CMS\Core\Tests\Unit\Resource\BaseTestCa
 	public function setUp() {
 		parent::setUp();
 		$this->singletonInstances = \TYPO3\CMS\Core\Utility\GeneralUtility::getSingletonInstances();
-		\TYPO3\CMS\Core\Utility\GeneralUtility::purgeInstances();
 		\TYPO3\CMS\Core\Utility\GeneralUtility::setSingletonInstance(
 			'TYPO3\\CMS\\Core\\Resource\\FileRepository',
 			$this->getMock('TYPO3\\CMS\\Core\\Resource\\FileRepository')
diff --git a/typo3/sysext/core/Tests/Unit/Utility/ExtensionManagementUtilityTest.php b/typo3/sysext/core/Tests/Unit/Utility/ExtensionManagementUtilityTest.php
index df7cbe2c2582..260560edbaec 100644
--- a/typo3/sysext/core/Tests/Unit/Utility/ExtensionManagementUtilityTest.php
+++ b/typo3/sysext/core/Tests/Unit/Utility/ExtensionManagementUtilityTest.php
@@ -25,6 +25,7 @@ namespace TYPO3\CMS\Core\Tests\Unit\Utility;
  ***************************************************************/
 
 use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
+use TYPO3\CMS\Core\Utility\GeneralUtility;
 
 /**
  * Testcase for ExtensionManagementUtility
@@ -39,15 +40,6 @@ class ExtensionManagementUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
 	 */
 	protected $singletonInstances = array();
 
-	/**
-	 * phpunit still needs some globals that are
-	 * reconstructed before $backupGlobals is handled. Those
-	 * important globals are handled in tearDown() directly.
-	 *
-	 * @var array
-	 */
-	protected $globals = array();
-
 	/**
 	 * Absolute path to files that must be removed
 	 * after a test - handled in tearDown
@@ -71,9 +63,6 @@ class ExtensionManagementUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
 
 	public function tearDown() {
 		ExtensionManagementUtility::clearExtensionKeyMap();
-		foreach ($this->globals as $key => $value) {
-			$GLOBALS[$key] = unserialize($value);
-		}
 		foreach ($this->testFilesToDelete as $absoluteFileName) {
 			\TYPO3\CMS\Core\Utility\GeneralUtility::unlink_tempfile($absoluteFileName);
 		}
@@ -81,6 +70,7 @@ class ExtensionManagementUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
 			\TYPO3\CMS\Core\Utility\GeneralUtility::rmdir(PATH_site . 'typo3temp/test_ext/', TRUE);
 		}
 		ExtensionManagementUtilityAccessibleProxy::setPackageManager($this->backUpPackageManager);
+		ExtensionManagementUtilityAccessibleProxy::setCacheManager(NULL);
 		$GLOBALS['TYPO3_LOADED_EXT'] = new \TYPO3\CMS\Core\Compatibility\LoadedExtensionsArray($this->backUpPackageManager);
 		\TYPO3\CMS\Core\Utility\GeneralUtility::resetSingletonInstances($this->singletonInstances);
 		parent::tearDown();
@@ -98,6 +88,9 @@ class ExtensionManagementUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
 			eval(
 				'namespace ' . __NAMESPACE__ . ';' .
 				'class ' . $className . ' extends \\TYPO3\\CMS\\Core\\Utility\\ExtensionManagementUtility {' .
+				'  static public function setCacheManager(\TYPO3\CMS\Core\Cache\CacheManager $cacheManager = NULL) {'.
+				'    static::$cacheManager = $cacheManager;'.
+				'  }'.
 				'  public static function getPackageManager() {' .
 				'    return static::$packageManager;' .
 				'  }' .
@@ -748,8 +741,9 @@ class ExtensionManagementUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
 	 * @test
 	 */
 	public function loadExtLocalconfDoesNotReadFromCacheIfCachingIsDenied() {
-		$GLOBALS['typo3CacheManager'] = $this->getMock('TYPO3\\CMS\\Core\\Cache\\CacheManager', array('getCache'));
-		$GLOBALS['typo3CacheManager']->expects($this->never())->method('getCache');
+		$mockCacheManager = $this->getMock('TYPO3\\CMS\\Core\\Cache\\CacheManager', array('getCache'));
+		$mockCacheManager->expects($this->never())->method('getCache');
+		ExtensionManagementUtilityAccessibleProxy::setCacheManager($mockCacheManager);
 		$GLOBALS['TYPO3_LOADED_EXT'] = new \TYPO3\CMS\Core\Compatibility\LoadedExtensionsArray($this->createMockPackageManagerWithMockPackage(uniqid()));
 		ExtensionManagementUtility::loadExtLocalconf(FALSE);
 	}
@@ -765,8 +759,9 @@ class ExtensionManagementUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
 			'',
 			FALSE
 		);
-		$GLOBALS['typo3CacheManager'] = $this->getMock('TYPO3\\CMS\\Core\\Cache\\CacheManager', array('getCache'));
-		$GLOBALS['typo3CacheManager']->expects($this->any())->method('getCache')->will($this->returnValue($mockCache));
+		$mockCacheManager = $this->getMock('TYPO3\\CMS\\Core\\Cache\\CacheManager', array('getCache'));
+		$mockCacheManager->expects($this->any())->method('getCache')->will($this->returnValue($mockCache));
+		ExtensionManagementUtilityAccessibleProxy::setCacheManager($mockCacheManager);
 		$mockCache->expects($this->any())->method('has')->will($this->returnValue(TRUE));
 		$mockCache->expects($this->once())->method('requireOnce');
 		ExtensionManagementUtility::loadExtLocalconf(TRUE);
@@ -880,8 +875,9 @@ class ExtensionManagementUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
 			'',
 			FALSE
 		);
-		$GLOBALS['typo3CacheManager'] = $this->getMock('TYPO3\\CMS\\Core\\Cache\\CacheManager', array('getCache'));
-		$GLOBALS['typo3CacheManager']->expects($this->any())->method('getCache')->will($this->returnValue($mockCache));
+		$mockCacheManager = $this->getMock('TYPO3\\CMS\\Core\\Cache\\CacheManager', array('getCache'));
+		$mockCacheManager->expects($this->any())->method('getCache')->will($this->returnValue($mockCache));
+		ExtensionManagementUtilityAccessibleProxy::setCacheManager($mockCacheManager);
 		$mockCache->expects($this->once())->method('set')->with($this->anything(), $this->stringContains($uniqueStringInLocalconf), $this->anything());
 		ExtensionManagementUtilityAccessibleProxy::createExtLocalconfCacheEntry();
 	}
@@ -900,8 +896,9 @@ class ExtensionManagementUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
 			'',
 			FALSE
 		);
-		$GLOBALS['typo3CacheManager'] = $this->getMock('TYPO3\\CMS\\Core\\Cache\\CacheManager', array('getCache'));
-		$GLOBALS['typo3CacheManager']->expects($this->any())->method('getCache')->will($this->returnValue($mockCache));
+		$mockCacheManager = $this->getMock('TYPO3\\CMS\\Core\\Cache\\CacheManager', array('getCache'));
+		$mockCacheManager->expects($this->any())->method('getCache')->will($this->returnValue($mockCache));
+		ExtensionManagementUtilityAccessibleProxy::setCacheManager($mockCacheManager);
 		$mockCache->expects($this->once())
 			->method('set')
 			->with($this->anything(), $this->logicalNot($this->stringContains($extensionName)), $this->anything());
@@ -919,8 +916,9 @@ class ExtensionManagementUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
 			'',
 			FALSE
 		);
-		$GLOBALS['typo3CacheManager'] = $this->getMock('TYPO3\\CMS\\Core\\Cache\\CacheManager', array('getCache'));
-		$GLOBALS['typo3CacheManager']->expects($this->any())->method('getCache')->will($this->returnValue($mockCache));
+		$mockCacheManager = $this->getMock('TYPO3\\CMS\\Core\\Cache\\CacheManager', array('getCache'));
+		$mockCacheManager->expects($this->any())->method('getCache')->will($this->returnValue($mockCache));
+		ExtensionManagementUtilityAccessibleProxy::setCacheManager($mockCacheManager);
 		$mockCache->expects($this->once())->method('set')->with($this->anything(), $this->anything(), $this->equalTo(array()));
 		$GLOBALS['TYPO3_LOADED_EXT'] = new \TYPO3\CMS\Core\Compatibility\LoadedExtensionsArray($this->createMockPackageManagerWithMockPackage(uniqid()));
 		ExtensionManagementUtilityAccessibleProxy::createExtLocalconfCacheEntry();
@@ -948,8 +946,9 @@ class ExtensionManagementUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
 	 * @test
 	 */
 	public function loadBaseTcaDoesNotReadFromCacheIfCachingIsDenied() {
-		$GLOBALS['typo3CacheManager'] = $this->getMock('TYPO3\\CMS\\Core\\Cache\\CacheManager', array('getCache'));
-		$GLOBALS['typo3CacheManager']->expects($this->never())->method('getCache');
+		$mockCacheManager = $this->getMock('TYPO3\\CMS\\Core\\Cache\\CacheManager', array('getCache'));
+		$mockCacheManager->expects($this->never())->method('getCache');
+		ExtensionManagementUtilityAccessibleProxy::setCacheManager($mockCacheManager);
 		ExtensionManagementUtility::loadBaseTca(FALSE);
 	}
 
@@ -964,8 +963,9 @@ class ExtensionManagementUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
 			'',
 			FALSE
 		);
-		$GLOBALS['typo3CacheManager'] = $this->getMock('TYPO3\\CMS\\Core\\Cache\\CacheManager', array('getCache'));
-		$GLOBALS['typo3CacheManager']->expects($this->any())->method('getCache')->will($this->returnValue($mockCache));
+		$mockCacheManager = $this->getMock('TYPO3\\CMS\\Core\\Cache\\CacheManager', array('getCache'));
+		$mockCacheManager->expects($this->any())->method('getCache')->will($this->returnValue($mockCache));
+		ExtensionManagementUtilityAccessibleProxy::setCacheManager($mockCacheManager);
 		$mockCache->expects($this->any())->method('has')->will($this->returnValue(TRUE));
 		$mockCache->expects($this->once())->method('get');
 		ExtensionManagementUtility::loadBaseTca(TRUE);
@@ -994,8 +994,9 @@ class ExtensionManagementUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
 			'',
 			FALSE
 		);
-		$GLOBALS['typo3CacheManager'] = $this->getMock('TYPO3\\CMS\\Core\\Cache\\CacheManager', array('getCache'));
-		$GLOBALS['typo3CacheManager']->expects($this->any())->method('getCache')->will($this->returnValue($mockCache));
+		$mockCacheManager = $this->getMock('TYPO3\\CMS\\Core\\Cache\\CacheManager', array('getCache'));
+		$mockCacheManager->expects($this->any())->method('getCache')->will($this->returnValue($mockCache));
+		ExtensionManagementUtilityAccessibleProxy::setCacheManager($mockCacheManager);
 		$mockCache->expects($this->once())->method('has')->will($this->returnValue(FALSE));
 		$mockCache->expects($this->once())->method('set')->with($this->anything(), $this->stringContains($uniqueStringInTableConfiguration), $this->anything());
 		ExtensionManagementUtility::loadBaseTca(TRUE);
@@ -1012,8 +1013,9 @@ class ExtensionManagementUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
 			'',
 			FALSE
 		);
-		$GLOBALS['typo3CacheManager'] = $this->getMock('TYPO3\\CMS\\Core\\Cache\\CacheManager', array('getCache'));
-		$GLOBALS['typo3CacheManager']->expects($this->any())->method('getCache')->will($this->returnValue($mockCache));
+		$mockCacheManager = $this->getMock('TYPO3\\CMS\\Core\\Cache\\CacheManager', array('getCache'));
+		$mockCacheManager->expects($this->any())->method('getCache')->will($this->returnValue($mockCache));
+		ExtensionManagementUtilityAccessibleProxy::setCacheManager($mockCacheManager);
 		$mockCache->expects($this->once())->method('has')->will($this->returnValue(FALSE));
 		$mockCache->expects($this->once())->method('set')->with($this->anything(), $this->anything(), $this->equalTo(array()));
 		ExtensionManagementUtility::loadBaseTca();
@@ -1041,8 +1043,9 @@ class ExtensionManagementUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
 	 * @test
 	 */
 	public function loadExtTablesDoesNotReadFromCacheIfCachingIsDenied() {
-		$GLOBALS['typo3CacheManager'] = $this->getMock('TYPO3\\CMS\\Core\\Cache\\CacheManager', array('getCache'));
-		$GLOBALS['typo3CacheManager']->expects($this->never())->method('getCache');
+		$mockCacheManager = $this->getMock('TYPO3\\CMS\\Core\\Cache\\CacheManager', array('getCache'));
+		$mockCacheManager->expects($this->never())->method('getCache');
+		ExtensionManagementUtilityAccessibleProxy::setCacheManager($mockCacheManager);
 		$GLOBALS['TYPO3_LOADED_EXT'] = new \TYPO3\CMS\Core\Compatibility\LoadedExtensionsArray($this->createMockPackageManagerWithMockPackage(uniqid()));
 		ExtensionManagementUtility::loadExtLocalconf(FALSE);
 	}
@@ -1058,8 +1061,9 @@ class ExtensionManagementUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
 			'',
 			FALSE
 		);
-		$GLOBALS['typo3CacheManager'] = $this->getMock('TYPO3\\CMS\\Core\\Cache\\CacheManager', array('getCache'));
-		$GLOBALS['typo3CacheManager']->expects($this->any())->method('getCache')->will($this->returnValue($mockCache));
+		$mockCacheManager = $this->getMock('TYPO3\\CMS\\Core\\Cache\\CacheManager', array('getCache'));
+		$mockCacheManager->expects($this->any())->method('getCache')->will($this->returnValue($mockCache));
+		ExtensionManagementUtilityAccessibleProxy::setCacheManager($mockCacheManager);
 		$mockCache->expects($this->any())->method('has')->will($this->returnValue(TRUE));
 		$mockCache->expects($this->once())->method('requireOnce');
 		// Reset the internal cache access tracking variable of extMgm
@@ -1092,8 +1096,9 @@ class ExtensionManagementUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
 			'',
 			FALSE
 		);
-		$GLOBALS['typo3CacheManager'] = $this->getMock('TYPO3\\CMS\\Core\\Cache\\CacheManager', array('getCache'));
-		$GLOBALS['typo3CacheManager']->expects($this->any())->method('getCache')->will($this->returnValue($mockCache));
+		$mockCacheManager = $this->getMock('TYPO3\\CMS\\Core\\Cache\\CacheManager', array('getCache'));
+		$mockCacheManager->expects($this->any())->method('getCache')->will($this->returnValue($mockCache));
+		ExtensionManagementUtilityAccessibleProxy::setCacheManager($mockCacheManager);
 		$mockCache->expects($this->once())->method('set')->with($this->anything(), $this->stringContains($uniqueStringInTables), $this->anything());
 		ExtensionManagementUtilityAccessibleProxy::createExtTablesCacheEntry();
 	}
@@ -1113,8 +1118,9 @@ class ExtensionManagementUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
 			'',
 			FALSE
 		);
-		$GLOBALS['typo3CacheManager'] = $this->getMock('TYPO3\\CMS\\Core\\Cache\\CacheManager', array('getCache'));
-		$GLOBALS['typo3CacheManager']->expects($this->any())->method('getCache')->will($this->returnValue($mockCache));
+		$mockCacheManager = $this->getMock('TYPO3\\CMS\\Core\\Cache\\CacheManager', array('getCache'));
+		$mockCacheManager->expects($this->any())->method('getCache')->will($this->returnValue($mockCache));
+		ExtensionManagementUtilityAccessibleProxy::setCacheManager($mockCacheManager);
 		$mockCache->expects($this->once())
 			->method('set')
 			->with($this->anything(), $this->logicalNot($this->stringContains($extensionName)), $this->anything());
@@ -1132,8 +1138,9 @@ class ExtensionManagementUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
 			'',
 			FALSE
 		);
-		$GLOBALS['typo3CacheManager'] = $this->getMock('TYPO3\\CMS\\Core\\Cache\\CacheManager', array('getCache'));
-		$GLOBALS['typo3CacheManager']->expects($this->any())->method('getCache')->will($this->returnValue($mockCache));
+		$mockCacheManager = $this->getMock('TYPO3\\CMS\\Core\\Cache\\CacheManager', array('getCache'));
+		$mockCacheManager->expects($this->any())->method('getCache')->will($this->returnValue($mockCache));
+		ExtensionManagementUtilityAccessibleProxy::setCacheManager($mockCacheManager);
 		$mockCache->expects($this->once())->method('set')->with($this->anything(), $this->anything(), $this->equalTo(array()));
 		$GLOBALS['TYPO3_LOADED_EXT'] = new \TYPO3\CMS\Core\Compatibility\LoadedExtensionsArray($this->createMockPackageManagerWithMockPackage(uniqid()));
 		ExtensionManagementUtilityAccessibleProxy::createExtTablesCacheEntry();
@@ -1160,8 +1167,9 @@ class ExtensionManagementUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
 	 * @test
 	 */
 	public function removeCacheFilesFlushesSystemCaches() {
-		$GLOBALS['typo3CacheManager'] = $this->getMock('TYPO3\\CMS\\Core\\Cache\\CacheManager', array('flushCachesInGroup'));
-		$GLOBALS['typo3CacheManager']->expects($this->once())->method('flushCachesInGroup')->with('system');
+		$mockCacheManager = $this->getMock('TYPO3\\CMS\\Core\\Cache\\CacheManager', array('flushCachesInGroup'));
+		$mockCacheManager->expects($this->once())->method('flushCachesInGroup')->with('system');
+		ExtensionManagementUtilityAccessibleProxy::setCacheManager($mockCacheManager);
 		ExtensionManagementUtility::removeCacheFiles();
 	}
 
diff --git a/typo3/sysext/core/Tests/Unit/Utility/GeneralUtilityTest.php b/typo3/sysext/core/Tests/Unit/Utility/GeneralUtilityTest.php
index 4a153730607a..49d783923033 100644
--- a/typo3/sysext/core/Tests/Unit/Utility/GeneralUtilityTest.php
+++ b/typo3/sysext/core/Tests/Unit/Utility/GeneralUtilityTest.php
@@ -2480,11 +2480,11 @@ class GeneralUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
 		$file = PATH_site . 'typo3temp/' . $unique . '.xml';
 		Utility\GeneralUtility::writeFileToTypo3tempDir($file, $xml);
 		// Make sure there is no cached version of the label
-		$GLOBALS['typo3CacheManager']->getCache('l10n')->flush();
+		Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Cache\\CacheManager')->getCache('l10n')->flush();
 		// Get default value
 		$defaultLL = Utility\GeneralUtility::readLLfile('EXT:lang/locallang_core.xlf', 'default');
 		// Clear language cache again
-		$GLOBALS['typo3CacheManager']->getCache('l10n')->flush();
+		Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Cache\\CacheManager')->getCache('l10n')->flush();
 		// Set override file
 		$GLOBALS['TYPO3_CONF_VARS']['SYS']['locallangXMLOverride']['EXT:lang/locallang_core.xlf'][$unique] = $file;
 		/** @var $store \TYPO3\CMS\Core\Localization\LanguageStore */
diff --git a/typo3/sysext/extbase/Classes/Core/Bootstrap.php b/typo3/sysext/extbase/Classes/Core/Bootstrap.php
index a4683dadae3f..48e2f460058b 100644
--- a/typo3/sysext/extbase/Classes/Core/Bootstrap.php
+++ b/typo3/sysext/extbase/Classes/Core/Bootstrap.php
@@ -156,7 +156,7 @@ class Bootstrap implements \TYPO3\CMS\Extbase\Core\BootstrapInterface {
 	 * @see initialize()
 	 */
 	protected function initializeCache() {
-		$this->cacheManager = $GLOBALS['typo3CacheManager'];
+		$this->cacheManager = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Cache\\CacheManager');
 	}
 
 	/**
diff --git a/typo3/sysext/extbase/Classes/Object/Container/ClassInfoCache.php b/typo3/sysext/extbase/Classes/Object/Container/ClassInfoCache.php
index cece0c2e4cc9..9e221328f686 100644
--- a/typo3/sysext/extbase/Classes/Object/Container/ClassInfoCache.php
+++ b/typo3/sysext/extbase/Classes/Object/Container/ClassInfoCache.php
@@ -89,6 +89,6 @@ class ClassInfoCache {
 	 * Initialize the TYPO3 second level cache
 	 */
 	private function initializeLevel2Cache() {
-		$this->level2Cache = $GLOBALS['typo3CacheManager']->getCache('extbase_object');
+		$this->level2Cache = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Cache\\CacheManager')->getCache('extbase_object');
 	}
 }
diff --git a/typo3/sysext/extbase/Classes/Object/Container/Container.php b/typo3/sysext/extbase/Classes/Object/Container/Container.php
index b3f852cc15d3..8f75a9093ef1 100644
--- a/typo3/sysext/extbase/Classes/Object/Container/Container.php
+++ b/typo3/sysext/extbase/Classes/Object/Container/Container.php
@@ -152,7 +152,7 @@ class Container implements \TYPO3\CMS\Core\SingletonInterface {
 			return $this;
 		}
 		if ($className === 'TYPO3\\CMS\\Core\\Cache\\CacheManager') {
-			return $GLOBALS['typo3CacheManager'];
+			return \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Cache\\CacheManager');
 		}
 		if ($className === 'TYPO3\\CMS\\Core\\Package\\PackageManager') {
 			return \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Package\\PackageManager');
diff --git a/typo3/sysext/extbase/Classes/Scheduler/TaskExecutor.php b/typo3/sysext/extbase/Classes/Scheduler/TaskExecutor.php
index e6651bda6740..f9776afb9e5c 100644
--- a/typo3/sysext/extbase/Classes/Scheduler/TaskExecutor.php
+++ b/typo3/sysext/extbase/Classes/Scheduler/TaskExecutor.php
@@ -101,7 +101,7 @@ class TaskExecutor implements \TYPO3\CMS\Core\SingletonInterface {
 		}
 		// initialize reflection
 		$reflectionService = $this->objectManager->get('TYPO3\\CMS\\Extbase\\Reflection\\ReflectionService');
-		$reflectionService->setDataCache($GLOBALS['typo3CacheManager']->getCache('extbase_reflection'));
+		$reflectionService->setDataCache(\TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Cache\\CacheManager')->getCache('extbase_reflection'));
 		if (!$reflectionService->isInitialized()) {
 			$reflectionService->initialize();
 		}
diff --git a/typo3/sysext/extbase/Tests/Unit/Scheduler/TaskExecutorTest.php b/typo3/sysext/extbase/Tests/Unit/Scheduler/TaskExecutorTest.php
index f0500f79f5ed..8d8b9df9092a 100644
--- a/typo3/sysext/extbase/Tests/Unit/Scheduler/TaskExecutorTest.php
+++ b/typo3/sysext/extbase/Tests/Unit/Scheduler/TaskExecutorTest.php
@@ -28,6 +28,10 @@ namespace TYPO3\CMS\Extbase\Tests\Unit\Scheduler;
  *  This copyright notice MUST APPEAR in all copies of the script!
  ***************************************************************/
 
+use TYPO3\CMS\Core\Utility\GeneralUtility;
+
+require_once __DIR__ . '/Fixtures/MockACommandController.php';
+
 /**
  * TaskExecutor Test Class
  */
@@ -38,11 +42,6 @@ class TaskExecutorTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
 	 */
 	protected $controller;
 
-	/**
-	 * @var \TYPO3\CMS\Core\Cache\CacheManager|\PHPUnit_Framework_MockObject_MockObject
-	 */
-	protected $cacheManager;
-
 	/**
 	 * @var \TYPO3\CMS\Extbase\Object\ObjectManager|\PHPUnit_Framework_MockObject_MockObject
 	 */
@@ -63,25 +62,31 @@ class TaskExecutorTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
 	 */
 	protected $taskExecuter;
 
+	/**
+	 * Backup of current singleton instances
+	 */
+	protected $singletonInstances;
+
 	public function setUp() {
 		if (!\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded('scheduler')) {
 			$this->markTestSkipped('Tests need EXT:scheduler loaded.');
 		}
-		$this->controller = $this->getAccessibleMock('TYPO3\CMS\Extbase\Tests\MockACommandController', array('dummy'));
-		$this->controller->_set('reflectionService', $this->objectManager->get('TYPO3\CMS\Extbase\Reflection\ReflectionService'));
-		$this->controller->_set('objectManager', $this->objectManager);
-
-		$command = new \TYPO3\CMS\Extbase\Mvc\Cli\Command('TYPO3\CMS\Extbase\Tests\MockACommandController', 'funcA');
+		$this->singletonInstances = \TYPO3\CMS\Core\Utility\GeneralUtility::getSingletonInstances();
 		$nullBackend = new \TYPO3\CMS\Core\Cache\Backend\NullBackend('production');
 		$variableFrontend = new \TYPO3\CMS\Core\Cache\Frontend\VariableFrontend('foo', $nullBackend);
+		$mockCacheManager = $this->getMock('TYPO3\\CMS\\Core\\Cache\\CacheManager', array('dummy', 'getCache'));
+		$mockCacheManager->expects($this->any())->method('getCache')->will($this->returnValue($variableFrontend));
+		GeneralUtility::setSingletonInstance('TYPO3\\CMS\\Core\\Cache\\CacheManager', $mockCacheManager);
 
-		$this->cacheManager = $this->getMock('TYPO3\CMS\Core\Cache\CacheManager', array('dummy', 'getCache'));
-		$this->cacheManager->expects($this->any())->method('getCache')->will($this->returnValue($variableFrontend));
-		$GLOBALS['typo3CacheManager'] = $this->cacheManager;
+		$this->controller = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Tests\\MockACommandController', array('dummy'));
+		$this->controller->_set('reflectionService', $this->objectManager->get('TYPO3\\CMS\\Extbase\\Reflection\\ReflectionService'));
+		$this->controller->_set('objectManager', $this->objectManager);
 
-		$this->objectManager = $this->getMock('TYPO3\CMS\Extbase\Object\ObjectManager', array('dummy'));
-		$this->commandManager = $this->getMock('TYPO3\CMS\Extbase\Mvc\Cli\CommandManager', array('dummy', 'getCommandByIdentifier'));
-		$this->configurationManager = $this->getAccessibleMock('TYPO3\CMS\Extbase\Configuration\ConfigurationManager', array('dummy', 'getConfiguration', 'setContentObject', 'setConfiguration'));
+		$command = new \TYPO3\CMS\Extbase\Mvc\Cli\Command('TYPO3\\CMS\\Extbase\\Tests\\MockACommandController', 'funcA');
+
+		$this->objectManager = $this->getMock('TYPO3\\CMS\\Extbase\\Object\\ObjectManager', array('dummy'));
+		$this->commandManager = $this->getMock('TYPO3\\CMS\\Extbase\\Mvc\\Cli\\CommandManager', array('dummy', 'getCommandByIdentifier'));
+		$this->configurationManager = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Configuration\\ConfigurationManager', array('dummy', 'getConfiguration', 'setContentObject', 'setConfiguration'));
 
 		$this->configurationManager
 			->expects($this->once())
@@ -95,16 +100,21 @@ class TaskExecutorTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
 			->will($this->returnValue($command));
 	}
 
+	public function tearDown() {
+		\TYPO3\CMS\Core\Utility\GeneralUtility::resetSingletonInstances($this->singletonInstances);
+		parent::tearDown();
+	}
+
 	/**
 	 * @test
 	 * @author Alexander Schnitzler <alex.schnitzler@typovision.de>
 	 */
 	public function executeDispatchesTheRightCommandControllerAndCommandAction() {
-		$dispatcher = $this->getAccessibleMock('TYPO3\CMS\Extbase\Mvc\Dispatcher', array('resolveController'), array($this->objectManager));
+		$dispatcher = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Mvc\\Dispatcher', array('resolveController'), array($this->objectManager));
 		$dispatcher->expects($this->any())->method('resolveController')->will($this->returnValue($this->controller));
-		$dispatcher->_set('signalSlotDispatcher', $this->objectManager->get('TYPO3\CMS\Extbase\SignalSlot\Dispatcher'));
+		$dispatcher->_set('signalSlotDispatcher', $this->objectManager->get('TYPO3\\CMS\\Extbase\\SignalSlot\\Dispatcher'));
 
-		$this->taskExecuter = $this->getAccessibleMock('TYPO3\CMS\Extbase\Scheduler\TaskExecutor', array('dummy', 'shutdown', 'getDispatcher'));
+		$this->taskExecuter = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Scheduler\\TaskExecutor', array('dummy', 'shutdown', 'getDispatcher'));
 		$this->taskExecuter->expects($this->any())->method('getDispatcher')->will($this->returnValue($dispatcher));
 		$this->taskExecuter->_set('objectManager', $this->objectManager);
 		$this->taskExecuter->_set('commandManager', $this->commandManager);
diff --git a/typo3/sysext/extensionmanager/Classes/Utility/ConfigurationUtility.php b/typo3/sysext/extensionmanager/Classes/Utility/ConfigurationUtility.php
index 4c21b1c1d6e8..efd77e62fb91 100644
--- a/typo3/sysext/extensionmanager/Classes/Utility/ConfigurationUtility.php
+++ b/typo3/sysext/extensionmanager/Classes/Utility/ConfigurationUtility.php
@@ -71,7 +71,7 @@ class ConfigurationUtility implements \TYPO3\CMS\Core\SingletonInterface {
 		/** @var $configurationManager \TYPO3\CMS\Core\Configuration\ConfigurationManager */
 		$configurationManager = $this->objectManager->get('TYPO3\\CMS\\Core\\Configuration\\ConfigurationManager');
 		$configurationManager->setLocalConfigurationValueByPath('EXT/extConf/' . $extensionKey, serialize($configuration));
-		$GLOBALS['typo3CacheManager']->flushCachesInGroup('system');
+		\TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Cache\\CacheManager')->flushCachesInGroup('system');
 	}
 
 	/**
diff --git a/typo3/sysext/extensionmanager/Classes/Utility/InstallUtility.php b/typo3/sysext/extensionmanager/Classes/Utility/InstallUtility.php
index 878992cce042..12283fa25f94 100644
--- a/typo3/sysext/extensionmanager/Classes/Utility/InstallUtility.php
+++ b/typo3/sysext/extensionmanager/Classes/Utility/InstallUtility.php
@@ -26,6 +26,7 @@ namespace TYPO3\CMS\Extensionmanager\Utility;
  *
  *  This copyright notice MUST APPEAR in all copies of the script!
  ***************************************************************/
+
 /**
  * Extension Manager Install Utility
  *
@@ -81,6 +82,12 @@ class InstallUtility implements \TYPO3\CMS\Core\SingletonInterface {
 	 */
 	protected $packageManager;
 
+	/**
+	 * @var \TYPO3\CMS\Core\Cache\CacheManager
+	 * @inject
+	 */
+	protected $cacheManager;
+
 	/**
 	 * @var \TYPO3\CMS\Extbase\SignalSlot\Dispatcher
 	 * @inject
@@ -123,7 +130,7 @@ class InstallUtility implements \TYPO3\CMS\Core\SingletonInterface {
 		$this->processRuntimeDatabaseUpdates($extensionKey);
 		$this->saveDefaultConfiguration($extension['key']);
 		if ($extension['clearcacheonload']) {
-			$GLOBALS['typo3CacheManager']->flushCaches();
+			$this->cacheManager->flushCaches();
 		}
 	}
 
@@ -290,7 +297,7 @@ class InstallUtility implements \TYPO3\CMS\Core\SingletonInterface {
 	 * @return void
 	 */
 	public function reloadCaches() {
-		$GLOBALS['typo3CacheManager']->flushCachesInGroup('system');
+		$this->cacheManager->flushCachesInGroup('system');
 		\TYPO3\CMS\Core\Core\Bootstrap::getInstance()->reloadTypo3LoadedExtAndClassLoaderAndExtLocalconf()->loadExtensionTables();
 	}
 
diff --git a/typo3/sysext/extensionmanager/Tests/Unit/Utility/InstallUtilityTest.php b/typo3/sysext/extensionmanager/Tests/Unit/Utility/InstallUtilityTest.php
index a0e2c95551a6..1b128e131521 100644
--- a/typo3/sysext/extensionmanager/Tests/Unit/Utility/InstallUtilityTest.php
+++ b/typo3/sysext/extensionmanager/Tests/Unit/Utility/InstallUtilityTest.php
@@ -45,7 +45,7 @@ class InstallUtilityTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
 	protected $fakedExtensions = array();
 
 	/**
-	 * @var \PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Extensionmanager\Utility\InstallUtility
+	 * @var \PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Extensionmanager\Utility\InstallUtility|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface
 	 */
 	protected $installMock;
 
@@ -142,8 +142,9 @@ class InstallUtilityTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
 	 */
 	public function installCallsFlushCachesIfClearCacheOnLoadIsSet() {
 		$this->extensionData['clearcacheonload'] = TRUE;
-		$GLOBALS['typo3CacheManager'] = $this->getMock('TYPO3\\CMS\\Core\\Cache\\CacheManager');
-		$GLOBALS['typo3CacheManager']->expects($this->once())->method('flushCaches');
+		$cacheManagerMock = $this->getMock('TYPO3\\CMS\\Core\\Cache\\CacheManager');
+		$cacheManagerMock->expects($this->once())->method('flushCaches');
+		$this->installMock->_set('cacheManager', $cacheManagerMock);
 		$this->installMock->install($this->extensionKey);
 	}
 
diff --git a/typo3/sysext/fluid/Classes/View/AbstractTemplateView.php b/typo3/sysext/fluid/Classes/View/AbstractTemplateView.php
index ae241c7c3271..6a94fcddc1c3 100644
--- a/typo3/sysext/fluid/Classes/View/AbstractTemplateView.php
+++ b/typo3/sysext/fluid/Classes/View/AbstractTemplateView.php
@@ -79,7 +79,7 @@ abstract class AbstractTemplateView implements \TYPO3\CMS\Extbase\Mvc\View\ViewI
 	 */
 	public function injectTemplateCompiler(\TYPO3\CMS\Fluid\Core\Compiler\TemplateCompiler $templateCompiler) {
 		$this->templateCompiler = $templateCompiler;
-		$this->templateCompiler->setTemplateCache($GLOBALS['typo3CacheManager']->getCache('fluid_template'));
+		$this->templateCompiler->setTemplateCache(\TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Cache\\CacheManager')->getCache('fluid_template'));
 	}
 
 	/**
diff --git a/typo3/sysext/fluid/Classes/View/StandaloneView.php b/typo3/sysext/fluid/Classes/View/StandaloneView.php
index 8dbbfc851a6d..8bda6a82af66 100644
--- a/typo3/sysext/fluid/Classes/View/StandaloneView.php
+++ b/typo3/sysext/fluid/Classes/View/StandaloneView.php
@@ -89,7 +89,7 @@ class StandaloneView extends \TYPO3\CMS\Fluid\View\AbstractTemplateView {
 		$this->setControllerContext($controllerContext);
 		$this->templateCompiler = $this->objectManager->get('TYPO3\\CMS\\Fluid\\Core\\Compiler\\TemplateCompiler');
 		// singleton
-		$this->templateCompiler->setTemplateCache($GLOBALS['typo3CacheManager']->getCache('fluid_template'));
+		$this->templateCompiler->setTemplateCache(\TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Cache\\CacheManager')->getCache('fluid_template'));
 	}
 
 	/**
diff --git a/typo3/sysext/frontend/Classes/ContentObject/ContentObjectRenderer.php b/typo3/sysext/frontend/Classes/ContentObject/ContentObjectRenderer.php
index a99ab0e036d5..f2bbc8ad3b0d 100644
--- a/typo3/sysext/frontend/Classes/ContentObject/ContentObjectRenderer.php
+++ b/typo3/sysext/frontend/Classes/ContentObject/ContentObjectRenderer.php
@@ -2144,7 +2144,7 @@ class ContentObjectRenderer {
 	public function stdWrap_cacheRead($content = '', $conf = array()) {
 		if (!empty($conf['cache.']['key'])) {
 			/** @var $cacheFrontend \TYPO3\CMS\Core\Cache\Frontend\VariableFrontend */
-			$cacheFrontend = $GLOBALS['typo3CacheManager']->getCache('cache_hash');
+			$cacheFrontend = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Cache\\CacheManager')->getCache('cache_hash');
 			if ($cacheFrontend && $cacheFrontend->has($conf['cache.']['key'])) {
 				$content = $cacheFrontend->get($conf['cache.']['key']);
 				$this->stopRendering[$this->stdWrapRecursionLevel] = TRUE;
@@ -3385,7 +3385,7 @@ class ContentObjectRenderer {
 	public function stdWrap_cacheStore($content = '', $conf = array()) {
 		if (!empty($conf['cache.']['key'])) {
 			/** @var $cacheFrontend \TYPO3\CMS\Core\Cache\Frontend\VariableFrontend */
-			$cacheFrontend = $GLOBALS['typo3CacheManager']->getCache('cache_hash');
+			$cacheFrontend = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Cache\\CacheManager')->getCache('cache_hash');
 			if ($cacheFrontend) {
 				$tags = !empty($conf['cache.']['tags']) ? GeneralUtility::trimExplode(',', $conf['cache.']['tags']) : array();
 				if (strtolower($conf['cache.']['lifetime']) == 'unlimited') {
diff --git a/typo3/sysext/frontend/Classes/Controller/TypoScriptFrontendController.php b/typo3/sysext/frontend/Classes/Controller/TypoScriptFrontendController.php
index e8a356d62869..6b26ed34b86a 100644
--- a/typo3/sysext/frontend/Classes/Controller/TypoScriptFrontendController.php
+++ b/typo3/sysext/frontend/Classes/Controller/TypoScriptFrontendController.php
@@ -897,7 +897,7 @@ class TypoScriptFrontendController {
 	 * @return void
 	 */
 	protected function initCaches() {
-		$this->pageCache = $GLOBALS['typo3CacheManager']->getCache('cache_pages');
+		$this->pageCache = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Cache\\CacheManager')->getCache('cache_pages');
 	}
 
 	/**
@@ -4514,7 +4514,7 @@ if (version == "n3") {
 	 */
 	public function get_cache_timeout() {
 		/** @var $runtimeCache \TYPO3\CMS\Core\Cache\Frontend\AbstractFrontend */
-		$runtimeCache = $GLOBALS['typo3CacheManager']->getCache('cache_runtime');
+		$runtimeCache = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Cache\\CacheManager')->getCache('cache_runtime');
 		$cachedCacheLifetimeIdentifier = 'core-tslib_fe-get_cache_timeout';
 		$cachedCacheLifetime = $runtimeCache->get($cachedCacheLifetimeIdentifier);
 		if ($cachedCacheLifetime === FALSE) {
@@ -4877,7 +4877,7 @@ if (version == "n3") {
 	protected function getSysDomainCache() {
 		$entryIdentifier = 'core-database-sys_domain-complete';
 		/** @var $runtimeCache \TYPO3\CMS\Core\Cache\Frontend\AbstractFrontend */
-		$runtimeCache = $GLOBALS['typo3CacheManager']->getCache('cache_runtime');
+		$runtimeCache = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Cache\\CacheManager')->getCache('cache_runtime');
 
 		$sysDomainData = array();
 		if ($runtimeCache->has($entryIdentifier)) {
diff --git a/typo3/sysext/frontend/Classes/Page/PageRepository.php b/typo3/sysext/frontend/Classes/Page/PageRepository.php
index bd896578da75..a81a1ff56596 100644
--- a/typo3/sysext/frontend/Classes/Page/PageRepository.php
+++ b/typo3/sysext/frontend/Classes/Page/PageRepository.php
@@ -811,12 +811,10 @@ class PageRepository {
 	 */
 	static public function getHash($hash, $expTime = 0) {
 		$hashContent = NULL;
-		if (is_object($GLOBALS['typo3CacheManager'])) {
-			$contentHashCache = $GLOBALS['typo3CacheManager']->getCache('cache_hash');
-			$cacheEntry = $contentHashCache->get($hash);
-			if ($cacheEntry) {
-				$hashContent = $cacheEntry;
-			}
+		$contentHashCache = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Cache\\CacheManager')->getCache('cache_hash');
+		$cacheEntry = $contentHashCache->get($hash);
+		if ($cacheEntry) {
+			$hashContent = $cacheEntry;
 		}
 		return $hashContent;
 	}
@@ -835,9 +833,7 @@ class PageRepository {
 	 * @see tslib_TStemplate::start(), getHash()
 	 */
 	static public function storeHash($hash, $data, $ident, $lifetime = 0) {
-		if (is_object($GLOBALS['typo3CacheManager'])) {
-			$GLOBALS['typo3CacheManager']->getCache('cache_hash')->set($hash, $data, array('ident_' . $ident), (int)$lifetime);
-		}
+		GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Cache\\CacheManager')->getCache('cache_hash')->set($hash, $data, array('ident_' . $ident), (int)$lifetime);
 	}
 
 	/**
diff --git a/typo3/sysext/indexed_search/Classes/Controller/IndexedPagesController.php b/typo3/sysext/indexed_search/Classes/Controller/IndexedPagesController.php
index 7703b2b13f88..3435d1e2750e 100644
--- a/typo3/sysext/indexed_search/Classes/Controller/IndexedPagesController.php
+++ b/typo3/sysext/indexed_search/Classes/Controller/IndexedPagesController.php
@@ -990,7 +990,7 @@ class IndexedPagesController extends \TYPO3\CMS\Backend\Module\AbstractFunctionM
 						while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
 							$idList[] = (int)$row['page_id'];
 						}
-						$pageCache = $GLOBALS['typo3CacheManager']->getCache('cache_pages');
+						$pageCache = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Cache\\CacheManager')->getCache('cache_pages');
 						foreach ($idList as $pageId) {
 							$pageCache->flushByTag('pageId_' . $pageId);
 						}
diff --git a/typo3/sysext/install/Classes/Controller/AbstractController.php b/typo3/sysext/install/Classes/Controller/AbstractController.php
index 186e79f3d82d..9160970746b5 100644
--- a/typo3/sysext/install/Classes/Controller/AbstractController.php
+++ b/typo3/sysext/install/Classes/Controller/AbstractController.php
@@ -431,7 +431,7 @@ class AbstractController {
 		$GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['fluid_template']['options'] = array();
 
 		/** @var $cacheManager \TYPO3\CMS\Core\Cache\CacheManager */
-		$cacheManager = $GLOBALS['typo3CacheManager'];
+		$cacheManager = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Cache\\CacheManager');
 		$cacheManager->setCacheConfigurations($GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']);
 	}
 
diff --git a/typo3/sysext/install/Classes/Controller/Action/Step/DatabaseConnect.php b/typo3/sysext/install/Classes/Controller/Action/Step/DatabaseConnect.php
index c0b8c3ecd693..ee5147873759 100644
--- a/typo3/sysext/install/Classes/Controller/Action/Step/DatabaseConnect.php
+++ b/typo3/sysext/install/Classes/Controller/Action/Step/DatabaseConnect.php
@@ -183,7 +183,7 @@ class DatabaseConnect extends AbstractStepAction {
 					->disableCoreAndClassesCache();
 				if ($this->isDbalEnabled()) {
 					require(ExtensionManagementUtility::extPath('dbal') . 'ext_localconf.php');
-					$GLOBALS['typo3CacheManager']->setCacheConfigurations($GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']);
+					\TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Cache\\CacheManager')->setCacheConfigurations($GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']);
 				}
 				if (!$this->isConnectSuccessful()) {
 					/** @var $errorStatus \TYPO3\CMS\Install\Status\ErrorStatus */
diff --git a/typo3/sysext/install/Classes/Service/CachingFrameworkDatabaseSchemaService.php b/typo3/sysext/install/Classes/Service/CachingFrameworkDatabaseSchemaService.php
index fe04a1d7d4aa..3dcbc4830d8f 100644
--- a/typo3/sysext/install/Classes/Service/CachingFrameworkDatabaseSchemaService.php
+++ b/typo3/sysext/install/Classes/Service/CachingFrameworkDatabaseSchemaService.php
@@ -67,7 +67,7 @@ class CachingFrameworkDatabaseSchemaService {
 			'groups' => array('system')
 		);
 		/** @var \TYPO3\CMS\Core\Cache\CacheManager $cacheManager */
-		$cacheManager = $GLOBALS['typo3CacheManager'];
+		$cacheManager = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Cache\\CacheManager');
 		$cacheManager->setCacheConfigurations($GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']);
 		$cacheSqlString = \TYPO3\CMS\Core\Cache\Cache::getDatabaseTableDefinitions();
 		$sqlString = str_replace($extbaseObjectFakeName, 'extbase_object', $cacheSqlString);
diff --git a/typo3/sysext/install/Classes/Service/ClearCacheService.php b/typo3/sysext/install/Classes/Service/ClearCacheService.php
index cc12e0cad7e0..ff7245c43090 100644
--- a/typo3/sysext/install/Classes/Service/ClearCacheService.php
+++ b/typo3/sysext/install/Classes/Service/ClearCacheService.php
@@ -82,7 +82,7 @@ class ClearCacheService {
 			->initializeTypo3DbGlobal()
 			->loadExtensionTables(FALSE);
 
-		// $GLOBALS['typo3CacheManager'] is already instantiated in the install tool
+		// The cache manager is already instantiated in the install tool
 		// with some hacked settings to disable caching of extbase and fluid.
 		// We want a "fresh" object here to operate on a different cache setup.
 		// cacheManager implements SingletonInterface, so the only way to get a "fresh"
diff --git a/typo3/sysext/install/Classes/View/StandaloneView.php b/typo3/sysext/install/Classes/View/StandaloneView.php
index aabbcbed0882..dd34ca5c81c2 100644
--- a/typo3/sysext/install/Classes/View/StandaloneView.php
+++ b/typo3/sysext/install/Classes/View/StandaloneView.php
@@ -49,6 +49,6 @@ class StandaloneView extends \TYPO3\CMS\Fluid\View\StandaloneView {
 		$controllerContext->setUriBuilder($uriBuilder);
 		$this->setControllerContext($controllerContext);
 		$this->templateCompiler = $this->objectManager->get('TYPO3\\CMS\\Fluid\\Core\\Compiler\\TemplateCompiler');
-		$this->templateCompiler->setTemplateCache($GLOBALS['typo3CacheManager']->getCache('fluid_template'));
+		$this->templateCompiler->setTemplateCache(\TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Cache\\CacheManager')->getCache('fluid_template'));
 	}
 }
diff --git a/typo3/sysext/scheduler/Classes/Task/CachingFrameworkGarbageCollectionTask.php b/typo3/sysext/scheduler/Classes/Task/CachingFrameworkGarbageCollectionTask.php
index adac2f81c5a6..86c44b0cc642 100644
--- a/typo3/sysext/scheduler/Classes/Task/CachingFrameworkGarbageCollectionTask.php
+++ b/typo3/sysext/scheduler/Classes/Task/CachingFrameworkGarbageCollectionTask.php
@@ -57,7 +57,7 @@ class CachingFrameworkGarbageCollectionTask extends \TYPO3\CMS\Scheduler\Task\Ab
 				// The cache backend used for this cache
 				$usedCacheBackend = $cacheConfiguration['backend'];
 				if (in_array($usedCacheBackend, $this->selectedBackends)) {
-					$GLOBALS['typo3CacheManager']->getCache($cacheName)->collectGarbage();
+					\TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Cache\\CacheManager')->getCache($cacheName)->collectGarbage();
 				}
 			}
 		}
diff --git a/typo3/sysext/scheduler/Tests/Unit/Task/CachingFrameworkGarbageCollectionTest.php b/typo3/sysext/scheduler/Tests/Unit/Task/CachingFrameworkGarbageCollectionTest.php
index 08923c68a248..c30c366a7840 100644
--- a/typo3/sysext/scheduler/Tests/Unit/Task/CachingFrameworkGarbageCollectionTest.php
+++ b/typo3/sysext/scheduler/Tests/Unit/Task/CachingFrameworkGarbageCollectionTest.php
@@ -23,6 +23,7 @@ namespace TYPO3\CMS\Scheduler\Tests\Unit\Task;
  *
  *  This copyright notice MUST APPEAR in all copies of the script!
  ***************************************************************/
+use TYPO3\CMS\Core\Utility\GeneralUtility;
 
 /**
  * Test case
@@ -31,6 +32,26 @@ namespace TYPO3\CMS\Scheduler\Tests\Unit\Task;
  */
 class CachingFrameworkGarbageCollectionTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
 
+	/**
+	 * @var array
+	 */
+	protected $singletonInstances = array();
+
+	/**
+	 * Set up
+	 */
+	public function setUp() {
+		$this->singletonInstances = \TYPO3\CMS\Core\Utility\GeneralUtility::getSingletonInstances();
+	}
+
+	/**
+	 * Reset singleton instances
+	 */
+	public function tearDown() {
+		\TYPO3\CMS\Core\Utility\GeneralUtility::resetSingletonInstances($this->singletonInstances);
+		parent::tearDown();
+	}
+
 	/**
 	 * @test
 	 */
@@ -38,8 +59,9 @@ class CachingFrameworkGarbageCollectionTest extends \TYPO3\CMS\Core\Tests\UnitTe
 		$cache = $this->getMock('TYPO3\\CMS\\Core\\Cache\\Frontend\\StringFrontend', array(), array(), '', FALSE);
 		$cache->expects($this->any())->method('getIdentifier')->will($this->returnValue('cache'));
 		$cache->expects($this->atLeastOnce())->method('collectGarbage');
-		$GLOBALS['typo3CacheManager'] = new \TYPO3\CMS\Core\Cache\CacheManager();
-		$GLOBALS['typo3CacheManager']->registerCache($cache);
+		$mockCacheManager = new \TYPO3\CMS\Core\Cache\CacheManager();
+		$mockCacheManager->registerCache($cache);
+		GeneralUtility::setSingletonInstance('TYPO3\\CMS\\Core\\Cache\\CacheManager', $mockCacheManager);
 		$GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations'] = array(
 			'cache' => array(
 				'frontend' => 'TYPO3\\CMS\\Core\\Cache\\Frontend\\StringFrontend',
@@ -58,8 +80,9 @@ class CachingFrameworkGarbageCollectionTest extends \TYPO3\CMS\Core\Tests\UnitTe
 		$cache = $this->getMock('TYPO3\\CMS\\Core\\Cache\\Frontend\\StringFrontend', array(), array(), '', FALSE);
 		$cache->expects($this->any())->method('getIdentifier')->will($this->returnValue('cache'));
 		$cache->expects($this->never())->method('collectGarbage');
-		$GLOBALS['typo3CacheManager'] = new \TYPO3\CMS\Core\Cache\CacheManager();
-		$GLOBALS['typo3CacheManager']->registerCache($cache);
+		$mockCacheManager = new \TYPO3\CMS\Core\Cache\CacheManager();
+		$mockCacheManager->registerCache($cache);
+		GeneralUtility::setSingletonInstance('TYPO3\\CMS\\Core\\Cache\\CacheManager', $mockCacheManager);
 		$GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations'] = array(
 			'cache' => array(
 				'frontend' => 'TYPO3\\CMS\\Core\\Cache\\Frontend\\StringFrontend',
diff --git a/typo3/sysext/workspaces/Classes/Hook/DataHandlerHook.php b/typo3/sysext/workspaces/Classes/Hook/DataHandlerHook.php
index 1582feee461e..92e77cc24686 100644
--- a/typo3/sysext/workspaces/Classes/Hook/DataHandlerHook.php
+++ b/typo3/sysext/workspaces/Classes/Hook/DataHandlerHook.php
@@ -142,7 +142,7 @@ class DataHandlerHook {
 	 * @return void
 	 */
 	protected function flushWorkspaceCacheEntriesByWorkspaceId($workspaceId) {
-		$workspacesCache = $GLOBALS['typo3CacheManager']->getCache('workspaces_cache');
+		$workspacesCache = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Cache\\CacheManager')->getCache('workspaces_cache');
 		$workspacesCache->flushByTag($workspaceId);
 		$workspacesCache->flushByTag(\TYPO3\CMS\Workspaces\Service\WorkspaceService::SELECT_ALL_WORKSPACES);
 	}
diff --git a/typo3/sysext/workspaces/Classes/Service/GridDataService.php b/typo3/sysext/workspaces/Classes/Service/GridDataService.php
index 774510b69093..aeca0ab5508d 100644
--- a/typo3/sysext/workspaces/Classes/Service/GridDataService.php
+++ b/typo3/sysext/workspaces/Classes/Service/GridDataService.php
@@ -247,7 +247,7 @@ class GridDataService {
 	 * @return void
 	 */
 	protected function initializeWorkspacesCachingFramework() {
-		$this->workspacesCache = $GLOBALS['typo3CacheManager']->getCache('workspaces_cache');
+		$this->workspacesCache = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Cache\\CacheManager')->getCache('workspaces_cache');
 	}
 
 	/**
-- 
GitLab