- Add tests for Results registries (AttributeRegistry, InterfaceRegistry, TemplateRegistry) - Add tests for Processing components (ProcessingContext) - Add tests for Memory components (MemoryGuard) - Add tests for Value Objects (DiscoveryOptions, DiscoveryContext) All new tests pass and cover core functionality including: - Registry operations (add, get, has, serialize/deserialize, optimize) - Processing context (reflection caching, file context management) - Memory guard (memory checks, statistics, emergency cleanup) - Value objects (factory methods, scan types, cache keys, metrics)
144 lines
3.8 KiB
PHP
144 lines
3.8 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Tests\Framework\Discovery\Results;
|
|
|
|
use App\Framework\Discovery\Results\TemplateRegistry;
|
|
use App\Framework\Discovery\ValueObjects\TemplateMapping;
|
|
|
|
describe('TemplateRegistry', function () {
|
|
beforeEach(function () {
|
|
$this->registry = new TemplateRegistry();
|
|
});
|
|
|
|
it('can be instantiated', function () {
|
|
expect($this->registry)->toBeInstanceOf(TemplateRegistry::class);
|
|
});
|
|
|
|
it('starts empty', function () {
|
|
expect(count($this->registry))->toBe(0);
|
|
});
|
|
|
|
it('can add template mappings', function () {
|
|
$mapping = TemplateMapping::create(
|
|
name: 'template',
|
|
path: 'test/template.html',
|
|
type: 'view'
|
|
);
|
|
|
|
$this->registry->add($mapping);
|
|
|
|
expect(count($this->registry))->toBe(1);
|
|
});
|
|
|
|
it('can retrieve template by name', function () {
|
|
$mapping = TemplateMapping::create(
|
|
name: 'template',
|
|
path: 'test/template.html',
|
|
type: 'view'
|
|
);
|
|
|
|
$this->registry->add($mapping);
|
|
|
|
$found = $this->registry->get('template');
|
|
|
|
expect($found)->not->toBeNull();
|
|
expect($found)->toBeInstanceOf(TemplateMapping::class);
|
|
expect($found->name)->toBe('template');
|
|
expect($found->path->toString())->toBe('test/template.html');
|
|
});
|
|
|
|
it('returns null for non-existent template name', function () {
|
|
$found = $this->registry->get('non-existent');
|
|
|
|
expect($found)->toBeNull();
|
|
});
|
|
|
|
it('can check if template name exists', function () {
|
|
$mapping = TemplateMapping::create(
|
|
name: 'template',
|
|
path: 'test/template.html',
|
|
type: 'view'
|
|
);
|
|
|
|
expect($this->registry->has('template'))->toBeFalse();
|
|
|
|
$this->registry->add($mapping);
|
|
|
|
expect($this->registry->has('template'))->toBeTrue();
|
|
});
|
|
|
|
it('can get all templates', function () {
|
|
$mapping1 = TemplateMapping::create(
|
|
name: 'template1',
|
|
path: 'test/template1.html',
|
|
type: 'view'
|
|
);
|
|
|
|
$mapping2 = TemplateMapping::create(
|
|
name: 'template2',
|
|
path: 'test/template2.html',
|
|
type: 'view'
|
|
);
|
|
|
|
$this->registry->add($mapping1);
|
|
$this->registry->add($mapping2);
|
|
|
|
$all = $this->registry->getAll();
|
|
|
|
expect($all)->toBeArray();
|
|
expect(count($all))->toBe(2);
|
|
});
|
|
|
|
it('can serialize and deserialize', function () {
|
|
$mapping = TemplateMapping::create(
|
|
name: 'template',
|
|
path: 'test/template.html',
|
|
type: 'view'
|
|
);
|
|
|
|
$this->registry->add($mapping);
|
|
|
|
$array = $this->registry->toArray();
|
|
expect($array)->toBeArray();
|
|
|
|
$restored = TemplateRegistry::fromArray($array);
|
|
expect($restored)->toBeInstanceOf(TemplateRegistry::class);
|
|
expect(count($restored))->toBe(1);
|
|
expect($restored->has('template'))->toBeTrue();
|
|
});
|
|
|
|
it('can optimize for memory', function () {
|
|
$mapping = TemplateMapping::create(
|
|
name: 'template',
|
|
path: 'test/template.html',
|
|
type: 'view'
|
|
);
|
|
|
|
$this->registry->add($mapping);
|
|
|
|
$this->registry->optimize();
|
|
|
|
// Should still contain the data after optimization
|
|
expect($this->registry->has('template'))->toBeTrue();
|
|
});
|
|
|
|
it('can clear cache', function () {
|
|
$mapping = TemplateMapping::create(
|
|
name: 'template',
|
|
path: 'test/template.html',
|
|
type: 'view'
|
|
);
|
|
|
|
$this->registry->add($mapping);
|
|
expect($this->registry->has('template'))->toBeTrue();
|
|
|
|
$this->registry->clearCache();
|
|
|
|
// Cache clearing shouldn't remove the data
|
|
expect($this->registry->has('template'))->toBeTrue();
|
|
});
|
|
});
|
|
|