registry = new InterfaceRegistry(); }); it('can be instantiated', function () { expect($this->registry)->toBeInstanceOf(InterfaceRegistry::class); }); it('starts empty', function () { expect(count($this->registry))->toBe(0); }); it('can add interface mappings', function () { $mapping = InterfaceMapping::create( interface: 'Test\\MyInterface', implementation: 'Test\\MyClass', file: '/path/to/MyClass.php' ); $this->registry->add($mapping); expect(count($this->registry))->toBe(1); }); it('can retrieve implementations for an interface', function () { $interface = ClassName::create('Test\\MyInterface'); $mapping1 = InterfaceMapping::create( interface: 'Test\\MyInterface', implementation: 'Test\\MyClass1', file: '/path/to/MyClass1.php' ); $mapping2 = InterfaceMapping::create( interface: 'Test\\MyInterface', implementation: 'Test\\MyClass2', file: '/path/to/MyClass2.php' ); $this->registry->add($mapping1); $this->registry->add($mapping2); $implementations = $this->registry->get($interface->getFullyQualified()); expect($implementations)->toBeArray(); expect(count($implementations))->toBe(2); expect($implementations[0])->toBeInstanceOf(ClassName::class); expect($implementations[1])->toBeInstanceOf(ClassName::class); }); it('returns empty array for non-existent interface', function () { $interface = ClassName::create('Test\\NonExistentInterface'); $implementations = $this->registry->get($interface->getFullyQualified()); expect($implementations)->toBeArray(); expect(count($implementations))->toBe(0); }); it('can check if interface has implementations', function () { $interface = ClassName::create('Test\\MyInterface'); expect($this->registry->has($interface->getFullyQualified()))->toBeFalse(); $mapping = InterfaceMapping::create( interface: 'Test\\MyInterface', implementation: 'Test\\MyClass', file: '/path/to/MyClass.php' ); $this->registry->add($mapping); expect($this->registry->has($interface->getFullyQualified()))->toBeTrue(); }); it('can get all mappings', function () { $mapping1 = InterfaceMapping::create( interface: 'Test\\Interface1', implementation: 'Test\\Class1', file: '/path/to/Class1.php' ); $mapping2 = InterfaceMapping::create( interface: 'Test\\Interface2', implementation: 'Test\\Class2', file: '/path/to/Class2.php' ); $this->registry->add($mapping1); $this->registry->add($mapping2); $all = $this->registry->getAllMappings(); expect($all)->toBeArray(); expect(count($all))->toBe(2); }); it('can serialize and deserialize', function () { $interface = ClassName::create('Test\\MyInterface'); $mapping = InterfaceMapping::create( interface: 'Test\\MyInterface', implementation: 'Test\\MyClass', file: '/path/to/MyClass.php' ); $this->registry->add($mapping); $array = $this->registry->toArray(); expect($array)->toBeArray(); $restored = InterfaceRegistry::fromArray($array); expect($restored)->toBeInstanceOf(InterfaceRegistry::class); expect(count($restored))->toBe(1); expect($restored->has($interface->getFullyQualified()))->toBeTrue(); }); it('can optimize for memory', function () { $interface = ClassName::create('Test\\MyInterface'); $mapping = InterfaceMapping::create( interface: 'Test\\MyInterface', implementation: 'Test\\MyClass', file: '/path/to/MyClass.php' ); $this->registry->add($mapping); $this->registry->optimize(); // Should still contain the data after optimization expect($this->registry->has($interface->getFullyQualified()))->toBeTrue(); }); it('can clear cache', function () { $interface = ClassName::create('Test\\MyInterface'); $mapping = InterfaceMapping::create( interface: 'Test\\MyInterface', implementation: 'Test\\MyClass', file: '/path/to/MyClass.php' ); $this->registry->add($mapping); expect($this->registry->has($interface->getFullyQualified()))->toBeTrue(); $this->registry->clearCache(); // Cache clearing shouldn't remove the data expect($this->registry->has($interface->getFullyQualified()))->toBeTrue(); }); });