diff --git a/CHANGELOG.md b/CHANGELOG.md index 3455172e..00af70ca 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,6 +23,9 @@ All notable changes to this project will be documented in this file, in reverse [#64](https://github.com/zendframework/zend-servicemanager/pull/64) corrected benchmark assets signature - [#72](https://github.com/zendframework/zend-servicemanager/pull/72) corrected link to the Proxy Pattern Wikipedia page in the documentation +- [#78](https://github.com/zendframework/zend-servicemanager/issues/78) + [#79](https://github.com/zendframework/zend-servicemanager/pull/79) creation context was not being correctly passed + to abstract factories when using plugin managers ## 3.0.1 - 2016-01-19 diff --git a/src/ServiceManager.php b/src/ServiceManager.php index f6d4d97d..2bd3872a 100644 --- a/src/ServiceManager.php +++ b/src/ServiceManager.php @@ -236,7 +236,7 @@ public function has($name) // Check abstract factories foreach ($this->abstractFactories as $abstractFactory) { - if ($abstractFactory->canCreate($this, $name)) { + if ($abstractFactory->canCreate($this->creationContext, $name)) { return true; } } @@ -605,7 +605,7 @@ private function getFactory($name) // Check abstract factories foreach ($this->abstractFactories as $abstractFactory) { - if ($abstractFactory->canCreate($this, $name)) { + if ($abstractFactory->canCreate($this->creationContext, $name)) { return $abstractFactory; } } diff --git a/test/AbstractPluginManagerTest.php b/test/AbstractPluginManagerTest.php index c06cc054..d48a38eb 100644 --- a/test/AbstractPluginManagerTest.php +++ b/test/AbstractPluginManagerTest.php @@ -16,6 +16,7 @@ use Zend\ServiceManager\Exception\InvalidArgumentException; use Zend\ServiceManager\Exception\InvalidServiceException; use Zend\ServiceManager\Exception\ServiceNotFoundException; +use Zend\ServiceManager\Factory\AbstractFactoryInterface; use Zend\ServiceManager\Factory\FactoryInterface; use Zend\ServiceManager\Factory\InvokableFactory; use Zend\ServiceManager\ServiceManager; @@ -349,4 +350,21 @@ public function testPassingServiceInstanceViaConfigureShouldRaiseExceptionForInv stdClass::class => new stdClass(), ]]); } + + /** + * @group 79 + * @group 78 + */ + public function testAbstractFactoryGetsCreationContext() + { + $serviceManager = new ServiceManager(); + $pluginManager = new TestAsset\SimplePluginManager($serviceManager); + $abstractFactory = $this->prophesize(AbstractFactoryInterface::class); + $abstractFactory->canCreate($serviceManager, 'foo') + ->willReturn(true); + $abstractFactory->__invoke($serviceManager, 'foo', null) + ->willReturn(new InvokableObject()); + $pluginManager->addAbstractFactory($abstractFactory->reveal()); + $this->assertInstanceOf(InvokableObject::class, $pluginManager->get('foo')); + } }