diff --git a/src/ServiceManager.php b/src/ServiceManager.php index 466702a8..ada28605 100644 --- a/src/ServiceManager.php +++ b/src/ServiceManager.php @@ -705,8 +705,7 @@ private function mergeDelegators(array $config): array { foreach ($config as $key => $delegators) { if (! array_key_exists($key, $this->delegators)) { - $this->delegators[$key] = $delegators; - continue; + $this->delegators[$key] = []; } foreach ($delegators as $delegator) { diff --git a/test/ServiceManagerTest.php b/test/ServiceManagerTest.php index 06fb2ad3..3fd452e7 100644 --- a/test/ServiceManagerTest.php +++ b/test/ServiceManagerTest.php @@ -5,6 +5,7 @@ namespace LaminasTest\ServiceManager; use DateTime; +use Laminas\ContainerConfigTest\TestAsset\DelegatorFactory; use Laminas\ServiceManager\Factory\AbstractFactoryInterface; use Laminas\ServiceManager\Factory\FactoryInterface; use Laminas\ServiceManager\Factory\InvokableFactory; @@ -372,6 +373,30 @@ public function testFactoryMayBeStaticMethodDescribedByCallableString(): void self::assertEquals(stdClass::class, $serviceManager->get(stdClass::class)::class); } + public function testDuplicateDelegatorsAreRemoved(): void + { + $dependencies = [ + 'delegators' => [ + DateTime::class => [ + DelegatorFactory::class, + DelegatorFactory::class, + ], + ], + ]; + $serviceManager = new ServiceManager($dependencies); + $property = new ReflectionProperty(ServiceManager::class, "delegators"); + $property->setAccessible(true); + $delegators = $property->getValue($serviceManager); + self::assertSame( + [ + DateTime::class => [ + DelegatorFactory::class, + ], + ], + $delegators + ); + } + public function testResolvedAliasFromAbstractFactory(): void { $abstractFactory = $this->createMock(AbstractFactoryInterface::class);