Permalink
Browse files

revert test edits and add new tests

  • Loading branch information...
1 parent 0f479af commit f69a41ac6abe5f8898868446aef0f75eb1dd3e58 @stefanotorresi committed Sep 27, 2013
Showing with 60 additions and 1 deletion.
  1. +60 −1 tests/ZendTest/ServiceManager/ServiceManagerTest.php
@@ -753,14 +753,16 @@ public function testRetrieveServiceFromPeeringServiceManagerIfretrieveFromPeerin
/**
* @covers Zend\ServiceManager\ServiceManager::create
+ * @covers Zend\ServiceManager\ServiceManager::createDelegatorFromFactory
* @covers Zend\ServiceManager\ServiceManager::createDelegatorCallback
* @covers Zend\ServiceManager\ServiceManager::addDelegator
*/
public function testUsesDelegatorWhenAvailable()
{
$delegator = $this->getMock('Zend\\ServiceManager\\DelegatorFactoryInterface');
- $this->serviceManager->addDelegator('foo-service', $delegator);
+ $this->serviceManager->setService('foo-delegator', $delegator);
+ $this->serviceManager->addDelegator('foo-service', 'foo-delegator');
$this->serviceManager->setInvokableClass('foo-service', 'stdClass');
$delegator
@@ -787,6 +789,7 @@ public function testUsesDelegatorWhenAvailable()
/**
* @covers Zend\ServiceManager\ServiceManager::create
+ * @covers Zend\ServiceManager\ServiceManager::createDelegatorFromFactory
* @covers Zend\ServiceManager\ServiceManager::createDelegatorCallback
* @covers Zend\ServiceManager\ServiceManager::addDelegator
*/
@@ -795,6 +798,62 @@ public function testUsesMultipleDelegates()
$fooDelegator = new MockSelfReturningDelegatorFactory();
$barDelegator = new MockSelfReturningDelegatorFactory();
+ $this->serviceManager->setService('foo-delegate', $fooDelegator);
+ $this->serviceManager->setService('bar-delegate', $barDelegator);
+ $this->serviceManager->addDelegator('foo-service', 'foo-delegate');
+ $this->serviceManager->addDelegator('foo-service', 'bar-delegate');
+ $this->serviceManager->setInvokableClass('foo-service', 'stdClass');
+
+ $this->assertSame($barDelegator, $this->serviceManager->create('foo-service'));
+ $this->assertCount(1, $barDelegator->instances);
+ $this->assertCount(1, $fooDelegator->instances);
+ $this->assertInstanceOf('stdClass', array_shift($fooDelegator->instances));
+ $this->assertSame($fooDelegator, array_shift($barDelegator->instances));
+ }
+
+ /**
+ * @covers Zend\ServiceManager\ServiceManager::createDelegatorFromFactory
+ */
+ public function testDelegatorFactoryWhenNotRegisteredAsService()
+ {
+ $delegator = $this->getMock('Zend\\ServiceManager\\DelegatorFactoryInterface');
+
+ $this->serviceManager->addDelegator('foo-service', $delegator);
+ $this->serviceManager->setInvokableClass('foo-service', 'stdClass');
+
+ $delegator
+ ->expects($this->once())
+ ->method('createDelegatorWithName')
+ ->with(
+ $this->serviceManager,
+ 'fooservice',
+ 'foo-service',
+ $this->callback(function ($callback) {
+ if (!is_callable($callback)) {
+ return false;
+ }
+
+ $service = call_user_func($callback);
+
+ return $service instanceof \stdClass;
+ })
+ )
+ ->will($this->returnValue($delegator));
+
+ $this->assertSame($delegator, $this->serviceManager->create('foo-service'));
+ }
+
+ /**
+ * @covers Zend\ServiceManager\ServiceManager::create
+ * @covers Zend\ServiceManager\ServiceManager::createDelegatorFromFactory
+ * @covers Zend\ServiceManager\ServiceManager::createDelegatorCallback
+ * @covers Zend\ServiceManager\ServiceManager::addDelegator
+ */
+ public function testMultipleDelegatorFactoriesWhenNotRegisteredAsServices()
+ {
+ $fooDelegator = new MockSelfReturningDelegatorFactory();
+ $barDelegator = new MockSelfReturningDelegatorFactory();
+
$this->serviceManager->addDelegator('foo-service', $fooDelegator);
$this->serviceManager->addDelegator('foo-service', $barDelegator);
$this->serviceManager->setInvokableClass('foo-service', 'stdClass');

0 comments on commit f69a41a

Please sign in to comment.