found)->toBeTrue(); expect($result->entry)->toBe($entry); expect($result->reason)->toBeNull(); expect($result->isUsable())->toBeTrue(); }); it('creates found result with staleness check', function () { $registry = new DiscoveryRegistry( attributes: new AttributeRegistry(), interfaces: new InterfaceRegistry(), templates: new TemplateRegistry() ); $entry = new CacheEntry( registry: $registry, createdAt: Timestamp::fromDateTime(new \DateTimeImmutable()), version: 'v1-abc12345', cacheLevel: CacheLevel::NORMAL, cacheTier: CacheTier::HOT ); $stalenessCheck = StalenessCheckResult::fresh(); $result = CacheRetrievalResult::found($entry, $stalenessCheck); expect($result->found)->toBeTrue(); expect($result->stalenessCheck)->toBe($stalenessCheck); expect($result->isUsable())->toBeTrue(); }); it('creates not found result', function () { $result = CacheRetrievalResult::notFound('not_found'); expect($result->found)->toBeFalse(); expect($result->entry)->toBeNull(); expect($result->reason)->toBe('not_found'); expect($result->isUsable())->toBeFalse(); }); it('creates stale result', function () { $registry = new DiscoveryRegistry( attributes: new AttributeRegistry(), interfaces: new InterfaceRegistry(), templates: new TemplateRegistry() ); $entry = new CacheEntry( registry: $registry, createdAt: Timestamp::fromDateTime(new \DateTimeImmutable()), version: 'v1-abc12345', cacheLevel: CacheLevel::NORMAL, cacheTier: CacheTier::HOT ); $stalenessCheck = StalenessCheckResult::stale('directory_modified'); $result = CacheRetrievalResult::stale($entry, $stalenessCheck); expect($result->found)->toBeTrue(); expect($result->entry)->toBe($entry); expect($result->reason)->toBe('stale'); expect($result->stalenessCheck)->toBe($stalenessCheck); expect($result->isUsable())->toBeFalse(); }); it('throws exception when found without entry', function () { expect(fn() => new CacheRetrievalResult( found: true, entry: null ))->toThrow(\InvalidArgumentException::class); }); it('throws exception when not found with entry', function () { $registry = new DiscoveryRegistry( attributes: new AttributeRegistry(), interfaces: new InterfaceRegistry(), templates: new TemplateRegistry() ); $entry = new CacheEntry( registry: $registry, createdAt: Timestamp::fromDateTime(new \DateTimeImmutable()), version: 'v1-abc12345', cacheLevel: CacheLevel::NORMAL, cacheTier: CacheTier::HOT ); expect(fn() => new CacheRetrievalResult( found: false, entry: $entry ))->toThrow(\InvalidArgumentException::class); }); });