cacheFactory = $this->createMock(CacheItemPoolFactory::class); $this->logger = $this->createMock(Logger::class); $this->cache = $this->createMock(CacheItemPoolInterface::class); $this->subject = new GcpTokenCacheItemPool( [ GcpTokenCacheItemPool::OPTION_TOKEN_CACHE_KEY => self::TOKEN_CACHE_KEY, GcpTokenCacheItemPool::OPTION_DISABLE_WRITE => false, GcpTokenCacheItemPool::OPTION_PERSISTENCE => 'redis', ] ); $this->subject->setLogger($this->logger); $this->subject->setServiceLocator( $this->getServiceLocatorMock( [ CacheItemPoolFactory::class => $this->cacheFactory, ] ) ); $this->cacheFactory ->expects($this->once()) ->method('create') ->willReturn($this->cache); } public function testGetItem(): void { $cacheItem = $this->createCacheItem(); $this->cache ->expects($this->once()) ->method('getItem') ->with(self::TOKEN_CACHE_KEY) ->willReturn($cacheItem); $result = $this->subject->getItem('key'); $this->assertInstanceOf(CacheItem::class, $result); } public function testGetItems(): void { $cacheItem = $this->createCacheItem(); $this->cache ->expects($this->once()) ->method('getItems') ->with([self::TOKEN_CACHE_KEY]) ->willReturn([$cacheItem]); $result = $this->subject->getItems(['key']); $this->assertIsArray($result); $this->assertInstanceOf(CacheItem::class, $result[0]); } public function testHasItem(): void { $this->cache ->expects($this->once()) ->method('hasItem') ->with(self::TOKEN_CACHE_KEY) ->willReturn(true); $this->assertTrue($this->subject->hasItem('key')); } public function testClear(): void { $this->cache ->expects($this->once()) ->method('clear') ->willReturn(true); $this->assertTrue($this->subject->clear()); } public function testDeleteItem(): void { $this->cache ->expects($this->once()) ->method('deleteItem') ->with(self::TOKEN_CACHE_KEY) ->willReturn(true); $this->assertTrue($this->subject->deleteItem('key')); } public function testDeleteItems(): void { $this->cache ->expects($this->once()) ->method('deleteItems') ->with([self::TOKEN_CACHE_KEY]) ->willReturn(true); $this->assertTrue($this->subject->deleteItems(['key1'])); } public function testSave(): void { $cacheItem = $this->createCacheItem(); $this->cache ->expects($this->once()) ->method('save') ->with($cacheItem) ->willReturn(true); $this->assertTrue($this->subject->save($cacheItem)); } public function testSaveDeferred(): void { $cacheItem = $this->createCacheItem(); $this->cache ->expects($this->once()) ->method('saveDeferred') ->with($cacheItem) ->willReturn(true); $this->assertTrue($this->subject->saveDeferred($cacheItem)); } public function testCommit(): void { $this->cache ->expects($this->once()) ->method('commit') ->willReturn(true); $this->assertTrue($this->subject->commit()); } private function createCacheItem(): CacheItemInterface { return new CacheItem(self::TOKEN_CACHE_KEY); } }