Browse files

add single delegator tests for abtract plugin manager

  • Loading branch information...
1 parent 0a56163 commit bfab44bc61aaa69ca1699c9eed1ca191ffe0a26e @stefanotorresi committed Sep 27, 2013
Showing with 51 additions and 0 deletions.
  1. +51 −0 tests/ZendTest/ServiceManager/AbstractPluginManagerTest.php
View
51 tests/ZendTest/ServiceManager/AbstractPluginManagerTest.php
@@ -117,4 +117,55 @@ public function testCallableObjectWithMutableCreationOptions()
$method->setAccessible(true);
$method->invoke($this->pluginManager, $callable, 'foo', 'bar');
}
+
+ public function testValidatePluginGetsCalledOnDelegatorFactoryIfItsAService()
+ {
+ $pluginManagerMock = $this->getMockForAbstractClass('Zend\ServiceManager\AbstractPluginManager');
+ $delegatorFactoryMock = $this->getMock('Zend\\ServiceManager\\DelegatorFactoryInterface');
+
+ $pluginManagerMock->setService('delegator-factory', $delegatorFactoryMock);
+ $pluginManagerMock->addDelegator('foo-service', 'delegator-factory');
+
+ $pluginManagerMock->expects($this->once())
+ ->method('validatePlugin')
+ ->with($delegatorFactoryMock);
+
+ $pluginManagerMock->create('foo-service');
+ }
+
+ public function testSingleDelegatorUsage()
+ {
+ $delegatorFactory = $this->getMock('Zend\\ServiceManager\\DelegatorFactoryInterface');
+ $pluginManager = $this->getMockForAbstractClass('Zend\ServiceManager\AbstractPluginManager');
+ $realService = $this->getMock('stdClass', array(), array(), 'RealService');
+ $delegator = $this->getMock('stdClass', array(), array(), 'Delegator');
+
+ $delegatorFactory
+ ->expects($this->once())
+ ->method('createDelegatorWithName')
+ ->with(
+ $pluginManager,
+ 'fooservice',
+ 'foo-service',
+ $this->callback(function ($callback) use ($realService) {
+ if (!is_callable($callback)) {
+ return false;
+ }
+
+ return call_user_func($callback) === $realService;
+ })
+ )
+ ->will($this->returnValue($delegator));
+
+ $pluginManager->setFactory('foo-service', function() use ($realService) {
+ return $realService;
+ });
+ $pluginManager->addDelegator('foo-service', $delegatorFactory);
+
+ $pluginManager->expects($this->once())
+ ->method('validatePlugin')
+ ->with($delegator);
+
+ $this->assertSame($delegator, $pluginManager->get('foo-service'));
+ }
}

0 comments on commit bfab44b

Please sign in to comment.