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

Commit 8be70ef

Browse files
committed
Catch and re-throw ContainerExceptions
- to allow returning a ServiceNotFoundException.
1 parent 0d1b3aa commit 8be70ef

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

src/ServiceManager.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
use Exception;
1313
use Interop\Container\ContainerInterface;
14+
use Interop\Container\Exception\ContainerException;
1415
use ProxyManager\Configuration as ProxyConfiguration;
1516
use ProxyManager\Factory\LazyLoadingValueHolderFactory;
1617
use ProxyManager\GeneratorStrategy\EvaluatingGeneratorStrategy;
@@ -425,6 +426,8 @@ private function doCreate($resolvedName, array $options = null)
425426
} else {
426427
$object = $this->createDelegatorFromName($resolvedName, $options);
427428
}
429+
} catch (ContainerException $exception) {
430+
throw $exception;
428431
} catch (Exception $exception) {
429432
throw new ServiceNotCreatedException(sprintf(
430433
'Service with name "%s" could not be created. Reason: %s',

test/CommonServiceLocatorBehaviorsTrait.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
namespace ZendTest\ServiceManager;
1111

1212
use DateTime;
13+
use Interop\Container\Exception\ContainerException;
1314
use PHPUnit_Framework_TestCase as TestCase;
1415
use stdClass;
1516
use Zend\ServiceManager\Exception\InvalidArgumentException;
@@ -504,7 +505,7 @@ public function testPassingInvalidInitializerTypeViaConfigurationRaisesException
504505
public function testGetRaisesExceptionWhenNoFactoryIsResolved()
505506
{
506507
$serviceManager = $this->createContainer();
507-
$this->setExpectedException(ServiceNotCreatedException::class, 'invalid or missing factory');
508+
$this->setExpectedException(ContainerException::class, 'invalid or missing factory');
508509
$serviceManager->get('Some\Unknown\Service');
509510
}
510511

0 commit comments

Comments
 (0)