fix: DockerSecretsResolver - don't normalize absolute paths like /var/www/html/...
Some checks failed
Deploy Application / deploy (push) Has been cancelled
Some checks failed
Deploy Application / deploy (push) Has been cancelled
This commit is contained in:
@@ -0,0 +1,117 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Framework\Discovery\Storage\Services;
|
||||
|
||||
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\Discovery\Storage\Services\CacheEntrySerializer;
|
||||
use App\Framework\Core\ValueObjects\Timestamp;
|
||||
use App\Framework\Discovery\Storage\ValueObjects\CacheEntry;
|
||||
use App\Framework\Discovery\ValueObjects\CacheLevel;
|
||||
use App\Framework\Discovery\ValueObjects\CacheTier;
|
||||
|
||||
describe('CacheEntrySerializer', function () {
|
||||
beforeEach(function () {
|
||||
$this->serializer = new CacheEntrySerializer();
|
||||
});
|
||||
|
||||
it('serializes CacheEntry to array', function () {
|
||||
$registry = new DiscoveryRegistry(
|
||||
attributes: new AttributeRegistry(),
|
||||
interfaces: new InterfaceRegistry(),
|
||||
templates: new TemplateRegistry()
|
||||
);
|
||||
|
||||
$entry = new CacheEntry(
|
||||
registry: $registry,
|
||||
createdAt: Timestamp::fromDateTime(new \DateTimeImmutable('2024-01-01 12:00:00')),
|
||||
version: 'v1-abc12345',
|
||||
cacheLevel: CacheLevel::NORMAL,
|
||||
cacheTier: CacheTier::HOT
|
||||
);
|
||||
|
||||
$serialized = $this->serializer->serialize($entry);
|
||||
|
||||
expect($serialized)->toBeArray();
|
||||
// Registry should be serialized as string when explicitly serialized
|
||||
expect(is_string($serialized['registry']))->toBeTrue('Registry should be serialized as string');
|
||||
expect(isset($serialized['__registry_serialized__']))->toBeTrue('Should have serialization flag');
|
||||
expect($serialized['__registry_serialized__'])->toBeTrue('Serialization flag should be true');
|
||||
expect($serialized['version'])->toBe('v1-abc12345');
|
||||
});
|
||||
|
||||
it('deserializes DiscoveryRegistry (old format)', function () {
|
||||
$registry = new DiscoveryRegistry(
|
||||
attributes: new AttributeRegistry(),
|
||||
interfaces: new InterfaceRegistry(),
|
||||
templates: new TemplateRegistry()
|
||||
);
|
||||
|
||||
$entry = $this->serializer->deserialize($registry);
|
||||
|
||||
expect($entry)->toBeInstanceOf(CacheEntry::class);
|
||||
expect($entry->registry)->toBe($registry);
|
||||
expect($entry->isCompressed())->toBeFalse();
|
||||
});
|
||||
|
||||
it('deserializes array (new format)', function () {
|
||||
$registry = new DiscoveryRegistry(
|
||||
attributes: new AttributeRegistry(),
|
||||
interfaces: new InterfaceRegistry(),
|
||||
templates: new TemplateRegistry()
|
||||
);
|
||||
|
||||
$timestamp = Timestamp::fromDateTime(new \DateTimeImmutable('2024-01-01 12:00:00'));
|
||||
$data = [
|
||||
'registry' => $registry,
|
||||
'startTime' => $timestamp->toTimestamp(), // Serialize as int timestamp
|
||||
'version' => 'v1-abc12345',
|
||||
'cacheLevel' => CacheLevel::NORMAL->value,
|
||||
'cacheTier' => CacheTier::HOT->value,
|
||||
];
|
||||
|
||||
$entry = $this->serializer->deserialize($data);
|
||||
|
||||
expect($entry)->toBeInstanceOf(CacheEntry::class);
|
||||
expect($entry->registry)->toBe($registry);
|
||||
expect($entry->version)->toBe('v1-abc12345');
|
||||
});
|
||||
|
||||
it('supports DiscoveryRegistry format', function () {
|
||||
$registry = new DiscoveryRegistry(
|
||||
attributes: new AttributeRegistry(),
|
||||
interfaces: new InterfaceRegistry(),
|
||||
templates: new TemplateRegistry()
|
||||
);
|
||||
|
||||
expect($this->serializer->supports($registry))->toBeTrue();
|
||||
});
|
||||
|
||||
it('supports array format', function () {
|
||||
$data = [
|
||||
'registry' => new DiscoveryRegistry(
|
||||
attributes: new AttributeRegistry(),
|
||||
interfaces: new InterfaceRegistry(),
|
||||
templates: new TemplateRegistry()
|
||||
),
|
||||
];
|
||||
|
||||
expect($this->serializer->supports($data))->toBeTrue();
|
||||
});
|
||||
|
||||
it('does not support invalid format', function () {
|
||||
expect($this->serializer->supports('invalid'))->toBeFalse();
|
||||
expect($this->serializer->supports(123))->toBeFalse();
|
||||
expect($this->serializer->supports(null))->toBeFalse();
|
||||
});
|
||||
|
||||
it('throws exception when deserializing unsupported format', function () {
|
||||
expect(fn() => $this->serializer->deserialize('invalid'))
|
||||
->toThrow(\InvalidArgumentException::class);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user