diff --git a/src/Illuminate/Container/Container.php b/src/Illuminate/Container/Container.php index 39bf3bb59726..9538b993c62f 100755 --- a/src/Illuminate/Container/Container.php +++ b/src/Illuminate/Container/Container.php @@ -3,6 +3,7 @@ namespace Illuminate\Container; use Closure; +use Exception; use ArrayAccess; use LogicException; use ReflectionClass; @@ -613,11 +614,15 @@ public function make($abstract, array $parameters = []) */ public function get($id) { - if ($this->has($id)) { + try { return $this->resolve($id); - } + } catch (Exception $e) { + if ($this->has($id)) { + throw $e; + } - throw new EntryNotFoundException; + throw new EntryNotFoundException; + } } /** diff --git a/tests/Container/ContainerTest.php b/tests/Container/ContainerTest.php index f027e222d2af..f5b41daccdef 100755 --- a/tests/Container/ContainerTest.php +++ b/tests/Container/ContainerTest.php @@ -1069,6 +1069,25 @@ public function testUnknownEntryThrowsException() $container = new Container; $container->get('Taylor'); } + + /** + * @expectedException \Psr\Container\ContainerExceptionInterface + */ + public function testBoundEntriesThrowsContainerExceptionWhenNotResolvable() + { + $container = new Container; + $container->bind('Taylor', IContainerContractStub::class); + + $container->get('Taylor'); + } + + public function testContainerCanResolveClasses() + { + $container = new Container; + $class = $container->get(ContainerConcreteStub::class); + + $this->assertInstanceOf(ContainerConcreteStub::class, $class); + } } class ContainerConcreteStub