diff --git a/src/ServiceManager.php b/src/ServiceManager.php index 6dfe797b..8d604fec 100644 --- a/src/ServiceManager.php +++ b/src/ServiceManager.php @@ -591,7 +591,7 @@ public function canCreateFromAbstractFactory($cName, $rName) foreach ($this->abstractFactories as $index => $abstractFactory) { // Support string abstract factory class names if (is_string($abstractFactory) && class_exists($abstractFactory, true)) { - $this->abstractFactory[$index] = $abstractFactory = new $abstractFactory(); + $this->abstractFactories[$index] = $abstractFactory = new $abstractFactory(); } if ( diff --git a/test/ServiceManagerTest.php b/test/ServiceManagerTest.php index 86a7c3b3..92f7ff1d 100644 --- a/test/ServiceManagerTest.php +++ b/test/ServiceManagerTest.php @@ -17,6 +17,8 @@ use Zend\ServiceManager\ServiceManager; use Zend\ServiceManager\Config; +use ZendTest\ServiceManager\TestAsset\FooCounterAbstractFactory; + class ServiceManagerTest extends \PHPUnit_Framework_TestCase { @@ -599,4 +601,18 @@ public function testCanonicalizeName() $this->assertEquals(true, $this->serviceManager->has('foo/bar')); $this->assertEquals(true, $this->serviceManager->has('foo bar')); } + + /** + * @covers Zend\ServiceManager\ServiceManager::canCreateFromAbstractFactory + */ + public function testWanCreateFromAbstractFactoryWillNotInstantiateAbstractFactoryOnce() + { + $count = FooCounterAbstractFactory::$instantiationCount; + $this->serviceManager->addAbstractFactory(__NAMESPACE__ . '\TestAsset\FooCounterAbstractFactory'); + + $this->serviceManager->canCreateFromAbstractFactory('foo', 'foo'); + $this->serviceManager->canCreateFromAbstractFactory('foo', 'foo'); + + $this->assertSame($count + 1, FooCounterAbstractFactory::$instantiationCount); + } } diff --git a/test/TestAsset/FooCounterAbstractFactory.php b/test/TestAsset/FooCounterAbstractFactory.php new file mode 100644 index 00000000..20685714 --- /dev/null +++ b/test/TestAsset/FooCounterAbstractFactory.php @@ -0,0 +1,51 @@ +