Permalink
Browse files

add delegator factory validation testing

  • Loading branch information...
1 parent c24acc6 commit a90fbea8110558c97de0b34b58a63a914a708d84 @stefanotorresi committed Sep 27, 2013
Showing with 29 additions and 0 deletions.
  1. +29 −0 tests/ZendTest/ServiceManager/ServiceManagerTest.php
@@ -864,4 +864,33 @@ public function testMultipleDelegatorFactoriesWhenNotRegisteredAsServices()
$this->assertInstanceOf('stdClass', array_shift($fooDelegator->instances));
$this->assertSame($fooDelegator, array_shift($barDelegator->instances));
}
+
+ public function testInvalidDelegatorFactoryThrowsException()
+ {
+ $delegatorFactory = new \stdClass;
+ $this->serviceManager->addDelegator('foo-service', $delegatorFactory);
+
+ try {
+ $this->serviceManager->create('foo-service');
+ $this->fail('Expected exception was not raised');
+ }catch (Exception\ServiceNotCreatedException $expected) {
+ $this->assertRegExp('/invalid factory/', $expected->getMessage());
+ return;
+ }
+ }
+
+ public function testInvalidDelegatorFactoryAmongMultipleOnesThrowsException()
+ {
+ $this->serviceManager->addDelegator('foo-service', new MockSelfReturningDelegatorFactory());
+ $this->serviceManager->addDelegator('foo-service', new MockSelfReturningDelegatorFactory());
+ $this->serviceManager->addDelegator('foo-service', 'stdClass');
+
+ try {
+ $this->serviceManager->create('foo-service');
+ $this->fail('Expected exception was not raised');
+ }catch (Exception\ServiceNotCreatedException $expected) {
+ $this->assertRegExp('/invalid factory/', $expected->getMessage());
+ return;
+ }
+ }
}

0 comments on commit a90fbea

Please sign in to comment.