‪TYPO3CMS  ‪main
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\Attributes\Test;
21 use PHPUnit\Framework\MockObject\MockObject;
26 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
27 
28 final class ‪CacheServiceTest extends UnitTestCase
29 {
32 
33  protected function ‪setUp(): void
34  {
35  parent::setUp();
36  $configurationManager = $this->createMock(ConfigurationManagerInterface::class);
37  $configurationManager->method('getConfiguration')->with(‪ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK)->willReturn([]);
38  $this->cacheManagerMock = $this->createMock(CacheManager::class);
39  $this->subject = new ‪CacheService($configurationManager, $this->cacheManagerMock, $this->createMock(ConnectionPool::class));
40  }
41 
42  #[Test]
44  {
45  $this->cacheManagerMock->expects(self::once())->method('flushCachesInGroupByTags')->with('pages', ['pageId_123']);
46  $this->subject->clearPageCache(123);
47  }
48 
49  #[Test]
51  {
52  $this->cacheManagerMock->expects(self::once())->method('flushCachesInGroupByTags')->with('pages', ['pageId_0']);
53  $this->subject->clearPageCache('Foo');
54  }
55 
56  #[Test]
58  {
59  $this->cacheManagerMock->expects(self::once())->method('flushCachesInGroup')->with('pages');
60  $this->subject->clearPageCache();
61  }
62 
63  #[Test]
65  {
66  $this->cacheManagerMock->expects(self::once())->method('flushCachesInGroupByTags')->with('pages', ['pageId_1', 'pageId_2', 'pageId_3']);
67  $this->subject->clearPageCache([1, 2, 3]);
68  }
69 
70  #[Test]
71  public function ‪clearsCachesOfRegisteredPageIds(): void
72  {
73  $this->cacheManagerMock->expects(self::once())->method('flushCachesInGroupByTags')->with('pages', ['pageId_2', 'pageId_15', 'pageId_8']);
74 
75  $this->subject->getPageIdStack()->push(8);
76  $this->subject->getPageIdStack()->push(15);
77  $this->subject->getPageIdStack()->push(2);
78 
79  $this->subject->clearCachesOfRegisteredPageIds();
80  }
81 
82  #[Test]
84  {
85  $this->cacheManagerMock->expects(self::once())->method('flushCachesInGroupByTags')->with('pages', ['pageId_2', 'pageId_15', 'pageId_8']);
86 
87  $this->subject->getPageIdStack()->push(8);
88  $this->subject->getPageIdStack()->push(15);
89  $this->subject->getPageIdStack()->push(15);
90  $this->subject->getPageIdStack()->push(2);
91  $this->subject->getPageIdStack()->push(2);
92 
93  $this->subject->clearCachesOfRegisteredPageIds();
94  }
95 }
‪TYPO3\CMS\Extbase\Tests\Unit\Service
Definition: CacheServiceTest.php:18
‪TYPO3\CMS\Extbase\Tests\Unit\Service\CacheServiceTest\clearPageCacheConvertsPageIdsToArray
‪clearPageCacheConvertsPageIdsToArray()
Definition: CacheServiceTest.php:43
‪TYPO3\CMS\Extbase\Tests\Unit\Service\CacheServiceTest\$cacheManagerMock
‪CacheManager &MockObject $cacheManagerMock
Definition: CacheServiceTest.php:31
‪TYPO3\CMS\Extbase\Tests\Unit\Service\CacheServiceTest\clearPageCacheDoesNotConvertPageIdsIfNoneAreSpecified
‪clearPageCacheDoesNotConvertPageIdsIfNoneAreSpecified()
Definition: CacheServiceTest.php:57
‪TYPO3\CMS\Extbase\Tests\Unit\Service\CacheServiceTest\$subject
‪CacheService $subject
Definition: CacheServiceTest.php:30
‪TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface
Definition: ConfigurationManagerInterface.php:28
‪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:29
‪TYPO3\CMS\Extbase\Tests\Unit\Service\CacheServiceTest\clearPageCacheUsesCacheManagerToFlushCacheOfSpecifiedPages
‪clearPageCacheUsesCacheManagerToFlushCacheOfSpecifiedPages()
Definition: CacheServiceTest.php:64
‪TYPO3\CMS\Extbase\Tests\Unit\Service\CacheServiceTest\clearsCachesOfDuplicateRegisteredPageIdsOnlyOnce
‪clearsCachesOfDuplicateRegisteredPageIdsOnlyOnce()
Definition: CacheServiceTest.php:83
‪TYPO3\CMS\Core\Cache\CacheManager
Definition: CacheManager.php:36
‪TYPO3\CMS\Extbase\Tests\Unit\Service\CacheServiceTest\setUp
‪setUp()
Definition: CacheServiceTest.php:33
‪TYPO3\CMS\Extbase\Tests\Unit\Service\CacheServiceTest\clearPageCacheConvertsPageIdsToNumericArray
‪clearPageCacheConvertsPageIdsToNumericArray()
Definition: CacheServiceTest.php:50
‪TYPO3\CMS\Extbase\Service\CacheService
Definition: CacheService.php:34
‪TYPO3\CMS\Core\Database\ConnectionPool
Definition: ConnectionPool.php:46
‪TYPO3\CMS\Extbase\Tests\Unit\Service\CacheServiceTest\clearsCachesOfRegisteredPageIds
‪clearsCachesOfRegisteredPageIds()
Definition: CacheServiceTest.php:71