Some checks failed
Deploy Application / deploy (push) Has been cancelled
128 lines
4.5 KiB
PHP
128 lines
4.5 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Tests\Framework\Discovery\Storage\ValueObjects;
|
|
|
|
use App\Framework\Discovery\Results\DiscoveryRegistry;
|
|
use App\Framework\Discovery\Results\AttributeRegistry;
|
|
use App\Framework\Discovery\Results\InterfaceRegistry;
|
|
use App\Framework\Discovery\Results\TemplateRegistry;
|
|
use App\Framework\Core\ValueObjects\Timestamp;
|
|
use App\Framework\Discovery\Storage\ValueObjects\CacheEntry;
|
|
use App\Framework\Discovery\Storage\ValueObjects\CacheRetrievalResult;
|
|
use App\Framework\Discovery\Storage\ValueObjects\StalenessCheckResult;
|
|
use App\Framework\Discovery\ValueObjects\CacheLevel;
|
|
use App\Framework\Discovery\ValueObjects\CacheTier;
|
|
|
|
describe('CacheRetrievalResult', function () {
|
|
it('creates found 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
|
|
);
|
|
|
|
$result = CacheRetrievalResult::found($entry);
|
|
|
|
expect($result->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);
|
|
});
|
|
});
|
|
|