diff --git a/typo3/sysext/core/Classes/Cache/CacheFactory.php b/typo3/sysext/core/Classes/Cache/CacheFactory.php index e5d901a65515c75fa0215d6d8c49189b6d9cd50d..265ad1fda3ea766624b6467a41a7ece02c3dd116 100644 --- a/typo3/sysext/core/Classes/Cache/CacheFactory.php +++ b/typo3/sysext/core/Classes/Cache/CacheFactory.php @@ -14,14 +14,15 @@ namespace TYPO3\CMS\Core\Cache; * The TYPO3 project - inspiring people to share! */ +use TYPO3\CMS\Core\Utility\GeneralUtility; + /** * This cache factory takes care of instantiating a cache frontend and injecting * a certain cache backend. After creation of the new cache, the cache object * is registered at the cache manager. * - * This file is a backport from FLOW3 - * @scope singleton - * @api + * @deprecated This file is not in use anymore, as the functionality + * was moved into the CacheManager class. */ class CacheFactory implements \TYPO3\CMS\Core\SingletonInterface { @@ -47,12 +48,13 @@ class CacheFactory implements \TYPO3\CMS\Core\SingletonInterface * * @param string $context The current FLOW3 context * @param \TYPO3\CMS\Core\Cache\CacheManager $cacheManager The cache manager + * @deprecated since TYPO3 v8, will be removed in TYPO3 v9, as it is not needed anymore */ public function __construct($context, \TYPO3\CMS\Core\Cache\CacheManager $cacheManager) { + GeneralUtility::logDeprecatedFunction(); $this->context = $context; $this->cacheManager = $cacheManager; - $this->cacheManager->injectCacheFactory($this); } /** @@ -71,7 +73,7 @@ class CacheFactory implements \TYPO3\CMS\Core\SingletonInterface public function create($cacheIdentifier, $cacheObjectName, $backendObjectName, array $backendOptions = array()) { // New operator used on purpose: This class is required early during - // bootstrap before makeInstance() is propely set up + // bootstrap before makeInstance() is properly set up $backendObjectName = '\\' . ltrim($backendObjectName, '\\'); $backend = new $backendObjectName($this->context, $backendOptions); if (!$backend instanceof \TYPO3\CMS\Core\Cache\Backend\BackendInterface) { diff --git a/typo3/sysext/core/Classes/Cache/CacheManager.php b/typo3/sysext/core/Classes/Cache/CacheManager.php index dfce8144efcae3d7ead698a8dcf5a86bff049857..ed3e486865259379f4fc3524ab18eaa8e922796c 100644 --- a/typo3/sysext/core/Classes/Cache/CacheManager.php +++ b/typo3/sysext/core/Classes/Cache/CacheManager.php @@ -14,7 +14,16 @@ namespace TYPO3\CMS\Core\Cache; * The TYPO3 project - inspiring people to share! */ +use TYPO3\CMS\Core\Cache\Backend\BackendInterface; +use TYPO3\CMS\Core\Cache\Backend\Typo3DatabaseBackend; +use TYPO3\CMS\Core\Cache\Exception\DuplicateIdentifierException; +use TYPO3\CMS\Core\Cache\Exception\InvalidBackendException; +use TYPO3\CMS\Core\Cache\Exception\InvalidCacheException; +use TYPO3\CMS\Core\Cache\Exception\NoSuchCacheException; use TYPO3\CMS\Core\Cache\Exception\NoSuchCacheGroupException; +use TYPO3\CMS\Core\Cache\Frontend\FrontendInterface; +use TYPO3\CMS\Core\Cache\Frontend\VariableFrontend; +use TYPO3\CMS\Core\SingletonInterface; /** * The Cache Manager @@ -23,15 +32,10 @@ use TYPO3\CMS\Core\Cache\Exception\NoSuchCacheGroupException; * @scope singleton * @api */ -class CacheManager implements \TYPO3\CMS\Core\SingletonInterface +class CacheManager implements SingletonInterface { /** - * @var \TYPO3\CMS\Core\Cache\CacheFactory - */ - protected $cacheFactory; - - /** - * @var \TYPO3\CMS\Core\Cache\Frontend\FrontendInterface[] + * @var FrontendInterface[] */ protected $caches = array(); @@ -54,21 +58,12 @@ class CacheManager implements \TYPO3\CMS\Core\SingletonInterface * @var array Default cache configuration as fallback */ protected $defaultCacheConfiguration = array( - 'frontend' => \TYPO3\CMS\Core\Cache\Frontend\VariableFrontend::class, - 'backend' => \TYPO3\CMS\Core\Cache\Backend\Typo3DatabaseBackend::class, + 'frontend' => VariableFrontend::class, + 'backend' => Typo3DatabaseBackend::class, 'options' => array(), 'groups' => array('all') ); - /** - * @param \TYPO3\CMS\Core\Cache\CacheFactory $cacheFactory - * @return void - */ - public function injectCacheFactory(\TYPO3\CMS\Core\Cache\CacheFactory $cacheFactory) - { - $this->cacheFactory = $cacheFactory; - } - /** * Sets configurations for caches. The key of each entry specifies the * cache identifier and the value is an array of configuration options. @@ -98,16 +93,16 @@ class CacheManager implements \TYPO3\CMS\Core\SingletonInterface /** * Registers a cache so it can be retrieved at a later point. * - * @param \TYPO3\CMS\Core\Cache\Frontend\FrontendInterface $cache The cache frontend to be registered + * @param FrontendInterface $cache The cache frontend to be registered * @return void - * @throws \TYPO3\CMS\Core\Cache\Exception\DuplicateIdentifierException if a cache with the given identifier has already been registered. + * @throws DuplicateIdentifierException if a cache with the given identifier has already been registered. * @api */ - public function registerCache(\TYPO3\CMS\Core\Cache\Frontend\FrontendInterface $cache) + public function registerCache(FrontendInterface $cache) { $identifier = $cache->getIdentifier(); if (isset($this->caches[$identifier])) { - throw new \TYPO3\CMS\Core\Cache\Exception\DuplicateIdentifierException('A cache with identifier "' . $identifier . '" has already been registered.', 1203698223); + throw new DuplicateIdentifierException('A cache with identifier "' . $identifier . '" has already been registered.', 1203698223); } $this->caches[$identifier] = $cache; } @@ -116,14 +111,14 @@ class CacheManager implements \TYPO3\CMS\Core\SingletonInterface * Returns the cache specified by $identifier * * @param string $identifier Identifies which cache to return - * @return \TYPO3\CMS\Core\Cache\Frontend\FrontendInterface The specified cache frontend - * @throws \TYPO3\CMS\Core\Cache\Exception\NoSuchCacheException + * @return FrontendInterface The specified cache frontend + * @throws NoSuchCacheException * @api */ public function getCache($identifier) { if ($this->hasCache($identifier) === false) { - throw new \TYPO3\CMS\Core\Cache\Exception\NoSuchCacheException('A cache with identifier "' . $identifier . '" does not exist.', 1203699034); + throw new NoSuchCacheException('A cache with identifier "' . $identifier . '" does not exist.', 1203699034); } if (!isset($this->caches[$identifier])) { $this->createCache($identifier); @@ -237,7 +232,9 @@ class CacheManager implements \TYPO3\CMS\Core\SingletonInterface * Instantiates the cache for $identifier. * * @param string $identifier - * @return void + * @throws DuplicateIdentifierException + * @throws InvalidBackendException + * @throws InvalidCacheException */ protected function createCache($identifier) { @@ -270,6 +267,26 @@ class CacheManager implements \TYPO3\CMS\Core\SingletonInterface $this->cacheGroups[$groupIdentifier][] = $identifier; } - $this->cacheFactory->create($identifier, $frontend, $backend, $backendOptions); + // New operator used on purpose: This class is required early during + // bootstrap before makeInstance() is properly set up + $backend = '\\' . ltrim($backend, '\\'); + $backendInstance = new $backend('production', $backendOptions); + if (!$backendInstance instanceof BackendInterface) { + throw new InvalidBackendException('"' . $backend . '" is not a valid cache backend object.', 1464550977); + } + if (is_callable(array($backendInstance, 'initializeObject'))) { + $backendInstance->initializeObject(); + } + + // New used on purpose, see comment above + $frontendInstance = new $frontend($identifier, $backendInstance); + if (!$frontendInstance instanceof FrontendInterface) { + throw new InvalidCacheException('"' . $frontend . '" is not a valid cache frontend object.', 1464550984); + } + if (is_callable(array($frontendInstance, 'initializeObject'))) { + $frontendInstance->initializeObject(); + } + + $this->registerCache($frontendInstance); } } diff --git a/typo3/sysext/core/Classes/Cache/DatabaseSchemaService.php b/typo3/sysext/core/Classes/Cache/DatabaseSchemaService.php index e33f98887b7755569d3e2c9175c45183c6e1492c..0e3b062fea130800517ab7852b9241b5386dc9ee 100644 --- a/typo3/sysext/core/Classes/Cache/DatabaseSchemaService.php +++ b/typo3/sysext/core/Classes/Cache/DatabaseSchemaService.php @@ -29,10 +29,8 @@ class DatabaseSchemaService public function getCachingFrameworkRequiredDatabaseSchema() { // Use new to circumvent the singleton pattern of CacheManager - $cacheManager = new CacheManager; + $cacheManager = new CacheManager(); $cacheManager->setCacheConfigurations($GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']); - // Cache manager needs cache factory. cache factory injects itself to manager in __construct() - new CacheFactory('production', $cacheManager); $tableDefinitions = ''; foreach ($GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations'] as $cacheName => $_) { diff --git a/typo3/sysext/core/Classes/Core/Bootstrap.php b/typo3/sysext/core/Classes/Core/Bootstrap.php index 0e44f4749d265184ff9817ad1186346c81d3d35d..0a5e49a00ebb343f6e2c4a08f930bf820d237035 100644 --- a/typo3/sysext/core/Classes/Core/Bootstrap.php +++ b/typo3/sysext/core/Classes/Core/Bootstrap.php @@ -564,10 +564,6 @@ class Bootstrap $cacheManager = new \TYPO3\CMS\Core\Cache\CacheManager(); $cacheManager->setCacheConfigurations($GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']); GeneralUtility::setSingletonInstance(\TYPO3\CMS\Core\Cache\CacheManager::class, $cacheManager); - - $cacheFactory = new \TYPO3\CMS\Core\Cache\CacheFactory('production', $cacheManager); - GeneralUtility::setSingletonInstance(\TYPO3\CMS\Core\Cache\CacheFactory::class, $cacheFactory); - $this->setEarlyInstance(\TYPO3\CMS\Core\Cache\CacheManager::class, $cacheManager); return $this; } diff --git a/typo3/sysext/core/Documentation/Changelog/master/Deprecation-76370-DeprecateCacheFactory.rst b/typo3/sysext/core/Documentation/Changelog/master/Deprecation-76370-DeprecateCacheFactory.rst new file mode 100644 index 0000000000000000000000000000000000000000..005f8d50ba6efbdc2862cc8eec938d83734e22d8 --- /dev/null +++ b/typo3/sysext/core/Documentation/Changelog/master/Deprecation-76370-DeprecateCacheFactory.rst @@ -0,0 +1,26 @@ +============================================ +Deprecation: #76370 - Deprecate CacheFactory +============================================ + +Description +=========== + +Class :php:`CacheFactory` has been deprecated. + + +Impact +====== + +The class is no longer used or instantiated by the core. + + +Affected Installations +====================== + +TYPO3 instances and extensions typically make no use of this internal class. + + +Migration +========= + +Nothing notable, do not use this class anymore. \ No newline at end of file diff --git a/typo3/sysext/core/Tests/Unit/Cache/FactoryTest.php b/typo3/sysext/core/Tests/Unit/Cache/CacheFactoryTest.php similarity index 100% rename from typo3/sysext/core/Tests/Unit/Cache/FactoryTest.php rename to typo3/sysext/core/Tests/Unit/Cache/CacheFactoryTest.php diff --git a/typo3/sysext/core/Tests/Unit/Cache/CacheManagerTest.php b/typo3/sysext/core/Tests/Unit/Cache/CacheManagerTest.php index 6c6d19d089c156b315d2c9905ee836fd303cd960..6c909fe8a91994c8ae0396f38be4d0936a281a76 100644 --- a/typo3/sysext/core/Tests/Unit/Cache/CacheManagerTest.php +++ b/typo3/sysext/core/Tests/Unit/Cache/CacheManagerTest.php @@ -14,12 +14,27 @@ namespace TYPO3\CMS\Core\Tests\Unit\Cache; * The TYPO3 project - inspiring people to share! */ +use TYPO3\CMS\Core\Cache\CacheManager; +use TYPO3\CMS\Core\Cache\Exception\InvalidBackendException; +use TYPO3\CMS\Core\Cache\Exception\InvalidCacheException; +use TYPO3\CMS\Core\Cache\Frontend\AbstractFrontend; +use TYPO3\CMS\Core\Tests\Unit\Cache\Fixtures\BackendConfigurationOptionFixture; +use TYPO3\CMS\Core\Tests\Unit\Cache\Fixtures\BackendDefaultFixture; +use TYPO3\CMS\Core\Tests\Unit\Cache\Fixtures\BackendFixture; +use TYPO3\CMS\Core\Tests\Unit\Cache\Fixtures\BackendInitializeObjectFixture; +use TYPO3\CMS\Core\Tests\Unit\Cache\Fixtures\FrontendBackendInstanceFixture; +use TYPO3\CMS\Core\Tests\Unit\Cache\Fixtures\FrontendDefaultFixture; +use TYPO3\CMS\Core\Tests\Unit\Cache\Fixtures\FrontendFixture; +use TYPO3\CMS\Core\Tests\Unit\Cache\Fixtures\FrontendIdentifierFixture; +use TYPO3\CMS\Core\Tests\Unit\Cache\Fixtures\FrontendInitializeObjectFixture; +use TYPO3\CMS\Core\Tests\UnitTestCase; + /** * Testcase for the TYPO3\CMS\Core\Cache\CacheManager * * This file is a backport from FLOW3 */ -class CacheManagerTest extends \TYPO3\CMS\Core\Tests\UnitTestCase +class CacheManagerTest extends UnitTestCase { /** * @test @@ -27,10 +42,10 @@ class CacheManagerTest extends \TYPO3\CMS\Core\Tests\UnitTestCase */ public function managerThrowsExceptionOnCacheRegistrationWithAlreadyExistingIdentifier() { - $manager = new \TYPO3\CMS\Core\Cache\CacheManager(); - $cache1 = $this->getMock(\TYPO3\CMS\Core\Cache\Frontend\AbstractFrontend::class, array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove', 'flush', 'flushByTag'), array(), '', false); + $manager = new CacheManager(); + $cache1 = $this->getMock(AbstractFrontend::class, array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove', 'flush', 'flushByTag'), array(), '', false); $cache1->expects($this->atLeastOnce())->method('getIdentifier')->will($this->returnValue('test')); - $cache2 = $this->getMock(\TYPO3\CMS\Core\Cache\Frontend\AbstractFrontend::class, array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove', 'flush', 'flushByTag'), array(), '', false); + $cache2 = $this->getMock(AbstractFrontend::class, array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove', 'flush', 'flushByTag'), array(), '', false); $cache2->expects($this->atLeastOnce())->method('getIdentifier')->will($this->returnValue('test')); $manager->registerCache($cache1); $manager->registerCache($cache2); @@ -41,10 +56,10 @@ class CacheManagerTest extends \TYPO3\CMS\Core\Tests\UnitTestCase */ public function managerReturnsThePreviouslyRegisteredCache() { - $manager = new \TYPO3\CMS\Core\Cache\CacheManager(); - $cache1 = $this->getMock(\TYPO3\CMS\Core\Cache\Frontend\AbstractFrontend::class, array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove', 'flush', 'flushByTag'), array(), '', false); + $manager = new CacheManager(); + $cache1 = $this->getMock(AbstractFrontend::class, array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove', 'flush', 'flushByTag'), array(), '', false); $cache1->expects($this->atLeastOnce())->method('getIdentifier')->will($this->returnValue('cache1')); - $cache2 = $this->getMock(\TYPO3\CMS\Core\Cache\Frontend\AbstractFrontend::class, array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove', 'flush', 'flushByTag'), array(), '', false); + $cache2 = $this->getMock(AbstractFrontend::class, array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove', 'flush', 'flushByTag'), array(), '', false); $cache2->expects($this->atLeastOnce())->method('getIdentifier')->will($this->returnValue('cache2')); $manager->registerCache($cache1); $manager->registerCache($cache2); @@ -57,8 +72,8 @@ class CacheManagerTest extends \TYPO3\CMS\Core\Tests\UnitTestCase */ public function getCacheThrowsExceptionForNonExistingIdentifier() { - $manager = new \TYPO3\CMS\Core\Cache\CacheManager(); - $cache = $this->getMock(\TYPO3\CMS\Core\Cache\Frontend\AbstractFrontend::class, array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove', 'flush', 'flushByTag'), array(), '', false); + $manager = new CacheManager(); + $cache = $this->getMock(AbstractFrontend::class, array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove', 'flush', 'flushByTag'), array(), '', false); $cache->expects($this->atLeastOnce())->method('getIdentifier')->will($this->returnValue('someidentifier')); $manager->registerCache($cache); $manager->getCache('someidentifier'); @@ -70,8 +85,8 @@ class CacheManagerTest extends \TYPO3\CMS\Core\Tests\UnitTestCase */ public function hasCacheReturnsCorrectResult() { - $manager = new \TYPO3\CMS\Core\Cache\CacheManager(); - $cache1 = $this->getMock(\TYPO3\CMS\Core\Cache\Frontend\AbstractFrontend::class, array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove', 'flush', 'flushByTag'), array(), '', false); + $manager = new CacheManager(); + $cache1 = $this->getMock(AbstractFrontend::class, array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove', 'flush', 'flushByTag'), array(), '', false); $cache1->expects($this->atLeastOnce())->method('getIdentifier')->will($this->returnValue('cache1')); $manager->registerCache($cache1); $this->assertTrue($manager->hasCache('cache1'), 'hasCache() did not return TRUE.'); @@ -83,12 +98,12 @@ class CacheManagerTest extends \TYPO3\CMS\Core\Tests\UnitTestCase */ public function flushCachesByTagCallsTheFlushByTagMethodOfAllRegisteredCaches() { - $manager = new \TYPO3\CMS\Core\Cache\CacheManager(); - $cache1 = $this->getMock(\TYPO3\CMS\Core\Cache\Frontend\AbstractFrontend::class, array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove', 'flush', 'flushByTag'), array(), '', false); + $manager = new CacheManager(); + $cache1 = $this->getMock(AbstractFrontend::class, array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove', 'flush', 'flushByTag'), array(), '', false); $cache1->expects($this->atLeastOnce())->method('getIdentifier')->will($this->returnValue('cache1')); $cache1->expects($this->once())->method('flushByTag')->with($this->equalTo('theTag')); $manager->registerCache($cache1); - $cache2 = $this->getMock(\TYPO3\CMS\Core\Cache\Frontend\AbstractFrontend::class, array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove', 'flush', 'flushByTag'), array(), '', false); + $cache2 = $this->getMock(AbstractFrontend::class, array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove', 'flush', 'flushByTag'), array(), '', false); $cache2->expects($this->once())->method('flushByTag')->with($this->equalTo('theTag')); $manager->registerCache($cache2); $manager->flushCachesByTag('theTag'); @@ -99,12 +114,12 @@ class CacheManagerTest extends \TYPO3\CMS\Core\Tests\UnitTestCase */ public function flushCachesCallsTheFlushMethodOfAllRegisteredCaches() { - $manager = new \TYPO3\CMS\Core\Cache\CacheManager(); - $cache1 = $this->getMock(\TYPO3\CMS\Core\Cache\Frontend\AbstractFrontend::class, array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove', 'flush', 'flushByTag'), array(), '', false); + $manager = new CacheManager(); + $cache1 = $this->getMock(AbstractFrontend::class, array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove', 'flush', 'flushByTag'), array(), '', false); $cache1->expects($this->atLeastOnce())->method('getIdentifier')->will($this->returnValue('cache1')); $cache1->expects($this->once())->method('flush'); $manager->registerCache($cache1); - $cache2 = $this->getMock(\TYPO3\CMS\Core\Cache\Frontend\AbstractFrontend::class, array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove', 'flush', 'flushByTag'), array(), '', false); + $cache2 = $this->getMock(AbstractFrontend::class, array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove', 'flush', 'flushByTag'), array(), '', false); $cache2->expects($this->once())->method('flush'); $manager->registerCache($cache2); $manager->flushCaches(); @@ -116,7 +131,7 @@ class CacheManagerTest extends \TYPO3\CMS\Core\Tests\UnitTestCase */ public function flushCachesInGroupThrowsExceptionForNonExistingGroup() { - $manager = new \TYPO3\CMS\Core\Cache\CacheManager(); + $manager = new CacheManager(); $manager->flushCachesInGroup('nonExistingGroup'); } @@ -126,31 +141,112 @@ class CacheManagerTest extends \TYPO3\CMS\Core\Tests\UnitTestCase */ public function flushCachesInGroupByTagThrowsExceptionForNonExistingGroup() { - $manager = new \TYPO3\CMS\Core\Cache\CacheManager(); - $manager->flushCachesInGroup('nonExistingGroup', 'someTag'); + $manager = new CacheManager(); + $manager->flushCachesInGroup('nonExistingGroup'); } /** * @test */ - public function getCacheCreatesCacheInstanceWithGivenConfiguration() + public function getCacheThrowsExceptionIfConfiguredFrontendDoesNotImplementFrontendInterface() { - $manager = new \TYPO3\CMS\Core\Cache\CacheManager(); - $cacheIdentifier = $this->getUniqueId('Test'); - $cacheObjectName = 'testCache'; - $backendObjectName = 'testBackend'; - $backendOptions = array('foo'); - $configuration = array( - $cacheIdentifier => array( - 'frontend' => $cacheObjectName, - 'backend' => $backendObjectName, - 'options' => $backendOptions - ) - ); - $factory = $this->getMock(\TYPO3\CMS\Core\Cache\CacheFactory::class, array('create'), array(), '', false); - $factory->expects($this->once())->method('create')->with($cacheIdentifier, $cacheObjectName, $backendObjectName, $backendOptions); - $manager->injectCacheFactory($factory); + $manager = new CacheManager(); + $cacheIdentifier = 'aCache'; + $configuration = [ + $cacheIdentifier => [ + 'frontend' => \stdClass::class, + 'backend' => BackendFixture::class, + 'options' => [], + ], + ]; + $manager->setCacheConfigurations($configuration); + $this->expectException(InvalidCacheException::class); + $this->expectExceptionCode(1464550984); + $manager->getCache($cacheIdentifier); + } + + /** + * @test + */ + public function getCacheThrowsExceptionIfConfiguredBackendDoesNotImplementBackendInterface() + { + $manager = new CacheManager(); + $cacheIdentifier = 'aCache'; + $configuration = [ + $cacheIdentifier => [ + 'frontend' => FrontendFixture::class, + 'backend' => \stdClass::class, + 'options' => [], + ], + ]; $manager->setCacheConfigurations($configuration); + $this->expectException(InvalidBackendException::class); + $this->expectExceptionCode(1464550977); + $manager->getCache($cacheIdentifier); + } + + /** + * @test + */ + public function getCacheCallsInitializeObjectOnFrontendInstance() + { + $manager = new CacheManager(); + $cacheIdentifier = 'aCache'; + $configuration = [ + $cacheIdentifier => [ + 'backend' => BackendFixture::class, + 'frontend' => FrontendInitializeObjectFixture::class, + 'options' => [], + ], + ]; + $manager->setCacheConfigurations($configuration); + // BackendInitializeObjectFixture throws exception if initializeObject() is called, so expect this + $this->expectException(\RuntimeException::class); + $this->expectExceptionCode(1464553495); + $manager->getCache($cacheIdentifier); + } + + /** + * @test + */ + public function getCacheCallsInitializeObjectOnBackendInstance() + { + $manager = new CacheManager(); + $cacheIdentifier = 'aCache'; + $configuration = [ + $cacheIdentifier => [ + 'backend' => BackendInitializeObjectFixture::class, + 'frontend' => FrontendFixture::class, + 'options' => [], + ], + ]; + $manager->setCacheConfigurations($configuration); + // BackendInitializeObjectFixture throws exception if initializeObject() is called, so expect this + $this->expectException(\RuntimeException::class); + $this->expectExceptionCode(1464552894); + $manager->getCache($cacheIdentifier); + } + + /** + * @test + */ + public function getCacheCreatesBackendWithGivenConfiguration() + { + $manager = new CacheManager(); + $cacheIdentifier = 'aCache'; + $configuration = [ + $cacheIdentifier => [ + 'backend' => BackendConfigurationOptionFixture::class, + 'frontend' => FrontendFixture::class, + 'options' => [ + 'anOption' => 'anOptionValue', + ], + ], + ]; + $manager->setCacheConfigurations($configuration); + // BackendInitializeObjectFixture throws exception if initializeObject() is called, so expect this + $this->expectException(\RuntimeException::class); + $this->expectExceptionCode(1464555007); $manager->getCache($cacheIdentifier); } @@ -159,20 +255,24 @@ class CacheManagerTest extends \TYPO3\CMS\Core\Tests\UnitTestCase */ public function getCacheCreatesCacheInstanceWithFallbackToDefaultFrontend() { - $manager = new \TYPO3\CMS\Core\Cache\CacheManager(); + /** @var \PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|CacheManager $manager */ + $manager = $this->getAccessibleMock(CacheManager::class, ['dummy'], [], '', false); $cacheIdentifier = $this->getUniqueId('Test'); - $backendObjectName = 'testBackend'; - $backendOptions = array('foo'); $configuration = array( $cacheIdentifier => array( - 'backend' => $backendObjectName, - 'options' => $backendOptions + 'backend' => BackendFixture::class, + 'options' => [] ) ); - $factory = $this->getMock(\TYPO3\CMS\Core\Cache\CacheFactory::class, array('create'), array(), '', false); - $factory->expects($this->once())->method('create')->with($cacheIdentifier, \TYPO3\CMS\Core\Cache\Frontend\VariableFrontend::class, $backendObjectName, $backendOptions); - $manager->injectCacheFactory($factory); + $defaultCacheConfiguration = [ + 'frontend' => FrontendDefaultFixture::class, + 'options' => [], + 'groups' => [], + ]; + $manager->_set('defaultCacheConfiguration', $defaultCacheConfiguration); $manager->setCacheConfigurations($configuration); + $this->expectException(\RuntimeException::class); + $this->expectExceptionCode(1464555650); $manager->getCache($cacheIdentifier); } @@ -181,42 +281,82 @@ class CacheManagerTest extends \TYPO3\CMS\Core\Tests\UnitTestCase */ public function getCacheCreatesCacheInstanceWithFallbackToDefaultBackend() { - $manager = new \TYPO3\CMS\Core\Cache\CacheManager(); + /** @var \PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|CacheManager $manager */ + $manager = $this->getAccessibleMock(CacheManager::class, ['dummy'], [], '', false); $cacheIdentifier = $this->getUniqueId('Test'); - $cacheObjectName = 'testCache'; - $backendOptions = array('foo'); $configuration = array( $cacheIdentifier => array( - 'frontend' => $cacheObjectName, - 'options' => $backendOptions + 'frontend' => FrontendFixture::class, + 'options' => [] ) ); - $factory = $this->getMock(\TYPO3\CMS\Core\Cache\CacheFactory::class, array('create'), array(), '', false); - $factory->expects($this->once())->method('create')->with($cacheIdentifier, $cacheObjectName, \TYPO3\CMS\Core\Cache\Backend\Typo3DatabaseBackend::class, $backendOptions); - $manager->injectCacheFactory($factory); + $defaultCacheConfiguration = [ + 'backend' => BackendDefaultFixture::class, + 'options' => [], + 'groups' => [], + ]; + $manager->_set('defaultCacheConfiguration', $defaultCacheConfiguration); $manager->setCacheConfigurations($configuration); + $this->expectException(\RuntimeException::class); + $this->expectExceptionCode(1464556045); $manager->getCache($cacheIdentifier); } /** * @test */ - public function getCacheCreatesCacheInstanceWithFallbackToDefaultBackenOptions() + public function getCacheReturnsInstanceOfTheSpecifiedCacheFrontend() { - $manager = new \TYPO3\CMS\Core\Cache\CacheManager(); - $cacheIdentifier = $this->getUniqueId('Test'); - $cacheObjectName = 'testCache'; - $backendObjectName = 'testBackend'; - $configuration = array( - $cacheIdentifier => array( - 'frontend' => $cacheObjectName, - 'backend' => $backendObjectName - ) - ); - $factory = $this->getMock(\TYPO3\CMS\Core\Cache\CacheFactory::class, array('create'), array(), '', false); - $factory->expects($this->once())->method('create')->with($cacheIdentifier, $cacheObjectName, $backendObjectName, array()); - $manager->injectCacheFactory($factory); + $manager = new CacheManager(); + $cacheIdentifier = 'aCache'; + $configuration = [ + $cacheIdentifier => [ + 'backend' => BackendFixture::class, + 'frontend' => FrontendFixture::class, + 'options' => [], + ], + ]; + $manager->setCacheConfigurations($configuration); + $this->assertInstanceOf(FrontendFixture::class, $manager->getCache($cacheIdentifier)); + } + + /** + * @test + */ + public function getCacheGivesIdentifierToCacheFrontend() + { + $manager = new CacheManager(); + $cacheIdentifier = 'aCache'; + $configuration = [ + $cacheIdentifier => [ + 'backend' => BackendFixture::class, + 'frontend' => FrontendIdentifierFixture::class, + 'options' => [], + ], + ]; + $manager->setCacheConfigurations($configuration); + $this->expectException(\RuntimeException::class); + $this->expectExceptionCode(1464555650); + $manager->getCache($cacheIdentifier); + } + + /** + * @test + */ + public function getCacheGivesBackendInstanceToCacheFrontend() + { + $manager = new CacheManager(); + $cacheIdentifier = 'aCache'; + $configuration = [ + $cacheIdentifier => [ + 'backend' => BackendFixture::class, + 'frontend' => FrontendBackendInstanceFixture::class, + 'options' => [], + ], + ]; $manager->setCacheConfigurations($configuration); + $this->expectException(\RuntimeException::class); + $this->expectExceptionCode(1464557160); $manager->getCache($cacheIdentifier); } } diff --git a/typo3/sysext/core/Tests/Unit/Cache/Fixtures/BackendConfigurationOptionFixture.php b/typo3/sysext/core/Tests/Unit/Cache/Fixtures/BackendConfigurationOptionFixture.php new file mode 100644 index 0000000000000000000000000000000000000000..eb4e6e9db017c61e96477d2697734800b23d70f4 --- /dev/null +++ b/typo3/sysext/core/Tests/Unit/Cache/Fixtures/BackendConfigurationOptionFixture.php @@ -0,0 +1,39 @@ +<?php +namespace TYPO3\CMS\Core\Tests\Unit\Cache\Fixtures; + +/* + * This file is part of the TYPO3 CMS project. + * + * It is free software; you can redistribute it and/or modify it under + * the terms of the GNU General Public License, either version 2 + * of the License, or any later version. + * + * For the full copyright and license information, please read the + * LICENSE.txt file that was distributed with this source code. + * + * The TYPO3 project - inspiring people to share! + */ + +/** + * Backend fixture for CacheManager test getCacheCreatesBackendWithGivenConfiguration() + */ +class BackendConfigurationOptionFixture extends BackendFixture +{ + /** + * Test if constructor receives backend options + * + * @param string $context FLOW3's application context + * @param array $options Configuration options - depends on the actual backend + */ + public function __construct($context, array $options = array()) + { + $testOptions = [ + 'anOption' => 'anOptionValue', + ]; + if ($options === $testOptions) { + // expected exception thrown + throw new \RuntimeException('', 1464555007); + } + } + +} diff --git a/typo3/sysext/core/Tests/Unit/Cache/Fixtures/BackendDefaultFixture.php b/typo3/sysext/core/Tests/Unit/Cache/Fixtures/BackendDefaultFixture.php new file mode 100644 index 0000000000000000000000000000000000000000..b8ad73448ae10fe57171a9faede38840c911aa1d --- /dev/null +++ b/typo3/sysext/core/Tests/Unit/Cache/Fixtures/BackendDefaultFixture.php @@ -0,0 +1,26 @@ +<?php +namespace TYPO3\CMS\Core\Tests\Unit\Cache\Fixtures; + +/* +* This file is part of the TYPO3 CMS project. +* +* It is free software; you can redistribute it and/or modify it under +* the terms of the GNU General Public License, either version 2 +* of the License, or any later version. +* +* For the full copyright and license information, please read the +* LICENSE.txt file that was distributed with this source code. +* +* The TYPO3 project - inspiring people to share! +*/ + +/** +* Backend for cache manager test getCacheCreatesCacheInstanceWithFallbackToDefaultBackend +*/ +class BackendDefaultFixture extends BackendFixture +{ + public function __construct() + { + throw new \RuntimeException('', 1464556045); + } +} diff --git a/typo3/sysext/core/Tests/Unit/Cache/Fixtures/BackendFixture.php b/typo3/sysext/core/Tests/Unit/Cache/Fixtures/BackendFixture.php new file mode 100644 index 0000000000000000000000000000000000000000..2c5e3a81894e0f30d960ae4f7ea77ae577ea357a --- /dev/null +++ b/typo3/sysext/core/Tests/Unit/Cache/Fixtures/BackendFixture.php @@ -0,0 +1,52 @@ +<?php +namespace TYPO3\CMS\Core\Tests\Unit\Cache\Fixtures; + +/* + * This file is part of the TYPO3 CMS project. + * + * It is free software; you can redistribute it and/or modify it under + * the terms of the GNU General Public License, either version 2 + * of the License, or any later version. + * + * For the full copyright and license information, please read the + * LICENSE.txt file that was distributed with this source code. + * + * The TYPO3 project - inspiring people to share! + */ + +use TYPO3\CMS\Core\Cache\Backend\BackendInterface; +use TYPO3\CMS\Core\Cache\Frontend\FrontendInterface; + +/** + * Backend fixture to test cache manager. + */ +class BackendFixture implements BackendInterface +{ + public function setCache(FrontendInterface $cache) + { + } + + public function set($entryIdentifier, $data, array $tags = array(), $lifetime = null) + { + } + + public function get($entryIdentifier) + { + } + + public function has($entryIdentifier) + { + } + + public function remove($entryIdentifier) + { + } + + public function flush() + { + } + + public function collectGarbage() + { + } +} diff --git a/typo3/sysext/core/Tests/Unit/Cache/Fixtures/BackendInitializeObjectFixture.php b/typo3/sysext/core/Tests/Unit/Cache/Fixtures/BackendInitializeObjectFixture.php new file mode 100644 index 0000000000000000000000000000000000000000..638aea1ae9c0b16c6aa8a91d7b3b47c6a860007b --- /dev/null +++ b/typo3/sysext/core/Tests/Unit/Cache/Fixtures/BackendInitializeObjectFixture.php @@ -0,0 +1,26 @@ +<?php +namespace TYPO3\CMS\Core\Tests\Unit\Cache\Fixtures; + +/* + * This file is part of the TYPO3 CMS project. + * + * It is free software; you can redistribute it and/or modify it under + * the terms of the GNU General Public License, either version 2 + * of the License, or any later version. + * + * For the full copyright and license information, please read the + * LICENSE.txt file that was distributed with this source code. + * + * The TYPO3 project - inspiring people to share! + */ + +/** + * Fixture to test cache manager details + */ +class BackendInitializeObjectFixture extends BackendFixture +{ + public function initializeObject() + { + throw new \RuntimeException('', 1464552894); + } +} diff --git a/typo3/sysext/core/Tests/Unit/Cache/Fixtures/FrontendBackendInstanceFixture.php b/typo3/sysext/core/Tests/Unit/Cache/Fixtures/FrontendBackendInstanceFixture.php new file mode 100644 index 0000000000000000000000000000000000000000..99cc23bccf47e15f4305a8a816c81708e61bc6f4 --- /dev/null +++ b/typo3/sysext/core/Tests/Unit/Cache/Fixtures/FrontendBackendInstanceFixture.php @@ -0,0 +1,28 @@ +<?php +namespace TYPO3\CMS\Core\Tests\Unit\Cache\Fixtures; + +/* +* This file is part of the TYPO3 CMS project. +* +* It is free software; you can redistribute it and/or modify it under +* the terms of the GNU General Public License, either version 2 +* of the License, or any later version. +* +* For the full copyright and license information, please read the +* LICENSE.txt file that was distributed with this source code. +* +* The TYPO3 project - inspiring people to share! +*/ + +/** +* Frontend for cache manager test getCacheGivesBackendInstanceToCacheFrontend +*/ +class FrontendBackendInstanceFixture extends FrontendFixture +{ + public function __construct($_, $backend) + { + if ($backend instanceof BackendFixture) { + throw new \RuntimeException('', 1464557160); + } + } +} diff --git a/typo3/sysext/core/Tests/Unit/Cache/Fixtures/FrontendDefaultFixture.php b/typo3/sysext/core/Tests/Unit/Cache/Fixtures/FrontendDefaultFixture.php new file mode 100644 index 0000000000000000000000000000000000000000..3ed4f3994bce01bef2ec94dc417e753ec53052eb --- /dev/null +++ b/typo3/sysext/core/Tests/Unit/Cache/Fixtures/FrontendDefaultFixture.php @@ -0,0 +1,26 @@ +<?php +namespace TYPO3\CMS\Core\Tests\Unit\Cache\Fixtures; + +/* +* This file is part of the TYPO3 CMS project. +* +* It is free software; you can redistribute it and/or modify it under +* the terms of the GNU General Public License, either version 2 +* of the License, or any later version. +* +* For the full copyright and license information, please read the +* LICENSE.txt file that was distributed with this source code. +* +* The TYPO3 project - inspiring people to share! +*/ + +/** +* Frontend for cache manager test getCacheCreatesCacheInstanceWithFallbackToDefaultFrontend +*/ +class FrontendDefaultFixture extends FrontendFixture +{ + public function __construct() + { + throw new \RuntimeException('', 1464555650); + } +} diff --git a/typo3/sysext/core/Tests/Unit/Cache/Fixtures/FrontendFixture.php b/typo3/sysext/core/Tests/Unit/Cache/Fixtures/FrontendFixture.php new file mode 100644 index 0000000000000000000000000000000000000000..c661ab5f20bf21823b1360ad93513b94b74c9866 --- /dev/null +++ b/typo3/sysext/core/Tests/Unit/Cache/Fixtures/FrontendFixture.php @@ -0,0 +1,79 @@ +<?php +namespace TYPO3\CMS\Core\Tests\Unit\Cache\Fixtures; + +/* +* This file is part of the TYPO3 CMS project. +* +* It is free software; you can redistribute it and/or modify it under +* the terms of the GNU General Public License, either version 2 +* of the License, or any later version. +* +* For the full copyright and license information, please read the +* LICENSE.txt file that was distributed with this source code. +* +* The TYPO3 project - inspiring people to share! +*/ + +use TYPO3\CMS\Core\Cache\Frontend\FrontendInterface; + +/** +* Fixture implementing frontend +*/ +class FrontendFixture implements FrontendInterface +{ + protected $identifier; + + public function __construct($identifier) + { + $this->identifier = $identifier; + } + + public function getIdentifier() + { + return $this->identifier; + } + + public function getBackend() + { + } + + public function set($entryIdentifier, $data, array $tags = array(), $lifetime = null) + { + } + + public function get($entryIdentifier) + { + } + + public function getByTag($tag) + { + } + + public function has($entryIdentifier) + { + } + + public function remove($entryIdentifier) + { + } + + public function flush() + { + } + + public function flushByTag($tag) + { + } + + public function collectGarbage() + { + } + + public function isValidEntryIdentifier($identifier) + { + } + + public function isValidTag($tag) + { + } +} diff --git a/typo3/sysext/core/Tests/Unit/Cache/Fixtures/FrontendIdentifierFixture.php b/typo3/sysext/core/Tests/Unit/Cache/Fixtures/FrontendIdentifierFixture.php new file mode 100644 index 0000000000000000000000000000000000000000..da764ddc580eed402e812caaf3662ac68eaed908 --- /dev/null +++ b/typo3/sysext/core/Tests/Unit/Cache/Fixtures/FrontendIdentifierFixture.php @@ -0,0 +1,28 @@ +<?php +namespace TYPO3\CMS\Core\Tests\Unit\Cache\Fixtures; + +/* +* This file is part of the TYPO3 CMS project. +* +* It is free software; you can redistribute it and/or modify it under +* the terms of the GNU General Public License, either version 2 +* of the License, or any later version. +* +* For the full copyright and license information, please read the +* LICENSE.txt file that was distributed with this source code. +* +* The TYPO3 project - inspiring people to share! +*/ + +/** +* Frontend for cache manager test getCacheGivesIdentifierToCacheFrontend +*/ +class FrontendIdentifierFixture extends FrontendFixture +{ + public function __construct($identifier) + { + if ($identifier === 'aCache') { + throw new \RuntimeException('', 1464555650); + } + } +} diff --git a/typo3/sysext/core/Tests/Unit/Cache/Fixtures/FrontendInitializeObjectFixture.php b/typo3/sysext/core/Tests/Unit/Cache/Fixtures/FrontendInitializeObjectFixture.php new file mode 100644 index 0000000000000000000000000000000000000000..930aad127c43823b6ad5fcfe55a64ee641c5b3e9 --- /dev/null +++ b/typo3/sysext/core/Tests/Unit/Cache/Fixtures/FrontendInitializeObjectFixture.php @@ -0,0 +1,26 @@ +<?php +namespace TYPO3\CMS\Core\Tests\Unit\Cache\Fixtures; + +/* +* This file is part of the TYPO3 CMS project. +* +* It is free software; you can redistribute it and/or modify it under +* the terms of the GNU General Public License, either version 2 +* of the License, or any later version. +* +* For the full copyright and license information, please read the +* LICENSE.txt file that was distributed with this source code. +* +* The TYPO3 project - inspiring people to share! +*/ + +/** +* Fixture implementing frontend +*/ +class FrontendInitializeObjectFixture extends FrontendFixture +{ + public function initializeObject() + { + throw new \RuntimeException('', 1464553495); + } +} diff --git a/typo3/sysext/core/Tests/Unit/Cache/last_synched_revision b/typo3/sysext/core/Tests/Unit/Cache/last_synched_revision deleted file mode 100644 index a2449fd1784350059fc31349ba979cb134eb5764..0000000000000000000000000000000000000000 --- a/typo3/sysext/core/Tests/Unit/Cache/last_synched_revision +++ /dev/null @@ -1 +0,0 @@ -868e073b9877d562c6ed65a5158c1c67b3a501a8 \ No newline at end of file diff --git a/typo3/sysext/install/Classes/Service/ClearCacheService.php b/typo3/sysext/install/Classes/Service/ClearCacheService.php index 4513bfb3ee028dd9dbb7888c915a0ee3104e0f6a..7ce5f79fc4f18439c62cdbd193d34a5424fd36e9 100644 --- a/typo3/sysext/install/Classes/Service/ClearCacheService.php +++ b/typo3/sysext/install/Classes/Service/ClearCacheService.php @@ -84,9 +84,6 @@ class ClearCacheService // using new directly! $cacheManager = new \TYPO3\CMS\Core\Cache\CacheManager(); $cacheManager->setCacheConfigurations($GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']); - // Cache manager needs cache factory. cache factory injects itself to manager in __construct() - new \TYPO3\CMS\Core\Cache\CacheFactory('production', $cacheManager); - $cacheManager->flushCaches(); }