‪TYPO3CMS  11.5
CacheServiceTest.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
20 use PHPUnit\Framework\MockObject\MockObject;
21 use Prophecy\PhpUnit\ProphecyTrait;
25 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
26 
30 class ‪CacheServiceTest extends UnitTestCase
31 {
32  use ProphecyTrait;
33 
34  protected ?‪CacheService ‪$cacheService = null;
35 
40 
41  protected function ‪setUp(): void
42  {
43  parent::setUp();
44  $configurationManager = $this->prophesize(ConfigurationManagerInterface::class);
45  $configurationManager->getConfiguration(‪ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK)->willReturn([]);
46  $this->cacheManagerMock = $this->createMock(CacheManager::class);
47  $this->cacheService = new ‪CacheService($configurationManager->reveal(), $this->cacheManagerMock);
48  }
49 
53  public function ‪clearPageCacheConvertsPageIdsToArray(): void
54  {
55  $this->cacheManagerMock->expects(self::once())->method('flushCachesInGroupByTags')->with('pages', ['pageId_123']);
56  $this->cacheService->clearPageCache(123);
57  }
58 
63  {
64  $this->cacheManagerMock->expects(self::once())->method('flushCachesInGroupByTags')->with('pages', ['pageId_0']);
65  $this->cacheService->clearPageCache('Foo');
66  }
67 
72  {
73  $this->cacheManagerMock->expects(self::once())->method('flushCachesInGroup')->with('pages');
74  $this->cacheService->clearPageCache();
75  }
76 
81  {
82  $this->cacheManagerMock->expects(self::once())->method('flushCachesInGroupByTags')->with('pages', ['pageId_1', 'pageId_2', 'pageId_3']);
83  $this->cacheService->clearPageCache([1, 2, 3]);
84  }
85 
89  public function ‪clearsCachesOfRegisteredPageIds(): void
90  {
91  $this->cacheManagerMock->expects(self::once())->method('flushCachesInGroupByTags')->with('pages', ['pageId_2', 'pageId_15', 'pageId_8']);
92 
93  $this->cacheService->getPageIdStack()->push(8);
94  $this->cacheService->getPageIdStack()->push(15);
95  $this->cacheService->getPageIdStack()->push(2);
96 
97  $this->cacheService->clearCachesOfRegisteredPageIds();
98  }
99 
104  {
105  $this->cacheManagerMock->expects(self::once())->method('flushCachesInGroupByTags')->with('pages', ['pageId_2', 'pageId_15', 'pageId_8']);
106 
107  $this->cacheService->getPageIdStack()->push(8);
108  $this->cacheService->getPageIdStack()->push(15);
109  $this->cacheService->getPageIdStack()->push(15);
110  $this->cacheService->getPageIdStack()->push(2);
111  $this->cacheService->getPageIdStack()->push(2);
112 
113  $this->cacheService->clearCachesOfRegisteredPageIds();
114  }
115 }
‪TYPO3\CMS\Extbase\Tests\Unit\Service
Definition: CacheServiceTest.php:18
‪TYPO3\CMS\Extbase\Tests\Unit\Service\CacheServiceTest\clearPageCacheConvertsPageIdsToArray
‪clearPageCacheConvertsPageIdsToArray()
Definition: CacheServiceTest.php:51
‪TYPO3\CMS\Extbase\Tests\Unit\Service\CacheServiceTest\clearPageCacheDoesNotConvertPageIdsIfNoneAreSpecified
‪clearPageCacheDoesNotConvertPageIdsIfNoneAreSpecified()
Definition: CacheServiceTest.php:69
‪TYPO3\CMS\Extbase\Tests\Unit\Service\CacheServiceTest\$cacheManagerMock
‪CacheManager MockObject $cacheManagerMock
Definition: CacheServiceTest.php:37
‪TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface
Definition: ConfigurationManagerInterface.php:28
‪TYPO3\CMS\Extbase\Tests\Unit\Service\CacheServiceTest\$cacheService
‪CacheService $cacheService
Definition: CacheServiceTest.php:33
‪TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface\CONFIGURATION_TYPE_FRAMEWORK
‪const CONFIGURATION_TYPE_FRAMEWORK
Definition: ConfigurationManagerInterface.php:29
‪TYPO3\CMS\Extbase\Tests\Unit\Service\CacheServiceTest
Definition: CacheServiceTest.php:31
‪TYPO3\CMS\Extbase\Tests\Unit\Service\CacheServiceTest\clearPageCacheUsesCacheManagerToFlushCacheOfSpecifiedPages
‪clearPageCacheUsesCacheManagerToFlushCacheOfSpecifiedPages()
Definition: CacheServiceTest.php:78
‪TYPO3\CMS\Extbase\Tests\Unit\Service\CacheServiceTest\clearsCachesOfDuplicateRegisteredPageIdsOnlyOnce
‪clearsCachesOfDuplicateRegisteredPageIdsOnlyOnce()
Definition: CacheServiceTest.php:101
‪TYPO3\CMS\Core\Cache\CacheManager
Definition: CacheManager.php:36
‪TYPO3\CMS\Extbase\Tests\Unit\Service\CacheServiceTest\setUp
‪setUp()
Definition: CacheServiceTest.php:39
‪TYPO3\CMS\Extbase\Tests\Unit\Service\CacheServiceTest\clearPageCacheConvertsPageIdsToNumericArray
‪clearPageCacheConvertsPageIdsToNumericArray()
Definition: CacheServiceTest.php:60
‪TYPO3\CMS\Extbase\Service\CacheService
Definition: CacheService.php:35
‪TYPO3\CMS\Extbase\Tests\Unit\Service\CacheServiceTest\clearsCachesOfRegisteredPageIds
‪clearsCachesOfRegisteredPageIds()
Definition: CacheServiceTest.php:87