Skip to content

[BUG] Service Manager Not Shared Duplicate new Instance with multiple Abstract Factories #3237

Closed
wants to merge 7 commits into from
View
2 library/Zend/ServiceManager/ServiceManager.php
@@ -892,8 +892,8 @@ protected function createFromAbstractFactory($canonicalName, $requestedName)
));
}
try {
- $this->pendingAbstractFactoryRequests[get_class($abstractFactory)] = $requestedName;
if ($abstractFactory->canCreateServiceWithName($this, $canonicalName, $requestedName)) {
+ $this->pendingAbstractFactoryRequests[get_class($abstractFactory)] = $requestedName;
$instance = $this->createServiceViaCallback(
array($abstractFactory, 'createServiceWithName'),
$canonicalName,
View
13 tests/ZendTest/ServiceManager/ServiceManagerTest.php
@@ -654,4 +654,17 @@ public function testCanGetAliasedServicesFromPeeringServiceManagers()
$this->assertSame($service, $this->serviceManager->get('alias-name'));
}
+
+ /**
+ * @covers Zend\ServiceManager\ServiceManager::get
+ */
+ public function testDuplicateNewInstanceMultipleAbstractFactories()
+ {
+ $this->serviceManager->setAllowOverride(true);
+ $this->serviceManager->setShareByDefault(false);
+ $this->serviceManager->addAbstractFactory('ZendTest\ServiceManager\TestAsset\BarAbstractFactory');
+ $this->serviceManager->addAbstractFactory('ZendTest\ServiceManager\TestAsset\FooAbstractFactory');
+ $this->assertInstanceOf('ZendTest\ServiceManager\TestAsset\Bar', $this->serviceManager->get('bar'));
+ $this->assertInstanceOf('ZendTest\ServiceManager\TestAsset\Bar', $this->serviceManager->get('bar'));
+ }
}
Something went wrong with that request. Please try again.