From dc77eaa39c58b50d0ea6d3ba7cd736cb9e4028be Mon Sep 17 00:00:00 2001 From: Matt Kynaston Date: Sat, 23 Jan 2016 18:44:50 +0000 Subject: [PATCH 1/3] Fixed creationContext not being passed to abstract factory canCreate() --- src/ServiceManager.php | 4 ++-- test/AbstractPluginManagerTest.php | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) 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..c144ac30 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,17 @@ public function testPassingServiceInstanceViaConfigureShouldRaiseExceptionForInv stdClass::class => new stdClass(), ]]); } + + 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')); + } } From 2543eac074d61f04ebb60e8d5f45ab9ab864786e Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Mon, 25 Jan 2016 00:21:41 +0100 Subject: [PATCH 2/3] #78 #79 - adding `@group` annotations to the newly introduced test case --- test/AbstractPluginManagerTest.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/test/AbstractPluginManagerTest.php b/test/AbstractPluginManagerTest.php index c144ac30..d48a38eb 100644 --- a/test/AbstractPluginManagerTest.php +++ b/test/AbstractPluginManagerTest.php @@ -351,6 +351,10 @@ public function testPassingServiceInstanceViaConfigureShouldRaiseExceptionForInv ]]); } + /** + * @group 79 + * @group 78 + */ public function testAbstractFactoryGetsCreationContext() { $serviceManager = new ServiceManager(); From 8b845a956caa903806dfa3631103097278b46406 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Mon, 25 Jan 2016 00:22:58 +0100 Subject: [PATCH 3/3] #78 #79 - documenting patch changes in the changelog --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) 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