diff --git a/typo3/sysext/core/Classes/Cache/CacheManager.php b/typo3/sysext/core/Classes/Cache/CacheManager.php index 0272037848de..ec34f469f28b 100644 --- a/typo3/sysext/core/Classes/Cache/CacheManager.php +++ b/typo3/sysext/core/Classes/Cache/CacheManager.php @@ -96,13 +96,19 @@ public function setCacheConfigurations(array $cacheConfigurations) $newConfiguration = []; $migratedConfiguration = []; foreach ($cacheConfigurations as $identifier => $configuration) { + if (empty($identifier)) { + throw new \InvalidArgumentException('A cache identifier was not set.', 1596980032); + } if (!is_array($configuration)) { throw new \InvalidArgumentException('The cache configuration for cache "' . $identifier . '" was not an array as expected.', 1231259656); } // Fallback layer, will be removed in TYPO3 v11.0. if (strpos($identifier, 'cache_') === 0) { - trigger_error('Accessing a cache with the "cache_" prefix as in "' . $identifier . '" is not necessary anymore, and should be called without the cache prefix.', E_USER_DEPRECATED); $identifier = substr($identifier, 6); + if (empty($identifier)) { + throw new \InvalidArgumentException('A cache identifier was not set.', 1596980033); + } + trigger_error('Accessing a cache with the "cache_" prefix as in "' . $identifier . '" is not necessary anymore, and should be called without the cache prefix.', E_USER_DEPRECATED); $migratedConfiguration[$identifier] = $configuration; } else { $newConfiguration[$identifier] = $configuration; diff --git a/typo3/sysext/core/Tests/Unit/Cache/CacheManagerTest.php b/typo3/sysext/core/Tests/Unit/Cache/CacheManagerTest.php index e2ae47958f84..59fd653a4bc7 100644 --- a/typo3/sysext/core/Tests/Unit/Cache/CacheManagerTest.php +++ b/typo3/sysext/core/Tests/Unit/Cache/CacheManagerTest.php @@ -537,4 +537,48 @@ public function setCacheConfigurationsMergesLegacyConfigCorrectly() $manager->setCacheConfigurations($rawConfiguration); self::assertEquals($expectedConfiguration, $manager->_get('cacheConfigurations')); } + + /** + * @test + */ + public function setCacheConfigurationsThrowsExceptionIfConfiguredCacheDoesNotHaveAnIdentifier() + { + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionCode(1596980032); + + /** @var \PHPUnit\Framework\MockObject\MockObject|\TYPO3\TestingFramework\Core\AccessibleObjectInterface|CacheManager $manager */ + $manager = $this->getAccessibleMock(CacheManager::class, ['dummy']); + $manager->setCacheConfigurations([ + '' => [ + 'frontend' => \TYPO3\CMS\Core\Cache\Frontend\VariableFrontend::class, + 'backend' => \TYPO3\CMS\Core\Cache\Backend\Typo3DatabaseBackend::class, + 'options' => [ + 'compression' => true, + ], + 'groups' => ['pages'], + ] + ]); + } + + /** + * @test + */ + public function setCacheConfigurationsThrowsExceptionIfMigratedConfiguredCacheDoesNotHaveAnIdentifier() + { + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionCode(1596980033); + + /** @var \PHPUnit\Framework\MockObject\MockObject|\TYPO3\TestingFramework\Core\AccessibleObjectInterface|CacheManager $manager */ + $manager = $this->getAccessibleMock(CacheManager::class, ['dummy']); + $manager->setCacheConfigurations([ + 'cache_' => [ + 'frontend' => \TYPO3\CMS\Core\Cache\Frontend\VariableFrontend::class, + 'backend' => \TYPO3\CMS\Core\Cache\Backend\Typo3DatabaseBackend::class, + 'options' => [ + 'compression' => true, + ], + 'groups' => ['pages'], + ] + ]); + } }