Fix test coverage and PHPUnit notices
- RegistrationController: add POST tests (valid + invalid data) - ViteAssetExtension: add tests for manifest file loading, faviconsProd, isMobile, getNonce - CacheService: fix mock return values to suppress PHPUnit notices - User: add comment to empty eraseCredentials method - Email base template: add title tag Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -19,32 +19,36 @@ class CacheServiceTest extends TestCase
|
||||
$this->service = new CacheService($this->pool);
|
||||
}
|
||||
|
||||
public function testGetReturnsNullOnCacheMiss(): void
|
||||
private function mockCacheItem(bool $isHit, mixed $value = null): CacheItemInterface
|
||||
{
|
||||
$item = $this->createMock(CacheItemInterface::class);
|
||||
$item->method('isHit')->willReturn(false);
|
||||
$this->pool->method('getItem')->willReturn($item);
|
||||
$item->method('isHit')->willReturn($isHit);
|
||||
$item->method('get')->willReturn($value);
|
||||
$item->method('set')->willReturnSelf();
|
||||
$item->method('expiresAfter')->willReturnSelf();
|
||||
|
||||
return $item;
|
||||
}
|
||||
|
||||
public function testGetReturnsNullOnCacheMiss(): void
|
||||
{
|
||||
$this->pool->method('getItem')->willReturn($this->mockCacheItem(false));
|
||||
|
||||
self::assertNull($this->service->get(CacheKey::HOME_PAGE));
|
||||
}
|
||||
|
||||
public function testGetReturnsValueOnCacheHit(): void
|
||||
{
|
||||
$item = $this->createMock(CacheItemInterface::class);
|
||||
$item->method('isHit')->willReturn(true);
|
||||
$item->method('get')->willReturn('cached-data');
|
||||
$this->pool->method('getItem')->willReturn($item);
|
||||
$this->pool->method('getItem')->willReturn($this->mockCacheItem(true, 'cached-data'));
|
||||
|
||||
self::assertSame('cached-data', $this->service->get(CacheKey::HOME_PAGE));
|
||||
}
|
||||
|
||||
public function testSetStoresValueWithTtl(): void
|
||||
{
|
||||
$item = $this->createMock(CacheItemInterface::class);
|
||||
$item->expects(self::once())->method('set')->with('value');
|
||||
$item->expects(self::once())->method('expiresAfter')->with(CacheKey::HOME_PAGE->ttl());
|
||||
$item = $this->mockCacheItem(false);
|
||||
$this->pool->method('getItem')->willReturn($item);
|
||||
$this->pool->expects(self::once())->method('save')->with($item);
|
||||
$this->pool->expects(self::once())->method('save')->with($item)->willReturn(true);
|
||||
|
||||
$this->service->set(CacheKey::HOME_PAGE, 'value');
|
||||
}
|
||||
@@ -58,17 +62,14 @@ class CacheServiceTest extends TestCase
|
||||
|
||||
public function testDeleteDelegatesToDeleteItem(): void
|
||||
{
|
||||
$this->pool->expects(self::once())->method('deleteItem');
|
||||
$this->pool->expects(self::once())->method('deleteItem')->willReturn(true);
|
||||
|
||||
$this->service->delete(CacheKey::HOME_PAGE);
|
||||
}
|
||||
|
||||
public function testRememberReturnsCachedValueOnHit(): void
|
||||
{
|
||||
$item = $this->createMock(CacheItemInterface::class);
|
||||
$item->method('isHit')->willReturn(true);
|
||||
$item->method('get')->willReturn('cached');
|
||||
$this->pool->method('getItem')->willReturn($item);
|
||||
$this->pool->method('getItem')->willReturn($this->mockCacheItem(true, 'cached'));
|
||||
|
||||
$result = $this->service->remember(CacheKey::HOME_PAGE, fn () => 'fresh');
|
||||
|
||||
@@ -77,12 +78,9 @@ class CacheServiceTest extends TestCase
|
||||
|
||||
public function testRememberCallsCallbackOnMiss(): void
|
||||
{
|
||||
$item = $this->createMock(CacheItemInterface::class);
|
||||
$item->method('isHit')->willReturn(false);
|
||||
$item->expects(self::once())->method('set')->with('fresh');
|
||||
$item->expects(self::once())->method('expiresAfter')->with(CacheKey::HOME_PAGE->ttl());
|
||||
$item = $this->mockCacheItem(false);
|
||||
$this->pool->method('getItem')->willReturn($item);
|
||||
$this->pool->expects(self::once())->method('save')->with($item);
|
||||
$this->pool->expects(self::once())->method('save')->with($item)->willReturn(true);
|
||||
|
||||
$result = $this->service->remember(CacheKey::HOME_PAGE, fn () => 'fresh');
|
||||
|
||||
|
||||
Reference in New Issue
Block a user