Skip to content
This repository was archived by the owner on Feb 6, 2020. It is now read-only.

Commit c966f49

Browse files
committed
Merge branch 'fix/#79-#78-creation-context-not-passed-to-abstract-factory'
Close #78 Close #79
2 parents 23e244a + 8b845a9 commit c966f49

File tree

3 files changed

+23
-2
lines changed

3 files changed

+23
-2
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ All notable changes to this project will be documented in this file, in reverse
2323
[#64](https://github.com/zendframework/zend-servicemanager/pull/64) corrected benchmark assets signature
2424
- [#72](https://github.com/zendframework/zend-servicemanager/pull/72) corrected link to the Proxy Pattern Wikipedia
2525
page in the documentation
26+
- [#78](https://github.com/zendframework/zend-servicemanager/issues/78)
27+
[#79](https://github.com/zendframework/zend-servicemanager/pull/79) creation context was not being correctly passed
28+
to abstract factories when using plugin managers
2629

2730
## 3.0.1 - 2016-01-19
2831

src/ServiceManager.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ public function has($name)
236236

237237
// Check abstract factories
238238
foreach ($this->abstractFactories as $abstractFactory) {
239-
if ($abstractFactory->canCreate($this, $name)) {
239+
if ($abstractFactory->canCreate($this->creationContext, $name)) {
240240
return true;
241241
}
242242
}
@@ -605,7 +605,7 @@ private function getFactory($name)
605605

606606
// Check abstract factories
607607
foreach ($this->abstractFactories as $abstractFactory) {
608-
if ($abstractFactory->canCreate($this, $name)) {
608+
if ($abstractFactory->canCreate($this->creationContext, $name)) {
609609
return $abstractFactory;
610610
}
611611
}

test/AbstractPluginManagerTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Zend\ServiceManager\Exception\InvalidArgumentException;
1717
use Zend\ServiceManager\Exception\InvalidServiceException;
1818
use Zend\ServiceManager\Exception\ServiceNotFoundException;
19+
use Zend\ServiceManager\Factory\AbstractFactoryInterface;
1920
use Zend\ServiceManager\Factory\FactoryInterface;
2021
use Zend\ServiceManager\Factory\InvokableFactory;
2122
use Zend\ServiceManager\ServiceManager;
@@ -349,4 +350,21 @@ public function testPassingServiceInstanceViaConfigureShouldRaiseExceptionForInv
349350
stdClass::class => new stdClass(),
350351
]]);
351352
}
353+
354+
/**
355+
* @group 79
356+
* @group 78
357+
*/
358+
public function testAbstractFactoryGetsCreationContext()
359+
{
360+
$serviceManager = new ServiceManager();
361+
$pluginManager = new TestAsset\SimplePluginManager($serviceManager);
362+
$abstractFactory = $this->prophesize(AbstractFactoryInterface::class);
363+
$abstractFactory->canCreate($serviceManager, 'foo')
364+
->willReturn(true);
365+
$abstractFactory->__invoke($serviceManager, 'foo', null)
366+
->willReturn(new InvokableObject());
367+
$pluginManager->addAbstractFactory($abstractFactory->reveal());
368+
$this->assertInstanceOf(InvokableObject::class, $pluginManager->get('foo'));
369+
}
352370
}

0 commit comments

Comments
 (0)