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

Commit

Permalink
Merge branch 'fix/#79-#78-creation-context-not-passed-to-abstract-fac…
Browse files Browse the repository at this point in the history
…tory'

Close #78
Close #79
  • Loading branch information
Ocramius committed Jan 24, 2016
2 parents 23e244a + 8b845a9 commit c966f49
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions src/ServiceManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -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;
}
}
Expand Down
18 changes: 18 additions & 0 deletions test/AbstractPluginManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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'));
}
}

0 comments on commit c966f49

Please sign in to comment.