-
Notifications
You must be signed in to change notification settings - Fork 89
Fixed creationContext not being passed to abstract factory canCreate() #79
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same, ->shouldBeCalled() is necessary. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also: every time I read prophecy code I cringe >.< There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Haha @danizord absolutely wanted we used Prophecy and I actually quite like it now :). I've tested, you're right. I don't know what I thought that :/. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
cough, I've learned from GandalPHP that magic is good when it works :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @danizord that's why I wrote a 2 Mb library to avoid having magic methods ;-) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see, but they don't hurt in this context (tests) IMHO. It just makes the test a lot more readable than: $this->getMock(MyStuff::class, [], [], '', false)->expects($this->once())->method('doSomething')->with($this->equalTo('something')); There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, I like (and read) that syntax better, heh.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Rly? Damn, that was my unique argument. 😂 |
||
$pluginManager->addAbstractFactory($abstractFactory->reveal()); | ||
$this->assertInstanceOf(InvokableObject::class, $pluginManager->get('foo')); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shouldBeCalled() should be added (as far as I remember, without shouldBeCalled this assertion does nothing actually, and changing foo to something completely different does not throw any error... but I may be wrong. Mind testing @Ocramius ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
True. But the intention was to catch the situation where
canCreate()
was called with the$pluginManager
instead of the$serviceManager
, which it does (in a rather ugly fashion ;)