Skip to content

Commit

Permalink
Merge pull request #251 from settermjd/fix-bug-in-delegator-list-crea…
Browse files Browse the repository at this point in the history
…tion

Remove duplicate delgators for all services
  • Loading branch information
settermjd authored Dec 19, 2024
2 parents 9ccfbfc + d734c7d commit 6873b9e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
3 changes: 1 addition & 2 deletions src/ServiceManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
24 changes: 24 additions & 0 deletions test/ServiceManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -372,6 +373,29 @@ 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");
$delegators = $property->getValue($serviceManager);
self::assertSame(
[
DateTime::class => [
DelegatorFactory::class,
],
],
$delegators
);
}

public function testResolvedAliasFromAbstractFactory(): void
{
$abstractFactory = $this->createMock(AbstractFactoryInterface::class);
Expand Down

0 comments on commit 6873b9e

Please sign in to comment.