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(); }); });